如何在执行此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属性
发布评论