如何在执行此f:event侦听器之前设置bean属性 [英] How to set a bean property before executing this f:event listener

查看:129
本文介绍了如何在执行此f:event侦听器之前设置bean属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在执行此f:event侦听器之前从jsf页面设置bean属性:

How to set a bean property from jsf page before executing this f:event listener:

    <f:event type="preRenderComponent" listener="bean.method}"/>

我尝试了以下代码,但没有将值设置为bean属性。

I tried the below code but it does not set the value to the bean property.

    <f:event type="preRenderComponent" listener="bean.method}">
        <f:setPropertyActionListener target="#{bean.howMany}" value="2"/>
    </f:event>






JSF2.1.6 with PF 3.3


JSF2.1.6 with PF 3.3

以下代码有任何问题吗? (这有效!但我只想确认这是否有任何问题!?)

Any issues with this below code? (This works! but I just want to confirm if there are any issues with this!?)


<f:event type="preRenderComponent" listener="#{bean.setHowMany(15)}"/> 
<f:event type="preRenderComponent" listener="#{bean.method}"/>



推荐答案

尝试

<f:event type="preRenderComponent" listener="#{bean.method('2')}"/>

如果不行,请尝试

<f:event type="preRenderComponent" listener="#{bean.method}">
    <f:attribute name="howMany" value="2" />
</f:event>

并在您管理的bean中添加以下内容

and in you managed bean add the following

public void method(ComponentSystemEvent event) {
    String howMany = (String) event.getComponent().getAttributes().get("howMany");
}

我认为你最好避免两个后续< f :event> 调用,当你真的不需要它们时,虽然我认为我看到某个地方声明的顺序将是执行的顺序,它仍然可能因不同的JSF实现而有所不同可以100%确定你可以指望它...

I think you better avoid two subsequent <f:event> calls , when you don't really need them, Although I think i saw somewhere that the order of declaration will be the order of execution, It still may vary between different JSF implementation and you never can be 100% sure that you can count on it...

所以在这种情况下只使用一个的INMO更好

so INMO using only one is better in this case

<f:event type="preRenderComponent" listener="#{bean.method(15)}"/>

这篇关于如何在执行此f:event侦听器之前设置bean属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆