]
Sebastien Degardin commented on JBSEAM-2615:
--------------------------------------------
After further investigations, this has nothing to deal with Ajax Toolkit.
here is what happens :
During the INVOKE_APPLICATION phase, the NavigationHandler (either Seam's one or JSF
RI's one) calls ExternalContext.redirect which
calls "FacesContext.getCurrentInstance().responseComplete();" to no execute
the RenderResponse and then, later the
Lifecycle is called again executing like when a page is requested for the first time
(RESORE_VIEW then RENDER_RESPONSE).
Since faceContext.getResponseComplete returns true, others problems could also happen.
If we keep track (in the event context for example) that some phases have already been
executed, then we can avoid re-executing the SeamPhaseListener when not needed. (like
before and after RESTORE_VIEW in the case of this pageContext problem).
POJO does not get outjected in the page context as expected
-----------------------------------------------------------
Key: JBSEAM-2615
URL:
http://jira.jboss.com/jira/browse/JBSEAM-2615
Project: JBoss Seam
Issue Type: Bug
Affects Versions: 2.0.1.GA
Environment: Seam 2.0.1, RichFaces 3.1.4, JBoss AS 4.2, Sun JSF 1.2 RI, Facelets
Reporter: fredatwork
I described what I believe is a bug regarding the seam page context. See
http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4128529 .
In brief, a POJO with page context got not outjected as expected.
Please consider the following sample (code id pasted below) and use it as described in
the forum topic referenced above.
View sample2.seam first in your favorite browser. Once the start button is pressed,
sample2next.xhtml renders a counter at 0 . However, the Sample2Action.init action
initiated this counter to 1 . Everything happens as the completion of Sample2Action.init
does not outject the POJO Sample2Context to the PAGE context, and the action
Sample2Action.refresh retrieves a newly created object.
Same thing happens with the following modifications to the Sample2Action component (POJO
object is not auto-created, init method does it explicitely):
// Page context object
@In(value="Sample2Context", scope=ScopeType.PAGE, required=false)
@Out(value="Sample2Context", scope=ScopeType.PAGE, required=true)
private Sample2Context context;
/**
* @see sample2.Sample2Local#init()
*/
public void init() {
context = new Sample2Context ();
context.increment();
facesMessages.add(FacesMessage.SEVERITY_INFO, "Initiated page context " +
context);
System.out.println("Initiated page context " + context);
}
PS: I keep a safe-copy of Eclipse projects with the sources below, in case someone needs
them (cannot attach zip files to this bug report)
Fred ( fredatwork(a)free.fr )
*****************************************************************************************************************************
Sample2Local.java
*****************************************************************************************************************************
package sample2;
import javax.ejb.Local;
/**
* Sample 2 interface
* @author fredatwork
*
*/
@Local
public interface Sample2Local {
public void init();
public void refresh();
public void remove();
}
*****************************************************************************************************************************
Sample2Bean.java
*****************************************************************************************************************************
package sample2;
import javax.ejb.Remove;
import javax.ejb.Stateless;
import javax.faces.application.FacesMessage;
import org.jboss.seam.ScopeType;
import org.jboss.seam.annotations.Begin;
import org.jboss.seam.annotations.End;
import org.jboss.seam.annotations.In;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.Out;
import org.jboss.seam.contexts.Contexts;
import org.jboss.seam.faces.FacesMessages;
/**
* Sample 2
* @author fredatwork
*
*/
@Stateless(name="Sample2Action")
@Name("Sample2Action")
public class Sample2Bean implements Sample2Local {
// Page context object
@In(value="Sample2Context", create=true, required=false)
@Out(value="Sample2Context", scope=ScopeType.PAGE, required=true)
private Sample2Context context;
// Messages
@In
private FacesMessages facesMessages;
/**
* @see sample2.Sample2Local#init()
*/
public void init() {
context.increment();
facesMessages.add(FacesMessage.SEVERITY_INFO, "Initiated page context " +
context);
System.out.println("Initiated page context " + context);
}
/**
* @see sample2.Sample2Local#refresh()
*/
public void refresh() {
Object object = Contexts.lookupInStatefulContexts("Sample2Context");
System.out.println("Context object : " + object);
Object pageObject = Contexts.getPageContext().get("Sample2Context");
System.out.println("Page context object : " + pageObject);
System.out.println("In refresh with : " + context);
context.increment();
System.out.println("Incremented page context " + context);
facesMessages.add(FacesMessage.SEVERITY_INFO, "Incremented page context " +
context);
}
/**
* @see sample2.Sample2Local#remove()
*/
@Remove
public void remove() {
}
}
*****************************************************************************************************************************
Sample2Context.java
*****************************************************************************************************************************
package sample2;
import java.io.Serializable;
import org.jboss.seam.annotations.Name;
/**
* @author fredatwork
*
*/
public class Sample2Context implements Serializable {
private int counter;
/**
* @return the counter
*/
public int getCounter() {
return counter;
}
/**
* @param counter the counter to set
*/
public void setCounter(int counter) {
this.counter = counter;
}
/**
* Increment counter by 1
*/
public void increment() {
counter++;
}
/**
* @see java.lang.Object#toString()
*/
@Override
public String toString() {
return "[Context = " + counter + "]";
}
}
*****************************************************************************************************************************
sample2.xhtml
*****************************************************************************************************************************
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html
xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:s="http://jboss.com/products/seam/taglib">
<head>
<meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1" lang="fr"/>
<title>Sample2</title>
</head>
<body>
<h:form>
<h:messages/>
<h:commandButton action="#{Sample2Action.init}"
value="Start"></h:commandButton>
</h:form>
</body>
</html>
*****************************************************************************************************************************
sample2next.xhtml
*****************************************************************************************************************************
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html
xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:s="http://jboss.com/products/seam/taglib">
<head>
<meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1" lang="fr"/>
<title>Sample2Next</title>
</head>
<body>
<h:form>
<h:messages/>
<h:outputLabel value="Counter :"/>
<h:outputText value="#{Sample2Context.counter}"/>
<h:commandButton value="Refresh"
action="#{Sample2Action.refresh}"/>
</h:form>
</body>
</html>
*****************************************************************************************************************************
components.xml
*****************************************************************************************************************************
<?xml version="1.0" encoding="UTF-8"?>
<components
xmlns="http://jboss.com/products/seam/components"
xmlns:core="http://jboss.com/products/seam/core"
xmlns:security="http://jboss.com/products/seam/security"
xmlns:transaction="http://jboss.com/products/seam/transaction"
xmlns:mail="http://jboss.com/products/seam/mail"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation=
"http://jboss.com/products/seam/core
http://jboss.com/products/seam/core-2.0.xsd
http://jboss.com/products/seam/transaction
http://jboss.com/products/seam/transaction-2.0.xsd
http://jboss.com/products/seam/security
http://jboss.com/products/seam/security-2.0.xsd
http://jboss.com/products/seam/components
http://jboss.com/products/seam/components-2.0.xsd">
<core:init jndi-pattern="sample/#{ejbName}/local"
debug="true"/>
<core:manager conversation-timeout="120000"
concurrent-request-timeout="500"
conversation-id-parameter="cid"/>
<transaction:ejb-transaction/>
</components>
*****************************************************************************************************************************
faces-config.xml
*****************************************************************************************************************************
<?xml version="1.0" encoding="UTF-8"?>
<faces-config
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-facesconfig_1_2.xsd"
version="1.2">
<!-- Application setting -->
<application>
<locale-config>
<default-locale>fr</default-locale>
<supported-locale>en</supported-locale>
</locale-config>
</application>
</faces-config>
*****************************************************************************************************************************
pages.xml
*****************************************************************************************************************************
<?xml version="1.0" encoding="UTF-8"?>
<pages
xmlns="http://jboss.com/products/seam/pages"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://jboss.com/products/seam/pages
http://jboss.com/products/seam/pages-2.0.xsd"
>
<!--
*************************************************************************************
-->
<!-- Wilcard
-->
<!--
*************************************************************************************
-->
<page view-id="*" >
<navigation from-action="#{Sample2Action.init}">
<redirect view-id="/sample2next.xhtml"/>
</navigation>
<navigation from-action="#{Sample3Action.init}">
<redirect view-id="/sample3next.xhtml"/>
</navigation>
<navigation from-action="#{Sample4Action.init}">
<redirect view-id="/sample4next.xhtml"/>
</navigation>
</page>
<exception class="org.jboss.seam.NoConversationException">
<redirect view-id="/no_conversation.xhtml"/>
</exception>
</pages>
*****************************************************************************************************************************
web.xml
*****************************************************************************************************************************
<?xml version="1.0" encoding="UTF-8"?>
<web-app
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID"
version="2.5">
<display-name>sample</display-name>
<context-param>
<param-name>org.ajax4jsf.VIEW_HANDLERS</param-name>
<param-value>com.sun.facelets.FaceletViewHandler</param-value>
</context-param>
<context-param>
<param-name>javax.faces.STATE_SAVING_METHOD</param-name>
<param-value>client</param-value>
</context-param>
<context-param>
<param-name>javax.faces.DEFAULT_SUFFIX</param-name>
<param-value>.xhtml</param-value>
</context-param>
<context-param>
<param-name>facelets.REFRESH_PERIOD</param-name>
<param-value>2</param-value>
</context-param>
<context-param>
<param-name>facelets.DEVELOPMENT</param-name>
<param-value>true</param-value>
</context-param>
<context-param>
<param-name>com.sun.faces.validateXml</param-name>
<param-value>false</param-value>
</context-param>
<context-param>
<param-name>com.sun.faces.verifyObjects</param-name>
<param-value>false</param-value>
</context-param>
<context-param>
<param-name>org.richfaces.SKIN</param-name>
<param-value>DEFAULT</param-value>
</context-param>
<!-- Seam -->
<listener>
<listener-class>org.jboss.seam.servlet.SeamListener</listener-class>
</listener>
<servlet>
<servlet-name>Seam Resource Servlet</servlet-name>
<servlet-class>org.jboss.seam.servlet.SeamResourceServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Seam Resource Servlet</servlet-name>
<url-pattern>/seam/resource/*</url-pattern>
</servlet-mapping>
<filter>
<filter-name>Seam Filter</filter-name>
<filter-class>org.jboss.seam.servlet.SeamFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>Seam Filter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<!-- JSF -->
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.seam</url-pattern>
</servlet-mapping>
<!-- Session configuration -->
<session-config>
<session-timeout>1</session-timeout>
</session-config>
</web-app>
*****************************************************************************************************************************
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: