当前位置: 首页>>代码示例>>Java>>正文


Java ModelAndView类代码示例

本文整理汇总了Java中org.springframework.web.portlet.ModelAndView的典型用法代码示例。如果您正苦于以下问题:Java ModelAndView类的具体用法?Java ModelAndView怎么用?Java ModelAndView使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


ModelAndView类属于org.springframework.web.portlet包,在下文中一共展示了ModelAndView类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: doResolveException

import org.springframework.web.portlet.ModelAndView; //导入依赖的package包/类
@Override
protected ModelAndView doResolveException(
		PortletRequest request, MimeResponse response, Object handler, Exception ex) {

	if (handler != null) {
		Method handlerMethod = findBestExceptionHandlerMethod(handler, ex);
		if (handlerMethod != null) {
			NativeWebRequest webRequest = new PortletWebRequest(request, response);
			try {
				Object[] args = resolveHandlerArguments(handlerMethod, handler, webRequest, ex);
				if (logger.isDebugEnabled()) {
					logger.debug("Invoking request handler method: " + handlerMethod);
				}
				Object retVal = doInvokeMethod(handlerMethod, handler, args);
				return getModelAndView(retVal);
			}
			catch (Exception invocationEx) {
				logger.error("Invoking request method resulted in exception : " + handlerMethod, invocationEx);
			}
		}
	}
	return null;
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:24,代码来源:AnnotationMethodHandlerExceptionResolver.java

示例2: getModelAndView

import org.springframework.web.portlet.ModelAndView; //导入依赖的package包/类
@SuppressWarnings("unchecked")
private ModelAndView getModelAndView(Object returnValue) {
	if (returnValue instanceof ModelAndView) {
		return (ModelAndView) returnValue;
	}
	else if (returnValue instanceof Model) {
		return new ModelAndView().addAllObjects(((Model) returnValue).asMap());
	}
	else if (returnValue instanceof Map) {
		return new ModelAndView().addAllObjects((Map<String, Object>) returnValue);
	}
	else if (returnValue instanceof View) {
		return new ModelAndView(returnValue);
	}
	else if (returnValue instanceof String) {
		return new ModelAndView((String) returnValue);
	}
	else if (returnValue == null) {
		return new ModelAndView();
	}
	else {
		throw new IllegalArgumentException("Invalid handler method return value: " + returnValue);
	}
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:25,代码来源:AnnotationMethodHandlerExceptionResolver.java

示例3: handleRenderRequest

import org.springframework.web.portlet.ModelAndView; //导入依赖的package包/类
@Override
public ModelAndView handleRenderRequest(RenderRequest request, RenderResponse response) throws Exception {
	// If the portlet is minimized and we don't want to render then return null.
	if (WindowState.MINIMIZED.equals(request.getWindowState()) && !this.renderWhenMinimized) {
		return null;
	}

	// Delegate to PortletContentGenerator for checking and preparing.
	checkAndPrepare(request, response);

	// Execute in synchronized block if required.
	if (this.synchronizeOnSession) {
		PortletSession session = request.getPortletSession(false);
		if (session != null) {
			Object mutex = PortletUtils.getSessionMutex(session);
			synchronized (mutex) {
				return handleRenderRequestInternal(request, response);
			}
		}
	}

	return handleRenderRequestInternal(request, response);
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:24,代码来源:AbstractController.java

示例4: doResolveException

import org.springframework.web.portlet.ModelAndView; //导入依赖的package包/类
/**
 * Actually resolve the given exception that got thrown during on handler execution,
 * returning a ModelAndView that represents a specific error page if appropriate.
 * @param request current portlet request
 * @param response current portlet response
 * @param handler the executed handler, or null if none chosen at the time of
 * the exception (for example, if multipart resolution failed)
 * @param ex the exception that got thrown during handler execution
 * @return a corresponding ModelAndView to forward to, or null for default processing
 */
@Override
protected ModelAndView doResolveException(
		PortletRequest request, MimeResponse response, Object handler, Exception ex) {

	// Log exception, both at debug log level and at warn level, if desired.
	if (logger.isDebugEnabled()) {
		logger.debug("Resolving exception from handler [" + handler + "]: " + ex);
	}
	logException(ex, request);

	// Expose ModelAndView for chosen error view.
	String viewName = determineViewName(ex, request);
	if (viewName != null) {
		return getModelAndView(viewName, ex, request);
	}
	else {
		return null;
	}
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:30,代码来源:SimpleMappingExceptionResolver.java

示例5: resolveModelAndView

import org.springframework.web.portlet.ModelAndView; //导入依赖的package包/类
@Override
public org.springframework.web.servlet.ModelAndView resolveModelAndView(Method handlerMethod,
		Class<?> handlerType,
		Object returnValue,
		ExtendedModelMap implicitModel,
		NativeWebRequest webRequest) {
	if (returnValue instanceof MySpecialArg) {
		return new org.springframework.web.servlet.ModelAndView(new View() {
			@Override
			public String getContentType() {
				return "text/html";
			}

			@Override
			public void render(Map<String, ?> model, HttpServletRequest request, HttpServletResponse response)
					throws Exception {
				response.getWriter().write("myValue");
			}

		});
	}
	return UNRESOLVED;
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:24,代码来源:PortletAnnotationControllerTests.java

示例6: handleRenderRequestInternal

import org.springframework.web.portlet.ModelAndView; //导入依赖的package包/类
/**
 * Handles render phase of two cases: form submissions and showing a new form.
 * Delegates the decision between the two to {@code isFormSubmission},
 * always treating requests without existing form session attribute
 * as new form when using session form mode.
 * @see #isFormSubmission
 * @see #showNewForm
 * @see #processFormSubmission
 * @see #handleActionRequestInternal
 */
@Override
protected ModelAndView handleRenderRequestInternal(RenderRequest request, RenderResponse response)
		throws Exception {

	// Form submission or new form to show?
	if (isFormSubmission(request)) {

		// If it is an invalid submit then handle it.
		if (isInvalidSubmission(request)) {
			logger.debug("Invalid submit - calling renderInvalidSubmit");
			return renderInvalidSubmit(request, response);
		}

		// Valid submit -> render.
		logger.debug("Valid submit - calling renderFormSubmission");
		return renderFormSubmission(request, response, getRenderCommand(request), getRenderErrors(request));
	}

	else {
		// New form to show: render form view.
		return showNewForm(request, response);
	}
}
 
开发者ID:deathspeeder,项目名称:class-guard,代码行数:34,代码来源:AbstractFormController.java

示例7: getModelAndView

import org.springframework.web.portlet.ModelAndView; //导入依赖的package包/类
@SuppressWarnings("unchecked")
private ModelAndView getModelAndView(Object returnValue) {
	if (returnValue instanceof ModelAndView) {
		return (ModelAndView) returnValue;
	}
	else if (returnValue instanceof Model) {
		return new ModelAndView().addAllObjects(((Model) returnValue).asMap());
	}
	else if (returnValue instanceof Map) {
		return new ModelAndView().addAllObjects((Map) returnValue);
	}
	else if (returnValue instanceof View) {
		return new ModelAndView(returnValue);
	}
	else if (returnValue instanceof String) {
		return new ModelAndView((String) returnValue);
	}
	else if (returnValue == null) {
		return new ModelAndView();
	}
	else {
		throw new IllegalArgumentException("Invalid handler method return value: " + returnValue);
	}
}
 
开发者ID:deathspeeder,项目名称:class-guard,代码行数:25,代码来源:AnnotationMethodHandlerExceptionResolver.java

示例8: handleRenderRequestInternal

import org.springframework.web.portlet.ModelAndView; //导入依赖的package包/类
@Override
protected final ModelAndView handleRenderRequestInternal(
		RenderRequest request, RenderResponse response) throws Exception {

	Object command = null;
	BindException errors = null;

	// Get the command and errors objects from the session, if they exist.
	if (isCommandInSession(request)) {
		logger.debug("Render phase obtaining command and errors objects from session");
		command = getRenderCommand(request);
		errors = getRenderErrors(request);
	}
	else {
		logger.debug("Render phase creating new command and errors objects");
		command = getCommand(request);
		PortletRequestDataBinder binder = bindAndValidate(request, command);
		errors = new BindException(binder.getBindingResult());
	}

	return handleRender(request, response, command, errors);
}
 
开发者ID:deathspeeder,项目名称:class-guard,代码行数:23,代码来源:AbstractCommandController.java

示例9: handleRenderRequest

import org.springframework.web.portlet.ModelAndView; //导入依赖的package包/类
public ModelAndView handleRenderRequest(RenderRequest request, RenderResponse response) throws Exception {
	// If the portlet is minimized and we don't want to render then return null.
	if (WindowState.MINIMIZED.equals(request.getWindowState()) && !this.renderWhenMinimized) {
		return null;
	}

	// Delegate to PortletContentGenerator for checking and preparing.
	checkAndPrepare(request, response);

	// Execute in synchronized block if required.
	if (this.synchronizeOnSession) {
		PortletSession session = request.getPortletSession(false);
		if (session != null) {
			Object mutex = PortletUtils.getSessionMutex(session);
			synchronized (mutex) {
				return handleRenderRequestInternal(request, response);
			}
		}
	}

	return handleRenderRequestInternal(request, response);
}
 
开发者ID:deathspeeder,项目名称:class-guard,代码行数:23,代码来源:AbstractController.java

示例10: resolveModelAndView

import org.springframework.web.portlet.ModelAndView; //导入依赖的package包/类
@Override
public org.springframework.web.servlet.ModelAndView resolveModelAndView(Method handlerMethod,
		Class handlerType,
		Object returnValue,
		ExtendedModelMap implicitModel,
		NativeWebRequest webRequest) {
	if (returnValue instanceof MySpecialArg) {
		return new org.springframework.web.servlet.ModelAndView(new View() {
			@Override
			public String getContentType() {
				return "text/html";
			}

			@Override
			public void render(Map<String, ?> model, HttpServletRequest request, HttpServletResponse response)
					throws Exception {
				response.getWriter().write("myValue");
			}

		});
	}
	return UNRESOLVED;
}
 
开发者ID:deathspeeder,项目名称:class-guard,代码行数:24,代码来源:PortletAnnotationControllerTests.java

示例11: testRenderRequestWithParams

import org.springframework.web.portlet.ModelAndView; //导入依赖的package包/类
public void testRenderRequestWithParams() throws Exception {
	TestController tc = new TestController();
	MockRenderRequest request = new MockRenderRequest();
	MockRenderResponse response = new MockRenderResponse();
	String name = "test";
	int age = 30;
	request.addParameter("name", name);
	request.addParameter("age", "" + age);
	request.setContextPath("test");
	ModelAndView mav = tc.handleRenderRequest(request, response);
	assertEquals("test-view", mav.getViewName());
	TestBean command = (TestBean)mav.getModel().get(tc.getCommandName());
	assertEquals("Name should be bound", name, command.getName());
	assertEquals("Age should be bound", age, command.getAge());
	BindException errors = (BindException)mav.getModel().get(ERRORS_KEY);
	assertNotNull(errors);
	assertEquals("There should be no errors", 0, errors.getErrorCount());
}
 
开发者ID:deathspeeder,项目名称:class-guard,代码行数:19,代码来源:CommandControllerTests.java

示例12: testRenderRequestWithMismatch

import org.springframework.web.portlet.ModelAndView; //导入依赖的package包/类
public void testRenderRequestWithMismatch() throws Exception {
	TestController tc = new TestController();
	MockRenderRequest request = new MockRenderRequest();
	MockRenderResponse response = new MockRenderResponse();
	String name = "test";
	request.addParameter("name", name);
	request.addParameter("age", "zzz");
	request.setContextPath("test");
	ModelAndView mav = tc.handleRenderRequest(request, response);
	assertEquals("test-view", mav.getViewName());
	TestBean command = (TestBean)mav.getModel().get(tc.getCommandName());
	assertNotNull(command);
	assertEquals("Name should be bound", name, command.getName());
	BindException errors = (BindException)mav.getModel().get(ERRORS_KEY);
	assertEquals("There should be 1 error", 1, errors.getErrorCount());
	assertNotNull(errors.getFieldError("age"));
	assertEquals("typeMismatch", errors.getFieldError("age").getCode());
}
 
开发者ID:deathspeeder,项目名称:class-guard,代码行数:19,代码来源:CommandControllerTests.java

示例13: testWithValidatorAddingGlobalError

import org.springframework.web.portlet.ModelAndView; //导入依赖的package包/类
public void testWithValidatorAddingGlobalError() throws Exception {
	final String errorCode = "someCode";
	final String defaultMessage = "validation error!";
	TestController tc = new TestController();
	tc.setValidator(new Validator() {
		@Override
		public boolean supports(Class c) {
			return TestBean.class.isAssignableFrom(c);
		}
		@Override
		public void validate(Object o, Errors e) {
			e.reject(errorCode, defaultMessage);
		}
	});
	MockRenderRequest request = new MockRenderRequest();
	MockRenderResponse response = new MockRenderResponse();
	ModelAndView mav = tc.handleRenderRequest(request, response);
	BindException errors = (BindException)mav.getModel().get(ERRORS_KEY);
	assertEquals("There should be 1 error", 1, errors.getErrorCount());
	ObjectError error = errors.getGlobalError();
	assertEquals(error.getCode(), errorCode);
	assertEquals(error.getDefaultMessage(), defaultMessage);
}
 
开发者ID:deathspeeder,项目名称:class-guard,代码行数:24,代码来源:CommandControllerTests.java

示例14: displayContactForm

import org.springframework.web.portlet.ModelAndView; //导入依赖的package包/类
/**
 * Render method to display the contact form
 * @param request
 * @param response
 * @return
 */
@RenderMapping(params = "action=displayContactForm")
public ModelAndView displayContactForm(RenderRequest request, RenderResponse response) {
  ModelAndView modelAndView = new ModelAndView();

  // render contactForm.jsp
  modelAndView.setViewName("contactForm");

  // if an id has been passed in the request, it is an update
  // otherwise, it is a creation
  String contactId = request.getParameter("id");
  if(contactId != null) {
    Long id = Long.parseLong(contactId);
    // call the service to get the selected contact and pass it to the view
    modelAndView.addObject("contact", contactService.getContactById(id));
  } else {
    modelAndView.addObject("contact", new Contact());
  }

  return modelAndView;
}
 
开发者ID:exo-addons,项目名称:sample-springmvc-portlet,代码行数:27,代码来源:ContactController.java

示例15: renderViewAfterPaybox

import org.springframework.web.portlet.ModelAndView; //导入依赖的package包/类
/**
 * When user is redirected on the portlet after the paybox process, 
 * and if validatePayboxJustWithRedirection in pref portlet is true,
 * we validate the transaction regarding informations on queryString 
 * (there is a paybox signature that secures this, 
 * so we can do that even if we can consider it "less" secure than the direct call of paybox) 
 */
@RequestMapping(params="signature")
public ModelAndView renderViewAfterPaybox(@RequestParam(required=false) String montant, @RequestParam String reference, @RequestParam(required=false) String auto, 
		@RequestParam String erreur, @RequestParam String idtrans, @RequestParam String signature, RenderRequest request, RenderResponse response) {	
	
	if("true".equals(request.getPreferences().getValue(PREF_VALIDATE_AFTER_REDIRECT, "false"))) {
 	String uid = getUid(request);
 	String paperCutContext = request.getPreferences().getValue(PREF_PAPERCUT_CONTEXT, null);
 	String queryString = getQueryString(montant, reference, auto, erreur, idtrans, signature);

 	log.debug(queryString);
 	
 	esupPaperCutServices.get(paperCutContext).payboxCallback(montant, reference, auto, erreur, idtrans, signature, queryString, null, uid);
	}
	
	return renderView(request, response);
}
 
开发者ID:EsupPortail,项目名称:esup-papercut,代码行数:24,代码来源:EsupPapercutPortletController.java


注:本文中的org.springframework.web.portlet.ModelAndView类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。