JSF GAE:值更新托管bean方法中的问题 [英] JSF GAE: Value Update Problem in managed bean method
问题描述
我有一段简单的 h:outputText
指向一个 int
和一个 p:commandLink
来设置一个值:
I have the following piece of code with a simple h:outputText
pointing to a int
and a p:commandLink
to set a value:
<h:form id="f1">
<h:outputText id="text" value="#{testBean.index}"/>
<p:commandLink actionListener="#{testBean.test}" update="text">
<f:setPropertyActionListener target="#{testBean.index}" value="5" />
<h:graphicImage url="/images.png"/>
</p:commandLink>
</h:form>
托管bean如下所示:
The managed bean looks like this:
@javax.faces.bean.ManagedBean @ViewScoped
public class TestBean implements Serializable{
private int index; // getter/setter
@PostConstruct public void init() {
index = 0;log.log(Level.WARNING, "@PostConstruct");}
public void test(ActionEvent ae){
log.log(Level.WARNING, "Index: "+index);}
}
该bean构造正确,在第一次点击图像后, h:ouputText
更新为 5 。但在我的日志消息中,我只看到索引:0
在图片的第一次点击。
The bean is constructed correctly, and after the first click on the image the h:ouputText
is updated to 5. But in my log message I only see Index: 0
during the first click on the image.
这是类似的东西像 Jsf更新旧值的模型值,但我有JSF @ManagedBean
注解。
It's something similar like Jsf updates model value with old value, but I have the JSF @ManagedBean
annotation.
推荐答案
动作侦听器按照它们在视图中定义的顺序被调用。你想使用 action
而不是 actionListener
。更重要的是,动作
应该首先用于调用商业行为。
Action listeners are invoked in the order they're definied in the view. You want to use action
instead of actionListener
. Even more, the action
should in first place have been used to invoke a business action.
<p:commandLink action="#{testBean.test}" update="text">
<f:setPropertyActionListener target="#{testBean.index}" value="5" />
<h:graphicImage url="/images.png"/>
</p:commandLink>
另请参阅:
- 动作与动作侦听器之间的差异
- Differences between action and actionListener
See also:
这篇关于JSF GAE:值更新托管bean方法中的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!