List of usage examples for org.springframework.web.servlet ModelAndView getViewName
@Nullable
public String getViewName()
From source file:org.motechproject.server.outbox.web.VxmlOutboxControllerTest.java
@Test public void testRemoveOutboxMessageException() { String messageId = "mID"; Mockito.when(request.getParameter(VxmlOutboxController.MESSAGE_ID_PARAM)).thenReturn(messageId); doThrow(new RuntimeException()).when(voiceOutboxService).setMessageStatus(anyString(), Matchers.<OutboundVoiceMessageStatus>any()); ModelAndView modelAndView = vxmlOutboxController.remove(request, response); Assert.assertEquals(VxmlOutboxController.REMOVE_SAVED_MESSAGE_ERROR_TEMPLATE_NAME, modelAndView.getViewName()); }
From source file:no.dusken.aranea.web.spring.ChainedController.java
/** * Calls the handleRequest controller for each of the Controllers in the * chain sequentially, merging the ModelAndView objects returned after each * call and returning the merged ModelAndView object. An exception thrown by * any of the controllers in the chain will propagate upwards through the * handleRequest() method of the ChainedController. The ChainedController * itself does not support any communication between the controllers in the * chain, but this can be effected by the controllers posting to a common * accessible object such as the ApplicationContext. Note that this will * introduce coupling between the controllers and will be difficult to * arrange into a parallel chain. A controller can stop processing of the * chain by returning a null ModelAndView object. Enhanced with adding the * chained views to the controller. This enables the controller to render * the views from the chained controllers. * * @param request the HttpServletRequest object. * @param response the HttpServletResponse object. * @return the merged ModelAndView object for all the controllers. * @throws Exception if one is thrown by one of the controllers in the chain. *//*from w w w .ja v a 2s. c o m*/ public ModelAndView handleRequestSequentially(HttpServletRequest request, HttpServletResponse response) throws Exception { ModelAndView mergedModel = new ModelAndView(); List<String> mergedViews = new ArrayList<String>(); for (Controller controller : controllers) { try { ModelAndView model = controller.handleRequest(request, response); if (model == null) { // chain will stop if a controller returns a null // ModelAndView object. break; } mergedModel.addAllObjects(model.getModel()); mergedViews.add(model.getViewName()); } catch (Exception e) { throw new Exception( "Controller: " + controller.getClass().getName() + " threw exception: " + e.getMessage(), e); } } mergedModel.addObject("views", mergedViews); if (StringUtils.isNotEmpty(this.viewName)) { mergedModel.setViewName(this.viewName); } return mergedModel; }
From source file:net.groupbuy.interceptor.ExecuteTimeInterceptor.java
@Override public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception { Long executeTime = (Long) request.getAttribute(EXECUTE_TIME_ATTRIBUTE_NAME); if (executeTime == null) { Long startTime = (Long) request.getAttribute(START_TIME_ATTRIBUTE_NAME); Long endTime = System.currentTimeMillis(); executeTime = endTime - startTime; request.setAttribute(START_TIME_ATTRIBUTE_NAME, startTime); }//from w w w .j a va 2s . com if (modelAndView != null) { String viewName = modelAndView.getViewName(); if (!StringUtils.startsWith(viewName, REDIRECT_VIEW_NAME_PREFIX)) { modelAndView.addObject(EXECUTE_TIME_ATTRIBUTE_NAME, executeTime); } } if (logger.isDebugEnabled()) { logger.debug("[" + handler + "] executeTime: " + executeTime + "ms"); } }
From source file:biz.letsweb.lukasfloorspring.interceptors.MobileInterceptor.java
@Override public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView model) throws Exception { final String userAgent = request.getHeader(USER_AGENT_HEADER); if (userAgent != null) { // If the User-Agent matches a mobile device, then we set // the view name to the mobile view JSP so that a mobile // JSP is rendered instead of a normal view. if (isMobile(userAgent)) { if (model == null) { } else { final String view = model.getViewName(); model.setViewName(view + "-" + MOBILE_VIEWER_VIEW_NAME); }/* ww w . j av a2 s .c o m*/ } } }
From source file:com.carlos.projects.billing.ui.controllers.LoadComponentsControllerTest.java
@SuppressWarnings({ "unchecked" }) @Test// ww w. j a va 2 s .c om public void shouldLoadComponentsAndFamilyNameForAGivenFamilyCode() throws Exception { // Given Set<Component> components = mockComponents(); String familyName = "Family name"; when(family.getComponents()).thenReturn(components); when(family.getDescription()).thenReturn(familyName); // When ModelAndView modelAndView = controller.handleRequest(request, response); // Then verify(familyDao).getById(Family.class, familyCode); verify(family).getComponents(); verify(request).getParameter("familyCode"); assertThat((Set<Component>) modelAndView.getModel().get("components"), is(components)); assertThat((String) modelAndView.getModel().get("familyName"), is(familyName)); assertThat(modelAndView.getViewName(), is(controller.getViewName())); }
From source file:com.ms.commons.summer.web.handler.ComponentMethodHandlerAdapter.java
/** * @param request/*from w w w.ja v a 2s . c o m*/ * @param mv * @return */ private String buildViewName(HttpServletRequest request, ModelAndView mv, String nameSpace) { Object o = request.getAttribute(Widget.IS_WIDGET); boolean isWidget = o != null && "true".equals(o.toString()); String viewName = mv.getViewName(); if (viewName == null) { if (isWidget) { viewName = String.valueOf(request.getAttribute(Widget.WIDGET_URI)); } else { UrlPathHelper helper = new UrlPathHelper(); viewName = helper.getLookupPathForRequest(request); } } if (viewName.startsWith(WebResult.REDIRECT_URL_PREFIX)) { return viewName; } if (viewName.startsWith(WebResult.FORWARD_URL_PREFIX)) { return viewName; } // ?vm,?(.xxx) int index = viewName.indexOf("."); if (index != -1) { viewName = viewName.substring(0, index); } // : // /??/view/xxx/yyy/zzz // /??/widget/xxx/yyy/zzz if (nameSpace != null && nameSpace.length() > 0) { nameSpace = "/" + nameSpace; } else { nameSpace = ""; } if (isWidget) { return nameSpace + SummerVelocityLayoutView.DEFAULT_WIDGET_DIRECTORY + viewName; } else { return nameSpace + SummerVelocityLayoutView.DEFAULT_VIEW_DIRECTORY + viewName; } }
From source file:org.motechproject.server.outbox.web.VxmlOutboxControllerTest.java
@Test public void testSaveOutboxMessage() { String messageId = "mID"; String voiceMessageTypeName = "voicemessagetypename"; OutboundVoiceMessage voiceMessage = new OutboundVoiceMessage(); VoiceMessageType voiceMessageType = new VoiceMessageType(); voiceMessageType.setVoiceMessageTypeName(voiceMessageTypeName); voiceMessage.setVoiceMessageType(voiceMessageType); Mockito.when(request.getParameter("mId")).thenReturn(messageId); when(voiceOutboxService.getMessageById(messageId)).thenReturn(new OutboundVoiceMessage()); ModelAndView modelAndView = vxmlOutboxController.save(request, response); verify(voiceOutboxService).saveMessage(messageId); Assert.assertEquals(VxmlOutboxController.MESSAGE_SAVED_CONFIRMATION_TEMPLATE_NAME, modelAndView.getViewName()); }
From source file:org.motechproject.server.outbox.web.VxmlOutboxControllerTest.java
@Test public void testRemoveOutboxMessage() { String messageId = "mID"; when(request.getParameter("mId")).thenReturn(messageId); when(voiceOutboxService.getMessageById(messageId)).thenReturn(new OutboundVoiceMessage()); ModelAndView modelAndView = vxmlOutboxController.remove(request, response); verify(voiceOutboxService).setMessageStatus(messageId, OutboundVoiceMessageStatus.PLAYED); Assert.assertEquals(VxmlOutboxController.MESSAGE_REMOVED_CONFIRMATION_TEMPLATE_NAME, modelAndView.getViewName()); }
From source file:org.openmrs.module.radiology.web.controller.RadiologyOrderFormControllerTest.java
/** * @see RadiologyOrderFormController#getRadiologyOrderFormWithNewRadiologyOrder() */// w ww.j ava 2s. c o m @Test @Verifies(value = "should populate model and view with new radiology order", method = "getRadiologyOrderFormWithNewRadiologyOrder()") public void getRadiologyOrderFormWithNewRadiologyOrder_shouldPopulateModelAndViewWithNewRadiologyOrder() throws Exception { ModelAndView modelAndView = radiologyOrderFormController.getRadiologyOrderFormWithNewRadiologyOrder(); assertNotNull(modelAndView); assertThat(modelAndView.getViewName(), is("module/radiology/radiologyOrderForm")); assertThat(modelAndView.getModelMap(), hasKey("radiologyOrder")); RadiologyOrder order = (RadiologyOrder) modelAndView.getModelMap().get("radiologyOrder"); assertNull(order.getOrderId()); assertNotNull(order.getStudy()); assertNull(order.getStudy().getStudyId()); assertNull(order.getOrderer()); }