Package org.springframework.web.servlet

Examples of org.springframework.web.servlet.View


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

      assertSame(v1, v2);
    }
  }

  public void testNoSuchViewEnglish() throws Exception {
    View v = rb.resolveViewName("xxxxxxweorqiwuopeir", Locale.ENGLISH);
    assertTrue(v == null);
  }
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, 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<String, ?> 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

    RequestAttributes attrs = RequestContextHolder.getRequestAttributes();
    Assert.isInstanceOf(ServletRequestAttributes.class, attrs);
    List<MediaType> requestedMediaTypes = getMediaTypes(((ServletRequestAttributes) attrs).getRequest());
    if (requestedMediaTypes != null) {
      List<View> candidateViews = getCandidateViews(viewName, locale, requestedMediaTypes);
      View bestView = getBestView(candidateViews, requestedMediaTypes, attrs);
      if (bestView != null) {
        return bestView;
      }
    }
    if (this.useNotAcceptableStatusCode) {
View Full Code Here

  private List<View> getCandidateViews(String viewName, Locale locale, List<MediaType> requestedMediaTypes)
      throws Exception {

    List<View> candidateViews = new ArrayList<View>();
    for (ViewResolver viewResolver : this.viewResolvers) {
      View view = viewResolver.resolveViewName(viewName, locale);
      if (view != null) {
        candidateViews.add(view);
      }
      for (MediaType requestedMediaType : requestedMediaTypes) {
        List<String> extensions = this.contentNegotiationManager.resolveFileExtensions(requestedMediaType);
View Full Code Here

   * @see org.springframework.beans.factory.InitializingBean#afterPropertiesSet
   */
  @Override
  protected View loadView(String viewName, Locale locale) throws Exception {
    AbstractUrlBasedView view = buildView(viewName);
    View result = applyLifecycleMethods(viewName, view);
    return (view.checkResource(locale) ? result : null);
  }
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.