Results 1 to 5 of 5

Thread: How to map views

  1. #1

    Default How to map views

    Hi,

    How do I configure views via the xxx-servlet.xml file?

    For example, say I am making a web-app for inventory control of a store which sells "books", "magazines", and "music CDs". Each of these items has its own set of controllers and its own views (JSPs). I want the JSPs to be in a sub-directory structure under WEB-INF, with the "book" views, and the "magazine" views in separate sub-directories etc.

    But the only example "view resolver" configuration I have seen allows only for the JSPs to all sit in the same directory - and I can't work out how to configure resolving to different locations.

    Eg. I have seen this sort of view resolver configuration for InternalResourceViewResolver. But all the JSPs need to sit in "/WEB-INF/jsp/", and I can't see how to have some views in subdirectories of this.

    <property name="viewClass">
    <value>org.springframework.web.servlet.view.JstlVi ew</value>
    </property>
    <property name="prefix">
    <value>/WEB-INF/jsp/</value>
    </property>
    <property name="suffix">
    <value>.jsp</value>
    </property>


    Thanks for any help,
    Peter

  2. #2
    Join Date
    Aug 2004
    Location
    Amsterdam, Netherlands
    Posts
    450

    Default

    You could use the ResourceBundleViewResolver, which allows you to specify the URL and a view class in a properties file instead of only providing a suffix and a prefix.

    Of course, you could also return "bla/bla.jsp" as the view name.

    Alef

  3. #3

    Default

    Thanks for the reply.

    I guess your second response is along the lines of having a controller return a ModelAndView with a view name like "books/bookEdit" or "books/showBook" etc?

    I would rather have the controller just return for example "bookEdit", and have configuration decide exactly what JSP that maps to. Is that only possible by using a ResourceBundleViewResolver? Are there examples of how to use this view-resolver?

    Thanks,
    Peter

  4. #4
    Join Date
    Aug 2004
    Location
    Melbourne, FL
    Posts
    2,794

    Default

    You can use InternalResourceViewResolver - it'll take bookEdit (the logical view name you return) and resolve that to /${prefix}/bookEdit.${suffix}, for example /WEB-INF/foo/bar/bookEdit.jsp.

    Keith
    Keith Donald
    Core Spring Development Team

  5. #5

    Default

    But using InternalResourceViewResolver and "prefix" and "suffix" format, doesn't that mean the all JSPs will be mapped to the same "prefix"?

    I want different prefixes depending on the JSP/controller.

    I can get it to work by returning a ModelAndView from my "Controller" class with for example
    return new ModelAndView("books/showBook", "data", data);
    or
    return new ModelAndView("magazines/showMagazine", "data", data);

    but if I want to have an "edit form" I use SimpleFormController, and I get problems because I can't find out how to indicate the JSP with a path - I use formBackingObject to generate the data for the form, but this doesn't seem to allow me to indicate a path to the JSP.

Similar Threads

  1. Replies: 22
    Last Post: Feb 4th, 2010, 01:37 AM
  2. Complex views
    By neunistivlija in forum Swing
    Replies: 0
    Last Post: Oct 17th, 2005, 03:27 AM
  3. AbstractWizardController views
    By avp12 in forum Web
    Replies: 0
    Last Post: Mar 30th, 2005, 04:51 PM
  4. Multiple views and pages question
    By jwray in forum Swing
    Replies: 3
    Last Post: Feb 19th, 2005, 09:22 AM
  5. Newbie question on Pages and Views
    By ragnarwestad in forum Swing
    Replies: 8
    Last Post: Dec 13th, 2004, 10:47 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
  •