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

  • using both jsp and freemarker + confused with mapping


    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 :

    <bean id="viewResolver"
    		<property name="viewClass">
    		<property name="prefix">
    		<property name="suffix">
    	<!-- freemarker config -->
    	<bean id="freemarkerConfig"
    		<property name="templateLoaderPath"
    			value="/WEB-INF/freemarker/" />
    	<bean id="freemarkerViewResolver"
    		<property name="cache" value="true" />
    		<property name="prefix" value="" />
    		<property name="suffix" value=".ftl" />
    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
    <prop key="/admin/">paramMultiController</prop>
    The paramMultiController has a PropertiesMethodNameResolver configured like this :
    <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


  • #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.



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



      • #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:

        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: