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

编程入门 行业动态 更新时间:2024-10-11 03:20:49
本文介绍了如何在执行此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属性

本文发布于:2023-11-24 19:39:48,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1626551.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:侦听器   属性   如何在   event   bean

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!