Announcement Announcement Module
Collapse
No announcement yet.
using both jsp and freemarker + confused with mapping Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • using both jsp and freemarker + confused with mapping

    Hi,

    I am trying to use jsp and freemarker together. The freemarker part works, but the jsp part does not because freemarker tries to find the corresponding template.
    Configuration :

    Code:
    <bean id="viewResolver"
    		class="org.springframework.web.servlet.view.UrlBasedViewResolver">
    		<property name="viewClass">
    			<value>
    				org.springframework.web.servlet.view.InternalResourceView
    			</value>
    		</property>
    		<property name="prefix">
    			<value>/WEB-INF/jsp/</value>
    		</property>
    		<property name="suffix">
    			<value>.jsp</value>
    		</property>
    	</bean>
    
    	<!-- freemarker config -->
    	<bean id="freemarkerConfig"
    		class="org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer">
    		<property name="templateLoaderPath"
    			value="/WEB-INF/freemarker/" />
    	</bean>
    
    	<bean id="freemarkerViewResolver"
    		class="org.springframework.web.servlet.view.freemarker.FreeMarkerViewResolver">
    		<property name="cache" value="true" />
    		<property name="prefix" value="" />
    		<property name="suffix" value=".ftl" />
    	</bean>
    I thought that by putting the jsp part first, if spring finds a jsp file with the right name, it would output the jsp. If het jsp file does not exist, then it will look for the freemarker template. Clearly this is not happening. Also the order property (mentioned in the docs) is not available.
    Is there a way to solve this problem or should I just choose one of the two views ?

    My second question is about how an url is mapped to a controller.
    I would like to achieve that an url like :
    http://localhost:8080/webapp/admin/ is mapped to a method named 'overview'. and an url like http://localhost:8080/webapp/admin/listall is mapped to a method named 'listall'.

    I have a SimpleURLMapping with a property
    Code:
    <prop key="/admin/">paramMultiController</prop>
    The paramMultiController has a PropertiesMethodNameResolver configured like this :
    Code:
    <prop key="/listall">listAllProducts</prop>
    	<prop key="/*">overview</prop>
    But this does not work. When browsing to http://localhost:8080/webapp/admin/anything, it says not found. While I thought a '*' as a property would bring me to the 'overview' method.

    Any ideas ?

    thanks a lot

    Henk

  • #2
    Re: using both jsp and freemarker + confused with mapping

    Originally posted by henk
    Is there a way to solve this problem or should I just choose one of the two views ?
    yes, but you can't the two view resolvers you have.

    UrlBasedViewResolvers and their subclasses will *always* resolve a view from a name because typically they can't determine whether a resource exists before the view tries to load it.

    You need to specify either a ResourceBundleViewResolver or an XmlViewResolver. This can contain all or a subset of your views. If you want them to resolve specific views (say the FreeMarker ones if you have fewer of them) then set the "order" property to 0. Anything not defined in it will cause a fallback to your other resolver (ie the InternalResourceViewResolver).

    This has cropped up before - I think the reference docs are wrong. I'll track down the reference and fix it.

    hth,

    Comment


    • #3
      hmm.. can't find reference to this in the docs. Where exactly did you read it?

      Regards,

      Comment


      • #4
        I'm having the same problem.

        His configuration looks like my original config, probably he got it from the same place I did in the SpringRef:

        http://www.springframework.org/docs/...#view-velocity


        I did find 2 places in the doc that mentioned using the ResourceBundleViewResolver, and neither seemed complete (neither worked for me as documented), so if you're in there please take a look at these sections:

        http://www.springframework.org/docs/...olver-resolver
        http://www.springframework.org/docs/...w-jsp-resolver

        Comment

        Working...
        X