Page 2 of 2 FirstFirst 12
Results 11 to 12 of 12

Thread: Chaining view resolvers(InternalResourceViewResolver,AjaxUrlBase dViewResolver )prob.

  1. #11
    Join Date
    Feb 2008
    Location
    Vermont
    Posts
    32

    Default UrlBasedViewResovlers should allow you to specify if they can be chainable

    1. Always provide a list of views generated/handled by this ViewResolver (not very nice is it)
    2. As a fallback assume that the view is loadable with the current ResourceLoader (is going to fail miserably if you use something like tiles, velocity of freemarker which either don't have actual files or load files with a different strategy).
    So in situations where you are pulling from files out of the resource path - you can make those assumptions.

    Why not expose a parameter on the UrlBasedViewResolver that is something like:

    viewsAreFileBacked or some other flag (with a better name than that) - set to be false by default - that when true enables the UrlBasedViewResolvers to chain.

    The insistence that you can't make those assumptions causes everyone I know of to immediately subclass and override the view resolver to allow it to chain - because in most situations you CAN chain the view resolvers - except in the limited situations you are talking about.

  2. #12

    Thumbs up Fallback View Resolver (Similar to chain)

    Chaining View Resolver using order property helps you in Spring 3 but in 2.5 you have to handle it somewhat differently.

    Because when we configure the multimple InternalResourceviewResolver in Spring 2.5,(which in in turn is UrlBasedViewResolver) I consider only the first bean (ViewResolver) occurance or bean with order 1 to resolve view and do not pass it to the next view resolver bean with higer order.

    I think this could help you in many ways

    package com.util;

    import java.util.Locale;

    import org.springframework.web.servlet.View;
    import org.springframework.web.servlet.view.InternalResou rceViewResolver;

    public class FallbackJstlViewResolver extends InternalResourceViewResolver {

    private InternalResourceViewResolver mFallBackViewResolver ;

    public View resolveViewName(String pViewName , Locale pLocale)throws Exception{
    System.out.println("ChainableJstlViewResolver "+pViewName+" "+pLocale);

    View lView =null;

    String lResourecePath = getPrefix()+pViewName+getSuffix();
    if (!getApplicationContext().getResource(lResourecePa th).exists()){
    System.out.println("Inside If : "+lResourecePath+"Not found");
    if (mFallBackViewResolver == null){
    System.out.print("No fall back view resolver configured");
    lView = super.resolveViewName(pViewName, pLocale);
    }else{
    System.out.print("Resolving view using fallback view resolver");
    lView = mFallBackViewResolver.resolveViewName(pViewName, pLocale);
    }

    }else{
    System.out.println("Inside Else");
    lView = super.resolveViewName(pViewName, pLocale);

    }
    System.out.println(lResourecePath);
    return lView;
    }

    public void setFallBackViewResolver(InternalResourceViewResolv er pFallBackViewResolver){
    mFallBackViewResolver = pFallBackViewResolver;
    }
    }


    -------------------Bean Configuration ----------------------

    <bean id="ClientView" class="com.util.FallbackJstlViewResolver">
    <property name="viewClass" value="org.springframework.web.servlet.view.JstlVi ew"/>
    <property name="prefix" value="/jsps/client1/"/>
    <property name="suffix" value=".jsp"/>
    <property name="fallBackViewResolver" ref="ProductView"/>
    <property name="order" value="1"/>
    </bean>

    <bean id="ProductView" class="org.springframework.web.servlet.view.Intern alResourceViewResolver">
    <property name="viewClass" value="org.springframework.web.servlet.view.JstlVi ew"/>
    <property name="prefix" value="/jsps/"/>
    <property name="suffix" value=".jsp"/>
    <property name="order" value="2"/>
    </bean>
    Last edited by prashanthjoshi; Sep 22nd, 2009 at 11:58 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •