在PhaseListener调用initialize方法中。
public class myBean implements Serializable
{
private boolean myBoolean = "true";
public void initialize()
{
if(someCondition)
{
this.setMyBoolean(true);
}
else
{
this.setMyBoolean(false); // Lets assume myBoolean gets set to false here
}
}
}
此方法执行后,index.jsf呈现给用户。
在index.xhtml页面中,下面的代码在那里..
<h:commandLink action="#{myBean.secondMethod}" value="someLink">
</h:commandLink>
public String secondMethod()
{
log.debug("Value of myBoolean variable is: " +this.isMyBoolean());
return null;
}
当用户点击时someLink,上面的代码将打印myBoolean为true而不是false。
myBean是在request范围内。因为,这是一个新的要求,我不得不相信myBoolean它是新分配的true价值。
我该如何克服呢?我的意思是,当secondMethod被调用时,如果myBoolean是false,那么它也应该false在secondMethod。为什么myBoolean总是这样true?