我目前遇到了JSF执行顺序的问题.
看看我的示例代码:
<p:commandButton action="update.xhtml" ajax="false"
icon="ui-icon-pencil"
actionListener="#{marketingCodeBean.initForUpdate}">
<f:setPropertyActionListener
target="#{marketingCodeBean.marketingCode}" value="#{code}"></f:setPropertyActionListener>
</p:commandButton>
Run Code Online (Sandbox Code Playgroud)
我想使用setPropertyActionListener设置bean属性,并对actionListener = initForUpdate进行一些处理.但是JSF默认执行顺序是相反的,actionListener首先在setPropertyActionListener之前.这个问题有干净的解决方法吗?
我正在考虑使用actionListener并将bean参数传递给它,但我不确定这是否是最好的方法.
Bal*_*usC 31
这确实是预期的行为.动作侦听器(actionListener
,<f:actionListener>
和<f:setPropertyActionListener>
)都按照它们在组件上注册的顺序调用,actionListener
首先是属性.除了将后面的方法添加actionListener
为<f:actionListener>
(应该引用具体的ActionListener
接口实现类)之外,不可能以这种方式更改排序.
<p:commandButton ...>
<f:setPropertyActionListener target="#{marketingCodeBean.marketingCode}" value="#{code}" />
<f:actionListener type="com.example.InitForUpdate" />
</p:commandButton>
Run Code Online (Sandbox Code Playgroud)
更好的是只使用action
而不是actionListener
.它在所有动作侦听器之后调用.行动听众有意"准备"一个行动,并将其用于商业行为实际上是不好的做法.
<p:commandButton ... action="#{marketingCodeBean.initForUpdate}">
<f:setPropertyActionListener target="#{marketingCodeBean.marketingCode}" value="#{code}" />
</p:commandButton>
Run Code Online (Sandbox Code Playgroud)
同
public String initForUpdate() {
// ...
return "update.xhtml";
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
17440 次 |
最近记录: |