本文整理了Java中org.springframework.web.servlet.ModelAndView.getView()
方法的一些代码示例,展示了ModelAndView.getView()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ModelAndView.getView()
方法的具体详情如下:
包路径:org.springframework.web.servlet.ModelAndView
类名称:ModelAndView
方法名:getView
[英]Return the View object, or null if we are using a view name to be resolved by the DispatcherServlet via a ViewResolver.
[中]返回视图对象,如果使用DispatcherServlet通过ViewResolver解析的视图名称,则返回null。
代码示例来源:origin: spring-projects/spring-framework
/**
* Print the ModelAndView.
*/
protected void printModelAndView(@Nullable ModelAndView mav) throws Exception {
this.printer.printValue("View name", (mav != null) ? mav.getViewName() : null);
this.printer.printValue("View", (mav != null) ? mav.getView() : null);
if (mav == null || mav.getModel().size() == 0) {
this.printer.printValue("Model", null);
}
else {
for (String name : mav.getModel().keySet()) {
if (!name.startsWith(BindingResult.MODEL_KEY_PREFIX)) {
Object value = mav.getModel().get(name);
this.printer.printValue("Attribute", name);
this.printer.printValue("value", value);
Errors errors = (Errors) mav.getModel().get(BindingResult.MODEL_KEY_PREFIX + name);
if (errors != null) {
this.printer.printValue("errors", errors.getAllErrors());
}
}
}
}
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void redirectView() throws Exception {
RedirectView view = new RedirectView("/foo");
this.controller.setView(view);
ModelAndView modelAndView = this.controller.handleRequest(this.request, this.response);
assertSame(view, modelAndView.getView());
}
代码示例来源:origin: spring-projects/spring-framework
view = mv.getView();
if (view == null) {
throw new ServletException("ModelAndView [" + mv + "] neither contains a view name nor a " +
代码示例来源:origin: cloudfoundry/uaa
(Authentication) principal,
grantType
).getView();
代码示例来源:origin: spring-projects/spring-framework
@Override
public void handleReturnValue(@Nullable Object returnValue, MethodParameter returnType,
ModelAndViewContainer mavContainer, NativeWebRequest webRequest) throws Exception {
if (this.mavResolvers != null) {
for (ModelAndViewResolver mavResolver : this.mavResolvers) {
Class<?> handlerType = returnType.getContainingClass();
Method method = returnType.getMethod();
Assert.state(method != null, "No handler method");
ExtendedModelMap model = (ExtendedModelMap) mavContainer.getModel();
ModelAndView mav = mavResolver.resolveModelAndView(method, handlerType, returnValue, model, webRequest);
if (mav != ModelAndViewResolver.UNRESOLVED) {
mavContainer.addAllAttributes(mav.getModel());
mavContainer.setViewName(mav.getViewName());
if (!mav.isReference()) {
mavContainer.setView(mav.getView());
}
return;
}
}
}
// No suitable ModelAndViewResolver...
if (this.modelAttributeProcessor.supportsReturnType(returnType)) {
this.modelAttributeProcessor.handleReturnValue(returnValue, returnType, mavContainer, webRequest);
}
else {
throw new UnsupportedOperationException("Unexpected return type: " +
returnType.getParameterType().getName() + " in method: " + returnType.getMethod());
}
}
代码示例来源:origin: spring-projects/spring-security-oauth
return getImplicitGrantResponse(authorizationRequest).getView();
代码示例来源:origin: org.springframework/spring-webmvc
view = mv.getView();
if (view == null) {
throw new ServletException("ModelAndView [" + mv + "] neither contains a view name nor a " +
代码示例来源:origin: cloudfoundry/uaa
@Test
public void testValidOTPTakesToHomePage() throws Exception{
int code = 1234;
when(userGoogleMfaCredentialsProvisioning.isValidCode(ArgumentMatchers.any(UserGoogleMfaCredentials.class), eq(code))).thenReturn(true);
when(uaaAuthentication.getPrincipal()).thenReturn(new UaaPrincipal(userId, "Marissa", null, "uaa", null, null), null, null);
when(mfaProviderProvisioning.retrieveByName(mfaProvider.getName(), IdentityZoneHolder.get().getId())).thenReturn(mfaProvider);
when(userDb.retrieveUserByName("Marissa", "uaa")).thenReturn(new UaaUser(new UaaUserPrototype().withUsername("Marissa").withOrigin("uaa").withId("1234").withEmail("marissa@example.com")));
IdentityZoneHolder.get().getConfig().getMfaConfig().setEnabled(true).setProviderName(mfaProvider.getName());
SessionStatus sessionStatus = mock(SessionStatus.class);
ModelAndView returnView = endpoint.validateCode(
mock(Model.class),
Integer.toString(code),
mock(UserGoogleMfaCredentials.class),
sessionStatus);
assertEquals("/login/mfa/completed", ((RedirectView)returnView.getView()).getUrl());
verify(sessionStatus, times(1)).setComplete();
verifyMfaEvent(MfaAuthenticationSuccessEvent.class);
}
代码示例来源:origin: spring-projects/spring-framework
@Override
public void handleReturnValue(@Nullable Object returnValue, MethodParameter returnType,
ModelAndViewContainer mavContainer, NativeWebRequest webRequest) throws Exception {
if (returnValue == null) {
mavContainer.setRequestHandled(true);
return;
}
ModelAndView mav = (ModelAndView) returnValue;
if (mav.isReference()) {
String viewName = mav.getViewName();
mavContainer.setViewName(viewName);
if (viewName != null && isRedirectViewName(viewName)) {
mavContainer.setRedirectModelScenario(true);
}
}
else {
View view = mav.getView();
mavContainer.setView(view);
if (view instanceof SmartView && ((SmartView) view).isRedirectView()) {
mavContainer.setRedirectModelScenario(true);
}
}
mavContainer.setStatus(mav.getStatus());
mavContainer.addAllAttributes(mav.getModel());
}
代码示例来源:origin: spring-projects/spring-integration
MockHttpServletResponse response = new MockHttpServletResponse();
ModelAndView modelAndView = controller.handleRequest(request, response);
assertSame(view, modelAndView.getView());
assertEquals(1, modelAndView.getModel().size());
Object reply = modelAndView.getModel().get("reply");
代码示例来源:origin: org.springframework/spring-webmvc
@Override
public void handleReturnValue(@Nullable Object returnValue, MethodParameter returnType,
ModelAndViewContainer mavContainer, NativeWebRequest webRequest) throws Exception {
if (this.mavResolvers != null) {
for (ModelAndViewResolver mavResolver : this.mavResolvers) {
Class<?> handlerType = returnType.getContainingClass();
Method method = returnType.getMethod();
Assert.state(method != null, "No handler method");
ExtendedModelMap model = (ExtendedModelMap) mavContainer.getModel();
ModelAndView mav = mavResolver.resolveModelAndView(method, handlerType, returnValue, model, webRequest);
if (mav != ModelAndViewResolver.UNRESOLVED) {
mavContainer.addAllAttributes(mav.getModel());
mavContainer.setViewName(mav.getViewName());
if (!mav.isReference()) {
mavContainer.setView(mav.getView());
}
return;
}
}
}
// No suitable ModelAndViewResolver...
if (this.modelAttributeProcessor.supportsReturnType(returnType)) {
this.modelAttributeProcessor.handleReturnValue(returnValue, returnType, mavContainer, webRequest);
}
else {
throw new UnsupportedOperationException("Unexpected return type: " +
returnType.getParameterType().getName() + " in method: " + returnType.getMethod());
}
}
代码示例来源:origin: org.kantega.openaksess/openaksess-core
public Map<String, Object> handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception {
ModelAndView modelAndView = controller.handleRequest(request, response);
if (modelAndView.getView() instanceof RedirectView) {
RedirectView view = (RedirectView)modelAndView.getView();
response.sendRedirect(view.getUrl());
return new HashMap<>();
} else {
return modelAndView.getModel();
}
}
代码示例来源:origin: org.springframework/spring-webmvc
@Override
public void handleReturnValue(@Nullable Object returnValue, MethodParameter returnType,
ModelAndViewContainer mavContainer, NativeWebRequest webRequest) throws Exception {
if (returnValue == null) {
mavContainer.setRequestHandled(true);
return;
}
ModelAndView mav = (ModelAndView) returnValue;
if (mav.isReference()) {
String viewName = mav.getViewName();
mavContainer.setViewName(viewName);
if (viewName != null && isRedirectViewName(viewName)) {
mavContainer.setRedirectModelScenario(true);
}
}
else {
View view = mav.getView();
mavContainer.setView(view);
if (view instanceof SmartView && ((SmartView) view).isRedirectView()) {
mavContainer.setRedirectModelScenario(true);
}
}
mavContainer.setStatus(mav.getStatus());
mavContainer.addAllAttributes(mav.getModel());
}
代码示例来源:origin: pl.touk.widerest/widerest-api
protected ModelAndView interceptOutOfBandRedirect(ModelAndView mav) {
View view = mav.getView();
if (view instanceof RedirectView) {
String location = ((RedirectView) view).getUrl();
if (location.startsWith(OOB_URI)) {
UriComponents uriComponents = UriComponentsBuilder.newInstance().query(location.substring(OOB_URI.length() + 1)).build();
return new ModelAndView(new MappingJackson2JsonView(), uriComponents.getQueryParams().toSingleValueMap());
}
}
return mav;
}
}
代码示例来源:origin: spring-projects/spring-framework
chain = mapping2.getHandler(request);
mv = adapter.handle(request, new MockHttpServletResponse(), chain.getHandler());
assertNotNull(mv.getView());
assertEquals(RedirectView.class, mv.getView().getClass());
RedirectView redirectView = (RedirectView) mv.getView();
MockHttpServletResponse response = new MockHttpServletResponse();
redirectView.render(Collections.emptyMap(), request, response);
代码示例来源:origin: philwebb/springfaces
@Override
public void encodeAll(FacesContext context) throws IOException {
SpringFacesContext.getCurrentInstance(true).render(this.modelAndView.getView(),
this.modelAndView.getModel());
}
}
代码示例来源:origin: pl.edu.icm.synat/synat-ui-commons
public static boolean isRedirect(ModelAndView modelAndView) {
return modelAndView != null &&
((modelAndView.getView() != null && modelAndView.getView() instanceof RedirectView)
|| (modelAndView.getViewName() != null && modelAndView.getViewName().startsWith(UrlBasedViewResolver.REDIRECT_URL_PREFIX)));
}
代码示例来源:origin: philwebb/springfaces
private ModelAndView getModelAndView(FacesContext context, String viewId, Map<String, List<String>> parameters) {
DestinationAndModel destinationAndModel = getDestinationAndModelForViewId(context, viewId);
if (destinationAndModel != null) {
ModelAndView modelAndView = resolveDestination(context, destinationAndModel.getDestination());
Map<String, Object> resolvedViewModel = destinationAndModel.getModel(context, parameters,
modelAndView.getModel());
return new ModelAndView(modelAndView.getView(), resolvedViewModel);
}
return null;
}
代码示例来源:origin: pl.edu.icm.yadda.repowebeditor/repository-web-editor-core
@Override
public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) {
if (modelAndView != null) {
if ((modelAndView.getView() != null && modelAndView.getView() instanceof RedirectView)
|| (modelAndView.getViewName() != null && modelAndView.getViewName().startsWith(
UrlBasedViewResolver.REDIRECT_URL_PREFIX))) {
return;
}
List<Notification> notifications = notificationService.retrieveNotifications();
modelAndView.addObject(notificationKey, notifications);
logger.trace("View is " + modelAndView.getViewName());
}
}
代码示例来源:origin: riotfamily/riot
public View resolveView(HttpServletRequest request, ModelAndView mv)
throws ViewResolutionException {
if (mv.hasView() && !mv.isReference()) {
return mv.getView();
}
return resolveView(request, mv.getViewName());
}
内容来源于网络,如有侵权,请联系作者删除!