添加了`<f:actionListener>`之后,java`ViewScoped` bean会被重新创建吗?
我的JSF支持bean是ViewScoped
因为我添加了另一个动作监听器,所以即使视图没有改变,bean也会被重新创建
@ManagedBean (name="EncryptionBean")
@ViewScoped
public class EncryptionBean extends ClientBeanBase implements Serializable, ActionListener
{
.
.
.
@Override
public void processAction(ActionEvent arg0) throws AbortProcessingException
{
refresh();
}
}
HTML
<p:commandButton value="OK" type="submit" actionListener="#{FileSelectBean.actionOk}" oncomplete="dlgFileSelect.hide();" update=":formEncryptionDialog,:formTranscodingPage:streamInfoId" styleClass="buttonOK">
<f:actionListener type="com.company.rews.webclient.beans.EncryptionBean" />
</p:commandButton>
当我按下OK
按钮时,我不会期望bean再次被创建,因为它是ViewScoped
,但是它被重新创建(构造函数被调用),并且我丢失了一些变量。当我删除<f:actionListener>
行时,不会在OK
上重新创建BE
我该怎么办
# 1 楼答案
在这里找到了答案: Session scoped managed bean and actionListener
需要使用
binding
而不是type
: