【问题标题】:Set actionListener of primefaces CommandButton object in managed bean using binding使用绑定在托管 bean 中设置 primefaces CommandButton 对象的 actionListener
【发布时间】:2014-11-27 16:55:02
【问题描述】:

我正在使用 primefaces 绑定,我正在尝试将 actionListener 添加到托管 bean,但我不知道该怎么做。

当我使用时

commandButton.setActionListener(MethodBinding b);

此方法已弃用,有人可以帮助我吗?

【问题讨论】:

    标签: jsf primefaces binding managed-bean commandbutton


    【解决方案1】:

    setActionListener 方法已弃用。这已被addActionListener(javax.faces.event.ActionListener). 取代

    因此,您应该改用addActionListener

    xhtml

    <h:body>
        <h:form>
            <p:commandButton value="execute" binding="#{buttonView.button}"/>
        </h:form> 
    </h:body>
    

    托管豆

    /**
     *
     * @author Wittakarn
     */
    @SessionScoped
    @ManagedBean(name = "buttonView")
    public class ButtonView implements Serializable{
    
        private CommandButton button;
    
        public CommandButton getButton() {
            return button;
        }
    
        public void setButton(CommandButton button) {
            this.button = button;
        }
    
        @PostConstruct
        public void init(){
            button = new CommandButton();
            button.addActionListener(new CommandButtonActionListener());
        }
    }
    

    CommandButtonActionListener.java

    /**
     *
     * @author Wittakarn
     */
    public class CommandButtonActionListener implements ActionListener{
    
        @Override
        public void processAction(ActionEvent event) throws AbortProcessingException {
            System.out.println("execute");
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-08-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-06-20
      • 1970-01-01
      相关资源
      最近更新 更多