Package org.springframework.web.servlet

Examples of org.springframework.web.servlet.View


      assertSame(v1, v2);
    }
  }

  public void testNoSuchViewEnglish() throws Exception {
    View v = rb.resolveViewName("xxxxxxweorqiwuopeir", Locale.ENGLISH);
    assertTrue(v == null);
  }
View Full Code Here


  }
 
  public void testNoSuchBasename() throws Exception {
    try {
      rb.setBasename("weoriwoierqupowiuer");
      View v = rb.resolveViewName("debugView", Locale.ENGLISH);
      fail("No such basename: all requests should fail with exception");
    }
    catch (MissingResourceException ex) {
      // OK
    }
View Full Code Here

   * @param request current portlet render request
   * @param response current portlet render response
   * @throws Exception if there's a problem rendering the view
   */
  protected void render(ModelAndView mv, RenderRequest request, RenderResponse response) throws Exception {
    View view = null;
    if (mv.isReference()) {
      // We need to resolve the view name.
      view = resolveViewName(mv.getViewName(), mv.getModelInternal(), request);
      if (view == null) {
        throw new PortletException("Could not resolve view with name '" + mv.getViewName() +
            "' in portlet with name '" + getPortletName() + "'");
      }
    }
    else {
      // No need to lookup: the ModelAndView object contains the actual View object.
      Object viewObject = mv.getView();
      if (viewObject == null) {
        throw new PortletException("ModelAndView [" + mv + "] neither contains a view name nor a " +
            "View object in portlet with name '" + getPortletName() + "'");
      }
      if (!(viewObject instanceof View)) {
        throw new PortletException(
            "View object [" + viewObject + "] is not an instance of [org.springframework.web.servlet.View] - " +
            "DispatcherPortlet does not support any other view types");
      }
      view = (View) viewObject;
    }

    if (view == null) {
      throw new PortletException("Could not resolve view with name '" + mv.getViewName() +
          "' in portlet with name '" + getPortletName() + "'");
    }

    // Set the content type on the response if needed and if possible.
    // The Portlet spec requires the content type to be set on the RenderResponse;
    // it's not sufficient to let the View set it on the ServletResponse.
    if (response.getContentType() != null) {
      if (logger.isDebugEnabled()) {
        logger.debug("Portlet response content type already set to [" + response.getContentType() + "]");
      }
    }
    else {
      // No Portlet content type specified yet -> use the view-determined type.
      String contentType = view.getContentType();
      if (contentType != null) {
        if (logger.isDebugEnabled()) {
          logger.debug("Setting portlet response content type to view-determined type [" + contentType + "]");
        }
        response.setContentType(contentType);
View Full Code Here

   * @see ViewResolver#resolveViewName
   */
  protected View resolveViewName(String viewName, Map model, RenderRequest request) throws Exception {
    for (Iterator it = this.viewResolvers.iterator(); it.hasNext();) {
      ViewResolver viewResolver = (ViewResolver) it.next();
      View view = viewResolver.resolveViewName(viewName, request.getLocale());
      if (view != null) {
        return view;
      }
    }
    return null;
View Full Code Here

    VelocityViewResolver vr = new VelocityViewResolver();
    vr.setPrefix("prefix_");
    vr.setSuffix("_suffix");
    vr.setApplicationContext(wac);

    View view = vr.resolveViewName("test", Locale.CANADA);
    assertEquals("Correct view class", VelocityView.class, view.getClass());
    assertEquals("Correct URL", "prefix_test_suffix", ((VelocityView) view).getUrl());

    view = vr.resolveViewName("redirect:myUrl", Locale.getDefault());
    assertEquals("Correct view class", RedirectView.class, view.getClass());
    assertEquals("Correct URL", "myUrl", ((RedirectView) view).getUrl());

    view = vr.resolveViewName("forward:myUrl", Locale.getDefault());
    assertEquals("Correct view class", InternalResourceView.class, view.getClass());
    assertEquals("Correct URL", "myUrl", ((InternalResourceView) view).getUrl());
  }
View Full Code Here

    vr.setPrefix("prefix_");
    vr.setSuffix("_suffix");
    vr.setToolboxConfigLocation(toolbox);
    vr.setApplicationContext(wac);

    View view = vr.resolveViewName("test", Locale.CANADA);
    assertEquals("Correct view class", VelocityToolboxView.class, view.getClass());
    assertEquals("Correct URL", "prefix_test_suffix", ((VelocityView) view).getUrl());
    assertEquals("Correct toolbox", toolbox, ((VelocityToolboxView) view).getToolboxConfigLocation());
  }
View Full Code Here

    vr.setPrefix("prefix_");
    vr.setSuffix("_suffix");
    vr.setToolboxConfigLocation(toolbox);
    vr.setApplicationContext(wac);

    View view = vr.resolveViewName("test", Locale.CANADA);
    assertEquals("Correct view class", VelocityLayoutView.class, view.getClass());
    assertEquals("Correct URL", "prefix_test_suffix", ((VelocityView) view).getUrl());
    assertEquals("Correct toolbox", toolbox, ((VelocityToolboxView) view).getToolboxConfigLocation());
  }
View Full Code Here

    vr.setLayoutUrl("myLayoutUrl");
    vr.setLayoutKey("myLayoutKey");
    vr.setScreenContentKey("myScreenContentKey");
    vr.setApplicationContext(wac);

    View view = vr.resolveViewName("test", Locale.CANADA);
    assertEquals("Correct view class", VelocityLayoutView.class, view.getClass());
    assertEquals("Correct URL", "prefix_test_suffix", ((VelocityView) view).getUrl());
    // TODO: Need to test actual VelocityLayoutView properties and their functionality!
  }
View Full Code Here

    WebApplicationContext wac = prepareWebApplicationContext();

    InternalResourceViewResolver irvr = new InternalResourceViewResolver();
    irvr.setApplicationContext(wac);
    irvr.setViewClass(TilesView.class);
    View view = irvr.resolveViewName("testTile", new Locale("nl", ""));

    MockHttpServletRequest request = new MockHttpServletRequest(wac.getServletContext());
    MockHttpServletResponse response = new MockHttpServletResponse();
    request.setAttribute(DispatcherServlet.WEB_APPLICATION_CONTEXT_ATTRIBUTE, wac);
    request.setAttribute(DispatcherServlet.LOCALE_RESOLVER_ATTRIBUTE, new AcceptHeaderLocaleResolver());

    view.render(new HashMap(), request, response);
    assertEquals("/WEB-INF/jsp/layout.jsp", response.getForwardedUrl());
    ComponentContext cc = (ComponentContext) request.getAttribute(ComponentConstants.COMPONENT_CONTEXT);
    assertNotNull(cc);
    PathAttribute attr = (PathAttribute) cc.getAttribute("content");
    assertEquals("/WEB-INF/jsp/content.jsp", attr.getValue());

    view.render(new HashMap(), request, response);
    assertEquals("/WEB-INF/jsp/layout.jsp", response.getForwardedUrl());
    cc = (ComponentContext) request.getAttribute(ComponentConstants.COMPONENT_CONTEXT);
    assertNotNull(cc);
    attr = (PathAttribute) cc.getAttribute("content");
    assertEquals("/WEB-INF/jsp/content.jsp", attr.getValue());
View Full Code Here

    StaticWebApplicationContext wac = prepareWebApplicationContext();

    InternalResourceViewResolver irvr = new InternalResourceViewResolver();
    irvr.setApplicationContext(wac);
    irvr.setViewClass(TilesJstlView.class);
    View view = irvr.resolveViewName("testTile", new Locale("nl", ""));

    MockHttpServletRequest request = new MockHttpServletRequest(wac.getServletContext());
    MockHttpServletResponse response = new MockHttpServletResponse();
    request.setAttribute(DispatcherServlet.WEB_APPLICATION_CONTEXT_ATTRIBUTE, wac);
    request.setAttribute(DispatcherServlet.LOCALE_RESOLVER_ATTRIBUTE, new FixedLocaleResolver(locale));
    wac.addMessage("code1", locale, "messageX");
    view.render(new HashMap(), request, response);

    assertEquals("/WEB-INF/jsp/layout.jsp", response.getForwardedUrl());
    ComponentContext cc = (ComponentContext) request.getAttribute(ComponentConstants.COMPONENT_CONTEXT);
    assertNotNull(cc);
    PathAttribute attr = (PathAttribute) cc.getAttribute("content");
View Full Code Here

TOP

Related Classes of org.springframework.web.servlet.View

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.