What is the correct way to use RequestScoped Bean and rendered attribute?
有人知道如何将RequestScoped bean和jsf中的rendered属性一起使用吗?呈现的属性在applyValues阶段之前进行评估,因此无法正确评估。我不想保留任何状态。该示例可以是带有数据表和按钮的outputPanel。数据表获取值列表。package的outputPanel具有呈现的属性,例如:
1 2 3 4 5 6 7 | <p:outputPanel rendered="#{not empty requestScopedBean.dataList}"> <p:datatable value="#{requestScopedBean.dataList}"> ... </p:datatable> <p:commandButton action="#{requestScopedBean.someAction}" /> </p:outputPanel> |
在加载页面并单击按钮之后,什么也没发生,因为恢复了视图并评估了表达式-该bean的数据列表确实为空,因此不应呈现该面板。这导致甚至没有调用该动作方法-因为该按钮不存在。
如果您当时不希望具有已填充的数据表,则只需在感兴趣的命令按钮已被调用的情况下,在
1 2 3 4 5 | <p:outputPanel rendered="#{not empty requestScopedBean.dataList or not empty param[someButton.clientId]}"> ... <p:commandButton binding="#{someButton}" ... /> </p:outputPanel> |
也可以看看:
- 如何让验证取决于按下的按钮?