我想将按钮从支持 bean 动态添加到 JSF 页面(也支持 Rich Faces)。
按钮的值需要在运行时确定,并在按下按钮时返回到支持 bean。 (因此标题 - 我实际上试图能够做类似“#{beans.run(3)}”的事情,即 - 设置单击按钮时要使用的固定参数)
例如,如果用户创建一个按钮(在运行时)并为该按钮指定一个值。该值应返回到要分析的支持 bean。
我的问题 - 如何在运行时为按钮(该按钮是带有 a4j:support 子级的 JSF 组件)分配一个值? (我尝试使用 a4j:actionParam,但无法解决)
P.S - 我已经彻底修改了这个问题,使其比原来太长的问题更短、更切题
最佳答案
有多种选择:
- 使用 JSF 2.0
- 使用 JBoss EL 扩展
使用
<f:setPropertyActionListener value="3" target="#{bean.propety>
,其中propety
稍后由run()
读取方法。<h:commandButton action="#{bean.run}"> <f:setPropertyActionListener target="#{bean.property}" value="#{pageVariable}" /> </h:commandButton> <!-- pageVariable contains the number you are passing --> public class Bean { private int property; // with setters and getters public void run() { // do something with property } }
使用 Facelets 函数( here's an example 对于此类函数)(并非在所有情况下都适用)
关于java - 在 JSF - 尝试实现类似于 "#{bean.run(3)}"的东西,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2221605/