Hi,
I am trying to implement a very simple example, where I am invoking one jsp from another using jsf and spring framework. given below are the code snippets -
web.xml contents -
<?xml version="1.0"?>
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
<!--context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/applicationContext.xml</param-value>
</context-param-->
<context-param>
<param-name>javax.faces.STATE_SAVING_METHOD</param-name>
<param-value>server</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!-- Faces Servlet -->
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>-1</load-on-startup>
</servlet>
<!-- Faces Servlet Mapping -->
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.jsf</url-pattern>
</servlet-mapping>
</web-app>
faces-config contents -
<?xml version="1.0"?>
<!DOCTYPE faces-config PUBLIC
"-//Sun Microsystems, Inc.//DTD JavaServer Faces Config 1.1//EN"
"http://java.sun.com/dtd/web-facesconfig_1_1.dtd">
<faces-config>
<application>
<variable-resolver>
org.springframework.web.jsf.DelegatingVariableResolver
</variable-resolver>
</application>
<managed-bean>
<description>
Backing bean that contains transaction information.
</description>
<managed-bean-name>firstBean</managed-bean-name>
<managed-bean-class>com.rnd.web.faces.backinbean.FirstBean</managed-bean-class>
<managed-bean-scope>request</managed-bean-scope>
</managed-bean>
<navigation-rule>
<from-view-id>/pages/one.jsp</from-view-id>
<navigation-case>
<from-outcome>second</from-outcome>
<to-view-id>/pages/two.jsp </to-view-id>
<redirect/>
</navigation-case>
</navigation-rule>
</faces-config>
application-context contents -
<?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:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd"> <bean id="firstBean" class="com.rnd.web.faces.backinbean.FirstBean" scope="request">
</bean>
</beans>
I am calling FirstBean.firstToSecondMethod from one.jsp, setting some values in the method and calling two.jsp -
public String firstToSecMethod(){
System.out.println("inside java method.. ");
firstProp = "prop set in FirstBean java";
secondProp = 10;
return "second";
}
but two.jsp does not display the values
<td><h:outputText value="#{firstBean.firstProp}"/></td>
after changing the bean scope to session values are getting displayed properly.
I am not sure why this is happening.
I think request scope should work fine. Please advise.
Thanks,
Abhijeet