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

  • SWF+InternalResourceViewResolver

    Hi,

    I would like resolve views that are defined in the web flow by using a bean "InternalResourceViewResolver":

    web.xml:
    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
        <context-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>/WEB-INF/applicationContext.xml</param-value>
        </context-param>
        <listener>
            <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
        </listener>
        <servlet>
            <servlet-name>mailview</servlet-name>
            <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
            <load-on-startup>2</load-on-startup>
        </servlet>
        <servlet-mapping>
            <servlet-name>mailview</servlet-name>
            <url-pattern>*.htm</url-pattern>
        </servlet-mapping>
        <session-config>
            <session-timeout>
                30
            </session-timeout>
        </session-config>
        <welcome-file-list>
            <welcome-file>redirect.jsp</welcome-file>
        </welcome-file-list>
    </web-app>
    redirect.jsp:
    Code:
    <%--
    Views should be stored under the WEB-INF folder so that
    they are not accessible except through controller process.
    
    This JSP is here to provide a redirect to the dispatcher
    servlet but should be the only JSP outside of WEB-INF.
    --%>
    <%@page contentType="text/html" pageEncoding="UTF-8"%>
    <% response.sendRedirect("homeView.htm"); %>
    mailview-servlet.xml:
    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xmlns:p="http://www.springframework.org/schema/p"
           xmlns:aop="http://www.springframework.org/schema/aop"
           xmlns:tx="http://www.springframework.org/schema/tx"
           xmlns:webflow="http://www.springframework.org/schema/webflow-config"        
           xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
           http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
           http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
           http://www.springframework.org/schema/webflow-config http://www.springframework.org/schema/webflow-config/spring-webflow-config-2.0.xsd">
        
        <bean id="mailItemsViewSerice" class="be.services2actions.spring.webflow.mailview.MailItemModel" />
        <!--
        Most controllers will use the ControllerClassNameHandlerMapping above, but
        for the index controller we are using ParameterizableViewController, so we must
        define an explicit mapping for it.
        -->
               
        <bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
            <property name="mappings">
                <props>
                    <prop key="homeView.htm">flowController</prop>
                </props>
            </property>
        </bean>
    
        <webflow:flow-registry id="flowRegistry" >
            <webflow:flow-location id="homeView" path="/WEB-INF/flows/mailViewFlow.xml" />
        </webflow:flow-registry>
        
        <bean id="flowController" class="org.springframework.webflow.mvc.servlet.FlowController">
            <property name="flowExecutor" ref="flowExecutor" />
        </bean>
    
        <webflow:flow-executor id="flowExecutor" flow-registry="flowRegistry">
        </webflow:flow-executor>
        
        <bean id="viewResolver"
              class="org.springframework.web.servlet.view.InternalResourceViewResolver"
              p:prefix="/WEB-INF/jsp/"
              p:viewClass="org.springframework.web.servlet.view.JstlView"
               />
    
    </beans>
    mailViewFlow.xml:
    Code:
    <flow xmlns="http://www.springframework.org/schema/webflow"
    	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    	xsi:schemaLocation="http://www.springframework.org/schema/webflow
            http://www.springframework.org/schema/webflow/spring-webflow-2.0.xsd">
    
        <var name="mailItemModel" class="be.services2actions.spring.webflow.mailview.MailItemModel"/>
    
        <view-state id="homeView" model="mailItemModel" view="homeView.jspx">
            <transition on="viewMailItems" to="viewMailItemsAction" />
        </view-state>
    
        <action-state id="viewMailItemsAction">        
            <evaluate expression="mailItemsViewService.isUserValid(mailItemModel.username)" result="flowScope.isValidUser" />
            <transition to="checkValidUser" />
        </action-state>
        
        <decision-state id="checkValidUser">
            <if test="flowScope.isValidUser" then="getMailItems" else="invalidUserView"/>
        </decision-state>
    
        <action-state id="getMailItems">
            <evaluate expression="mailItemsViewService.retriveMailItems(mailItemModel.username)" result="flowScope.mailItems" />
            <transition to="validUserView" />
        </action-state>
    
        <end-state id="validUserView" view="/jsp/mailItemsView.jspx"/>
        
        <end-state id="invalidUserView" view="/jsp/invalidUserView.jspx" />
        
    </flow>

    So what I would like to do is when I define the view "homeView.jspx":
    <view-state id="homeView" model="mailItemModel" view="homeView.jspx">

    With the view resovler, it finds the view in:
    /WEB-INF/jsp/homeView.jspx

    Any ideas?
Working...
X