Java Code Examples for org.springframework.web.servlet.ModelAndView

The following code examples are extracted from open source projects. You can click to vote up the examples that are useful to you.

Example 1

From project alphaportal_dev, under directory /sys-src/alphaportal/web/src/test/java/alpha/portal/webapp/controller/.

Source file: CaseFormControllerTest.java

  23 
vote

/** 
 * Test new.
 * @throws Exception the exception
 */
@Test public void testNew() throws Exception {
  final MockHttpServletRequest request=this.newGet("/caseform");
  request.setRemoteUser("admin");
  final HttpServletResponse response=new MockHttpServletResponse();
  final ModelAndView mv=this.form.showForm(this.filters,request,response);
  Assert.assertNotNull(mv);
  Assert.assertEquals("caseform",mv.getViewName());
  Assert.assertEquals(new AlphaCase(),mv.getModel().get("case"));
}
 

Example 2

From project alphaportal_dev, under directory /sys-src/alphaportal/web/src/test/java/alpha/portal/webapp/controller/.

Source file: CaseFormControllerTest.java

  22 
vote

/** 
 * Test last.
 * @throws Exception the exception
 */
@Test public void testLast() throws Exception {
  MockHttpServletRequest request=this.newGet("/caseform");
  request.setParameter("caseId","550e4713-e22b-11d4-a716-446655440002");
  request.setRemoteUser("admin");
  ModelAndView mv=this.form.showForm(this.filters,request,new MockHttpServletResponse());
  request=this.newGet("/caseform");
  request.setParameter("caseId","last");
  request.setRemoteUser("admin");
  final AlphaCase aCase=this.caseManager.get("550e4713-e22b-11d4-a716-446655440002");
  mv=this.form.showForm(this.filters,request,new MockHttpServletResponse());
  Assert.assertEquals("caseform",mv.getViewName());
  Assert.assertEquals(aCase,mv.getModel().get("case"));
}
 

Example 3

From project aranea, under directory /server/src/main/java/no/dusken/aranea/admin/control/.

Source file: AddRelationPageSearchController.java

  22 
vote

@Override protected ModelAndView handle(HttpServletRequest request,HttpServletResponse response,Object o,BindException e) throws Exception {
  ModelAndView mav=super.handle(request,response,o,e);
  Long pageID=ServletRequestUtils.getLongParameter(request,"referencePage",0);
  Page page=pageService.getEntity(pageID);
  mav.getModel().put("referencePage",page);
  return mav;
}
 

Example 4

From project aranea, under directory /server/src/main/java/no/dusken/aranea/admin/control/.

Source file: AddRelationSearchController.java

  22 
vote

@Override protected ModelAndView handle(HttpServletRequest request,HttpServletResponse response,Object o,BindException e) throws Exception {
  ModelAndView mav=super.handle(request,response,o,e);
  Long pageID=ServletRequestUtils.getLongParameter(request,"referencePage",0);
  Page page=pageService.getEntity(pageID);
  mav.getModel().put("referencePage",page);
  return mav;
}
 

Example 5

From project arquillian-extension-spring, under directory /arquillian-warp-spring/src/main/java/org/jboss/arquillian/warp/extension/spring/servlet/.

Source file: WarpDispatcherServlet.java

  22 
vote

/** 
 * {@inheritDoc}
 */
@Override protected ModelAndView processHandlerException(HttpServletRequest request,HttpServletResponse response,Object handler,Exception ex) throws Exception {
  ModelAndView mv=super.processHandlerException(request,response,handler,ex);
  SpringMvcResultImpl mvcResult=getMvcResult(request);
  mvcResult.setModelAndView(mv);
  mvcResult.setException(ex);
  return mv;
}
 

Example 6

From project arquillian-extension-spring, under directory /arquillian-warp-spring/src/test/java/org/jboss/arquillian/warp/extension/spring/container/.

Source file: SpringMvcResultImplTestCase.java

  22 
vote

/** 
 * <p>Tests both  {@link SpringMvcResultImpl#setModelAndView(ModelAndView)} and {@link SpringMvcResultImpl#getModelAndView()} method.</p>
 */
@Test public void testModelAndViewProperty(){
  ModelAndView modelAndView=mock(ModelAndView.class);
  assertNull("The property has invalid value.",instance.getModelAndView());
  instance.setModelAndView(modelAndView);
  assertEquals("The property value is invalid.",modelAndView,instance.getModelAndView());
}
 

Example 7

From project banshun, under directory /banshun/web/src/test/java/com/griddynamics/banshun/web/.

Source file: AnnotatedTestController.java

  22 
vote

@RequestMapping("/annotation-test.html") public ModelAndView annotationTest(){
  String message="Hello Spring MVC";
  ModelAndView modelAndView=new ModelAndView("testView");
  modelAndView.addObject("message",message);
  return modelAndView;
}
 

Example 8

From project banshun, under directory /banshun/web/src/test/java/com/griddynamics/banshun/web/.

Source file: AnnotatedTestController.java

  22 
vote

@RequestMapping("/another-annotation-test.html") public ModelAndView anotherAnnotationTest(){
  String message="Hello Another Spring MVC";
  ModelAndView modelAndView=new ModelAndView("testView");
  modelAndView.addObject("message",message);
  return modelAndView;
}
 

Example 9

From project Carolina-Digital-Repository, under directory /admin/src/main/java/edu/unc/lib/dl/ui/.

Source file: AjaxPathController.java

  22 
vote

@RequestMapping("/ajax/getallpaths") public ModelAndView handleRequest(HttpServletRequest request,HttpServletResponse response) throws Exception {
  logger.debug("**************** in Ajax Path Controller *************");
  List paths=uiWebService.getCollectionPaths("test");
  ModelAndView mav=new ModelAndView(new JsonView());
  mav.addObject("paths",paths);
  return mav;
}
 

Example 10

From project Carolina-Digital-Repository, under directory /admin/src/main/java/edu/unc/lib/dl/ui/.

Source file: UpdateModsController.java

  22 
vote

@RequestMapping(value="/admin/updatemods",method=RequestMethod.GET) public ModelAndView accessMods(HttpServletRequest request,@RequestParam String pid){
  String objectLabel=tripleStoreQueryService.lookupLabel(pid);
  ModelAndView mv=new ModelAndView("modseditor");
  mv.addObject("objectLabel",objectLabel);
  return mv;
}
 

Example 11

From project cas, under directory /cas-server-core/src/main/java/org/jasig/cas/services/web/.

Source file: ManageRegisteredServicesMultiActionController.java

  22 
vote

/** 
 * Method to delete the RegisteredService by its ID.
 * @param request the HttpServletRequest
 * @param response the HttpServletResponse
 * @return the Model and View to go to after the service is deleted.
 */
public ModelAndView deleteRegisteredService(final HttpServletRequest request,final HttpServletResponse response){
  final String id=request.getParameter("id");
  final long idAsLong=Long.parseLong(id);
  final ModelAndView modelAndView=new ModelAndView(new RedirectView("manage.html",true),"status","deleted");
  final RegisteredService r=this.servicesManager.delete(idAsLong);
  modelAndView.addObject("serviceName",r != null ? r.getName() : "");
  return modelAndView;
}
 

Example 12

From project cas, under directory /cas-server-core/src/main/java/org/jasig/cas/web/.

Source file: DelegatingController.java

  22 
vote

private ModelAndView generateErrorView(final String code,final String description,final Object[] args){
  final ModelAndView modelAndView=new ModelAndView(this.failureView);
  final String convertedDescription=getMessageSourceAccessor().getMessage(description,args,description);
  modelAndView.addObject("code",code);
  modelAndView.addObject("description",convertedDescription);
  return modelAndView;
}
 

Example 13

From project jahspotify, under directory /web/src/main/java/jahspotify/web/ui/.

Source file: HistoryBrowswerUIController.java

  22 
vote

@RequestMapping(value="/recent") public ModelAndView retrieveHistory(@RequestParam(value="index",defaultValue="0") int index,@RequestParam(value="count",defaultValue="${jahspotify.history.default-count}") int count){
  final ModelAndView modelAndView=new ModelAndView("/jsp/history.jsp");
  final Collection<TrackHistory> trackHistories=_historicalStorage.getHistory(index,count);
  modelAndView.addObject("trackHistories",trackHistories);
  modelAndView.addObject("index",index);
  modelAndView.addObject("count",count);
  return modelAndView;
}
 

Example 14

From project jahspotify, under directory /web/src/main/java/jahspotify/web/ui/.

Source file: HistoryBrowswerUIController.java

  22 
vote

@RequestMapping(value="/trackhistory/{queueTrackLink}") public ModelAndView trackHistoryDetail(@PathVariable(value="queueTrackLink") String queueTrackLink){
  final Link link=Link.create(queueTrackLink);
  final TrackHistory trackHistory=_historicalStorage.getHistory(link);
  final TrackStatistics trackStatistics=_historicalStorage.getTrackStatistics(trackHistory.getTrackLink());
  final ModelAndView modelAndView=new ModelAndView("/jsp/track-history-detail.jsp");
  modelAndView.addObject("trackStatistics",trackStatistics);
  return modelAndView;
}
 

Example 15

From project androidpn, under directory /androidpn-server-bin-tomcat/src/org/androidpn/server/console/controller/.

Source file: NotificationController.java

  21 
vote

public ModelAndView send(HttpServletRequest request,HttpServletResponse response) throws Exception {
  String broadcast=ServletRequestUtils.getStringParameter(request,"broadcast","Y");
  String username=ServletRequestUtils.getStringParameter(request,"username");
  String title=ServletRequestUtils.getStringParameter(request,"title");
  String message=ServletRequestUtils.getStringParameter(request,"message");
  String uri=ServletRequestUtils.getStringParameter(request,"uri");
  String apiKey=Config.getString("apiKey","");
  logger.debug("apiKey=" + apiKey);
  if (broadcast.equalsIgnoreCase("Y")) {
    notificationManager.sendBroadcast(apiKey,title,message,uri);
  }
 else {
    notificationManager.sendNotifcationToUser(apiKey,username,title,message,uri);
  }
  ModelAndView mav=new ModelAndView();
  mav.setViewName("redirect:notification.do");
  return mav;
}
 

Example 16

From project androidpn, under directory /androidpn-server-bin-tomcat/src/org/androidpn/server/console/controller/.

Source file: UserController.java

  21 
vote

public ModelAndView list(HttpServletRequest request,HttpServletResponse response) throws Exception {
  PresenceManager presenceManager=new PresenceManager();
  List<User> userList=userService.getUsers();
  for (  User user : userList) {
    if (presenceManager.isAvailable(user)) {
      user.setOnline(true);
    }
 else {
      user.setOnline(false);
    }
  }
  ModelAndView mav=new ModelAndView();
  mav.addObject("userList",userList);
  mav.setViewName("user/list");
  return mav;
}
 

Example 17

From project egov-data, under directory /easyCompany2/src/main/java/egovframework/rte/tex/com/web/.

Source file: EgovCommonController.java

  21 
vote

@RequestMapping(value="/com/ajax.do") protected ModelAndView egovMain(String tabName,HttpServletRequest request) throws Exception {
  Locale locale=localeResolver.resolveLocale(request);
  Map<String,Object> model=new HashMap<String,Object>();
  model.put("divId","." + tabName);
  model.put("description",messageSource.getMessage(tabName,null,locale));
  return new ModelAndView(ajaxMainView,model);
}
 

Example 18

From project egov-data, under directory /easyCompany2/src/main/java/egovframework/rte/tex/dlv/web/.

Source file: EgovDeliveryController.java

  21 
vote

@RequestMapping("/dlv/viewXML.do") public ModelAndView viewXML(@ModelAttribute("searchVO") SearchVO searchVO) throws Exception {
  List<PurchaseVO> purchsList=egovDeliveryService.selectAllPurchaseXml();
  Map<String,Object> model=new HashMap<String,Object>();
  model.put("purchsList",purchsList);
  return new ModelAndView(purMarshallingView,model);
}
 

Example 19

From project elw, under directory /web/src/main/java/elw/web/.

Source file: AdminController.java

  21 
vote

@RequestMapping(value="index",method=RequestMethod.GET) public ModelAndView do_index(final HttpServletRequest req,final HttpServletResponse resp) throws IOException {
  final HashMap<String,Object> model=auth(req,resp,true,false);
  if (model == null) {
    return null;
  }
  return new ModelAndView("a/index",model);
}
 

Example 20

From project elw, under directory /web/src/main/java/elw/web/.

Source file: AdminController.java

  21 
vote

@RequestMapping(value="rest/index",method=RequestMethod.GET) public ModelAndView do_restIndex(final HttpServletRequest req,final HttpServletResponse resp) throws IOException {
  final HashMap<String,Object> model=auth(req,resp,false,false);
  if (model == null) {
    return null;
  }
  final List<Enrollment> enrolls=core.getQueries().enrollments();
  final List<IndexRow> indexData=core.index(enrolls);
  return new ModelAndView(ViewJackson.success(indexData));
}
 

Example 21

From project greenhouse, under directory /src/main/java/com/springsource/greenhouse/home/.

Source file: GlobalExceptionResolver.java

  21 
vote

public ModelAndView resolveException(HttpServletRequest request,HttpServletResponse response,Object handler,Exception ex){
  try {
    if (ex instanceof EmptyResultDataAccessException) {
      return handleEmptyResultDataAccessException((EmptyResultDataAccessException)ex,request,response,handler);
    }
  }
 catch (  Exception e) {
    logger.warn("Handling of [" + ex.getClass().getName() + "] resulted in Exception",ex);
    return null;
  }
  ModelAndView result=annotatedExceptionHandler.resolveException(request,response,handler,ex);
  if (result != null) {
    return result;
  }
  return defaultExceptionHandler.resolveException(request,response,handler,ex);
}
 

Example 22

From project amber, under directory /oauth-2.0/client-demo/src/main/java/org/apache/amber/oauth2/client/demo/controller/.

Source file: AuthzController.java

  20 
vote

@RequestMapping("/authorize") public ModelAndView authorize(@ModelAttribute("oauthParams") OAuthParams oauthParams,HttpServletRequest req,HttpServletResponse res) throws OAuthSystemException, IOException {
  try {
    Utils.validateAuthorizationParams(oauthParams);
    res.addCookie(new Cookie("clientId",oauthParams.getClientId()));
    res.addCookie(new Cookie("clientSecret",oauthParams.getClientSecret()));
    res.addCookie(new Cookie("authzEndpoint",oauthParams.getAuthzEndpoint()));
    res.addCookie(new Cookie("tokenEndpoint",oauthParams.getTokenEndpoint()));
    res.addCookie(new Cookie("redirectUri",oauthParams.getRedirectUri()));
    res.addCookie(new Cookie("scope",oauthParams.getScope()));
    res.addCookie(new Cookie("app",oauthParams.getApplication()));
    OAuthClientRequest request=OAuthClientRequest.authorizationLocation(oauthParams.getAuthzEndpoint()).setClientId(oauthParams.getClientId()).setRedirectURI(oauthParams.getRedirectUri()).setResponseType(ResponseType.CODE.toString()).setScope(oauthParams.getScope()).buildQueryMessage();
    return new ModelAndView(new RedirectView(request.getLocationUri()));
  }
 catch (  ApplicationException e) {
    oauthParams.setErrorMessage(e.getMessage());
    return new ModelAndView("get_authz");
  }
}
 

Example 23

From project amber, under directory /oauth-2.0/client-demo/src/main/java/org/apache/amber/oauth2/client/demo/controller/.

Source file: MainController.java

  20 
vote

@RequestMapping("/main/{app}") public ModelAndView authorize(@ModelAttribute("oauthParams") OAuthParams oauthParams,@ModelAttribute("oauthRegParams") OAuthRegParams oauthRegParams,@PathVariable("app") String app,HttpServletResponse res) throws OAuthSystemException, IOException {
  boolean selected=false;
  if (Utils.GITHUB.equals(app)) {
    selected=true;
    oauthParams.setAuthzEndpoint(Utils.GITHUB_AUTHZ);
    oauthParams.setTokenEndpoint(Utils.GITHUB_TOKEN);
  }
 else   if (Utils.FACEBOOK.equals(app)) {
    selected=true;
    oauthParams.setAuthzEndpoint(Utils.FACEBOOK_AUTHZ);
    oauthParams.setTokenEndpoint(Utils.FACEBOOK_TOKEN);
  }
 else   if (Utils.GOWALLA.equals(app)) {
    selected=true;
    oauthParams.setAuthzEndpoint(Utils.GOWALLA_AUTHZ);
    oauthParams.setTokenEndpoint(Utils.GOWALLA_TOKEN);
  }
 else   if (Utils.SMART_GALLERY.equals(app)) {
    selected=true;
    oauthRegParams.setAuthzEndpoint(Utils.SMART_GALLERY_AUTHZ);
    oauthRegParams.setTokenEndpoint(Utils.SMART_GALLERY_TOKEN);
    oauthRegParams.setRegistrationEndpoint(Utils.SMART_GALLERY_REGISTER);
    oauthRegParams.setApplication(app);
    oauthRegParams.setRedirectUri(Utils.REDIRECT_URI);
    return new ModelAndView("register");
  }
  if (selected) {
    oauthParams.setApplication(app);
    oauthParams.setRedirectUri(Utils.REDIRECT_URI);
    return new ModelAndView("get_authz");
  }
  return new ModelAndView("index");
}
 

Example 24

From project email-preview, under directory /src/main/java/org/jasig/portlet/emailpreview/controller/.

Source file: MailStoreConfigurationController.java

  20 
vote

@ResourceMapping(value="parameters") public ModelAndView getParameters(ResourceRequest req,ResourceResponse res,@RequestParam("linkService") String linkServiceKey,@RequestParam("authService") String authServiceKey) throws IOException {
  Map<String,Object> model=new HashMap<String,Object>();
  try {
    final IAuthenticationService authService=authServiceRegistry.getAuthenticationService(authServiceKey);
    if (authService != null) {
      final List<ConfigurationParameter> authParams=authService.getAdminConfigurationParameters();
      model.put("authParams",authParams);
    }
    final IEmailLinkService linkService=linkServiceRegistry.getEmailLinkService(linkServiceKey);
    if (linkService != null) {
      final List<ConfigurationParameter> linkParams=linkService.getAdminConfigurationParameters();
      model.put("linkParams",linkParams);
    }
  }
 catch (  Exception ex) {
    log.error("Error encountered attempting to retrieve parameter definitions",ex);
    res.setProperty(ResourceResponse.HTTP_STATUS_CODE,Integer.toString(HttpServletResponse.SC_INTERNAL_SERVER_ERROR));
    model.put("error","Error encountered attempting to retrieve parameter definitions");
  }
  return new ModelAndView("json",model);
}
 

Example 25

From project excilys-bank, under directory /excilys-bank-web/src/main/java/com/excilys/ebi/bank/web/interceptor/.

Source file: AnnotatedMethodHandlerInterceptor.java

  19 
vote

@Override public void postHandle(HttpServletRequest request,HttpServletResponse response,Object handler,ModelAndView modelAndView) throws Exception {
  if (modelAndView != null && !isRedirect(modelAndView) && handler instanceof HandlerMethod) {
    HandlerMethod handlerMethod=HandlerMethod.class.cast(handler);
    if (shouldIntercept(handlerMethod)) {
      @SuppressWarnings({"rawtypes","unchecked"}) Map<String,?> pathVariables=(Map)request.getAttribute(View.PATH_VARIABLES);
      postHandleInternal(request,response,handlerMethod,modelAndView,pathVariables);
    }
  }
}