Announcement Announcement Module
Collapse
No announcement yet.
forward alias. Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • forward alias.

    Hello to All!!
    Please suggest me how I can give an alias to forward path in struts manner. I mean:
    in struts we write
    Code:
    <action path="/process/login" type="com.my.site....">
       <forward name="success" path="/jsp/login.jsp"/>
    </action>
    As you can see the "success" name is alias of "/jsp/login.jsp" path. In spring we use viewResolver:
    Code:
    <bean id="viewResolver"
    class="org.springframework.web.servlet.view.UrlBasedViewResolver">
    <property name="prefix"><value>/WEB-INF/jsp/</value></property>
    <property name="suffix"><value>.jsp</value></property>
    </bean>
    As you know a real name of jsp file we need point in action class. I think it doesn't good idea, that's why I want to do it like in struts. How can I do it?
    I tried to use something like that:
    Code:
    <bean id="viewResolver" class="org.springframework.web.servlet.view.XmlViewResolver">
    		<property name="location"><value>/WEB-INF/views.xml</value></property>
    	</bean>
    but didn't understand what must be in view.xml file. Can anybody show me example?
    Thank you for your responses!

  • #2
    View XML simply contains the bean definitions for the view objects:

    Code:
    <bean id="parent" abstract="true" class="org.springframework.web.servlet.view.JstlView"/>
    
    <bean id="success" parent="paren">
      <property name="url"><value>/WEB-INF/jsp/login.jsp</value></property>
    </bean>
    
    <bean id="failure" parent="parent">
      <property name="url"><value>/WEB-INF/jsp/login.jsp</value></property>
    </bean>
    As you can see this uses the parent feature of the BeanFactory to limit the amount of times you have to type the class name...

    The same thing by the way can be done in the ResourceBundleViewResolver. It works alsmost the same, except for the view beans being defined in properties files instead of Spring XML format. More info can be found in the refernece manual and the ResourceBundleViewResolver's JavaDoc.

    regards,
    Alef

    Comment


    • #3
      Alef Arendsen, thanks for your help!

      Comment


      • #4
        Hello Alef!
        I have tried you solution. This is what I need. But in your example forward alias looks like a global forward name:

        Code:
        <bean id="success" parent="paren"> 
          <property name="url"><value>/WEB-INF/jsp/login.jsp</value></property> 
        </bean>
        Do you know how to define local forwards for an action? I mean, for ex., I 've got "LOGIN" action which has its own "success" and "failure" farwards and I've got "LOGOUT" action with its own "success" and "failure" farwards as well. how to resolve such a case?

        Comment

        Working...
        X