2010-02-08 100 views
0

我想从支持bean动态添加按钮到JSF页面(也支持Rich Faces)。在JSF中 - 尝试实现与“#{bean.run(3)}”类似的东西

按钮的值需要在运行时确定,并在按下按钮时返回到后台bean。 (因此,标题 - 我实际上试图做一些类似于“#{beans.run(3)}”的操作,即 - 设置固定的参数,以便在单击按钮时使用)

因此,例如,如果用户创建一个按钮(在运行时)并给按钮一个值。这个值应该返回到要分析的支持bean。

我的问题 - 如何在运行时分配一个按钮(该按钮是带有a4j:支持子项的JSF组件)? (我尝试使用A4J:actionParam,但不能设法解决它)

PS - 我已经彻底改革这个问题是短,更重要的是从原来的太长的问题

回答

3

有许多opions的:

  • 使用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)功能(并不适用于所有情况)

+0

谢谢! 如何获得“f:setPropertyActionListener”仅在按下按钮时才计算? – Ben 2010-02-08 13:42:16

+0

看到我更新的答案。 – Bozho 2010-02-08 13:46:45

+0

Tnx再次。我有2个问题与f:setPropertyActionListener: (1)我没有使用h:commandButton,而是在html面板网格下的a4j:支持。 (2)我想添加f:setPropertyActionListener到a4j:支持子类,但是我找不到它在backing bean中创建的对象表示。 – Ben 2010-02-08 14:53:41

相关问题