Package org.springframework.web.servlet

Examples of org.springframework.web.servlet.View


   * @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, PortletRequest request, MimeResponse response) throws Exception {
    View view;
    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;
    }

    // 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


   * (typically in case of problems creating an actual View object)
   * @see ViewResolver#resolveViewName
   */
  protected View resolveViewName(String viewName, Map model, PortletRequest request) throws Exception {
    for (ViewResolver viewResolver : this.viewResolvers) {
      View view = viewResolver.resolveViewName(viewName, request.getLocale());
      if (view != null) {
        return view;
      }
    }
    return null;
View Full Code Here

      return createView(viewName, locale);
    }
    else {
      Object cacheKey = getCacheKey(viewName, locale);
      synchronized (this.viewCache) {
        View view = (View) this.viewCache.get(cacheKey);
        if (view == null) {
          // Ask the subclass to create the View object.
          view = createView(viewName, locale);
          this.viewCache.put(cacheKey, view);
          if (logger.isDebugEnabled()) {
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

  }


  public void testParentsAreAbstract() throws Exception {
    try {
      View v = rb.resolveViewName("debug.Parent", Locale.ENGLISH);
      fail("Should have thrown BeanIsAbstractException");
    }
    catch (BeanIsAbstractException ex) {
      // expected
    }
    try {
      View v = rb.resolveViewName("testParent", Locale.ENGLISH);
      fail("Should have thrown BeanIsAbstractException");
    }
    catch (BeanIsAbstractException ex) {
      // expected
    }
View Full Code Here

      // expected
    }
  }

  public void testDebugViewEnglish() throws Exception {
    View v = rb.resolveViewName("debugView", Locale.ENGLISH);
    assertTrue("debugView must be of type InternalResourceView", v instanceof InternalResourceView);
    InternalResourceView jv = (InternalResourceView) v;
    assertTrue("debugView must have correct URL", "jsp/debug/debug.jsp".equals(jv.getUrl()));

    Map m = jv.getStaticAttributes();
View Full Code Here

    assertTrue("Correct default content type", jv.getContentType().equals(AbstractView.DEFAULT_CONTENT_TYPE));
  }

  public void testDebugViewFrench() throws Exception {
    View v = rb.resolveViewName("debugView", Locale.FRENCH);
    assertTrue("French debugView must be of type InternalResourceView", v instanceof InternalResourceView);
    InternalResourceView jv = (InternalResourceView) v;
    assertTrue("French debugView must have correct URL", "jsp/debug/deboug.jsp".equals(jv.getUrl()));
    assertTrue(
      "Correct overridden (XML) content type, not '" + jv.getContentType() + "'",
View Full Code Here

    rb.setCache(getCache());
    rb.setDefaultParentView("testParent");
    rb.setLocalesToInitialize(new Locale[] {Locale.ENGLISH, Locale.FRENCH});
    rb.setApplicationContext(wac);

    View v = rb.resolveViewName("debugView", Locale.FRENCH);
    assertTrue("French debugView must be of type InternalResourceView", v instanceof InternalResourceView);
    InternalResourceView jv = (InternalResourceView) v;
    assertTrue("French debugView must have correct URL", "jsp/debug/deboug.jsp".equals(jv.getUrl()));
    assertTrue(
      "Correct overridden (XML) content type, not '" + jv.getContentType() + "'",
View Full Code Here

      jv.getContentType().equals("text/xml;charset=ISO-8859-1"));
  }

  public void testSameBundleOnlyCachedOnce() throws Exception {
    if (rb.isCache()) {
      View v1 = rb.resolveViewName("debugView", Locale.ENGLISH);
      View v2 = rb.resolveViewName("debugView", Locale.UK);
      assertSame(v1, v2);
    }
  }
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.