首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用绑定在托管bean中设置primefaces CommandButton对象的CommandButton

使用绑定在托管bean中设置primefaces CommandButton对象的CommandButton
EN

Stack Overflow用户
提问于 2014-11-27 16:55:02
回答 1查看 1.4K关注 0票数 0

我正在使用primefaces绑定,我试图在托管bean中添加actionListener,但我不知道如何做到这一点。

同时当我用

commandButton.setActionListener(MethodBinding b);

这个方法是不推荐的,有人能帮我吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-11-28 01:58:16

不推荐使用setActionListener方法。

因此,您应该使用addActionListener代替。

xhtml

代码语言:javascript
复制
<h:body>
    <h:form>
        <p:commandButton value="execute" binding="#{buttonView.button}"/>
    </h:form> 
</h:body>

管理豆

代码语言:javascript
复制
/**
 *
 * @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

代码语言:javascript
复制
/**
 *
 * @author Wittakarn
 */
public class CommandButtonActionListener implements ActionListener{

    @Override
    public void processAction(ActionEvent event) throws AbortProcessingException {
        System.out.println("execute");
    }
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/27175663

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档