【发布时间】:2014-07-10 10:28:34
【问题描述】:
我有一个 ViewScoped 托管 Bean。在我的 .xhtml 页面中,我想设置 bean 的属性值并在同一个 bean 的方法中使用它。 我设法从 jsf 页面设置了值,但是当我想在某些方法中使用它时,属性的值不是我之前设置的值。
说明 (xhtml): 在这种形式中,有一个设置属性值的命令链接。它工作正常。此外,当单击命令链接时,将显示第二种形式。
<h:form>
<h:commandLink value="Set" >
<f:setPropertyActionListener target="#{bean.attribute}" value="true" />
<f:ajax execute="@this" />
</h:commandLink>
</h:form>
此表单执行的方法使用了之前设置的属性值,但该值不为真,为假。
<h:form>
<h:commandButton id="submit" value="Execute" action="#{bean.execute}" />
</h:form>
豆子:
public void execute(){
if(isAttribute())
---do something---
}
问题是:为什么execute()不能正确读取属性值?
当我使用一种形式时,它工作正常。但我需要它们以分开的形式出现。
【问题讨论】:
-
如何在同一个请求中同时执行
#{bean.execute}和#{bean.attribute}? -
我执行这段代码没有问题。 commandLink 将值设置为
true,单击按钮时该值保持不变。我用的是 Mojarra JSF 2.2.7,你用的是哪个版本?