在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
?