I have the following basic (and maybe stupid) understanding problem in JSF:
There is one JSF page "testPage.xhtml" :
<!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:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html">
<f:view>
<h:body>
<h:form>
<h:commandLink id="B1" value="B1" action="#{testBean.ctrl}"/>
<h:commandLink id="B2" value="B2" action="#{testBean.ctrl}"
rendered="#{testBean.renderB2}"/>
</h:form>
</h:body>
</f:view>
</html>
And one backing bean "TestBean.java" :
package test;
import java.io.Serializable;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
@ManagedBean(name="testBean")
@RequestScoped
public class TestBean implements Serializable {
public static final long serialVersionUID = 1L;
private boolean renderB2 = false;
public String ctrl() {
setRenderB2(true);
System.out.println("ctrl() is called.");
return null;
}
public boolean getRenderB2() {
return renderB2;
}
public void setRenderB2(boolean renderB2) {
this.renderB2 = renderB2;
}
}
So both links have TestBean.ctrl()
as action.
First only B1
is rendered. Clicking B1
causes execution of TestBean.ctrl()
and B2
is rendered too.
However, clicking B2
then does not execute TestBean.ctrl()
.
And this is my question: Why is the action method not executed when clicking B2
?
Probably it is because B2
is not rendered again.But why does that prevent the execution of the action method (called by the previously rendered B2
link)?
I suspected that the rendered attribute is the cause for the action call disappearing somewhere in the lifecycle.
But is that really logical?
Is that really wanted by the JSF creators?
In my thinking the button was rendered when it was clicked and so the action should be executed and the new value for the rendered attribute should only be used in the render response phase?
(sorry I had some editing problems) – hubba Aug 10 '11 at 15:30