我有以下一段简单的代码h:outputText
指向一个int
and a p:commandLink
设置一个值:
<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 如下所示:
@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。但在我的日志消息中我只看到Index: 0
第一次单击图像时。
这是类似的东西Jsf 用旧值更新模型值 https://stackoverflow.com/questions/3408376,但我有 JSF@ManagedBean
注解。
操作侦听器按照它们在视图中定义的顺序被调用。你想使用action
代替actionListener
。更重要的是,action
首先应该用于调用业务操作。
<p:commandLink action="#{testBean.test}" update="text">
<f:setPropertyActionListener target="#{testBean.index}" value="5" />
<h:graphicImage url="/images.png"/>
</p:commandLink>
也可以看看:
- 动作和动作监听器之间的区别 https://stackoverflow.com/questions/3909267/differences-between-action-and-actionlistener/3909382#3909382
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)