我正在使用primefaces绑定,我试图在托管bean中添加actionListener,但我不知道如何做到这一点。
同时当我用
commandButton.setActionListener(MethodBinding b);
这个方法是不推荐的,有人能帮我吗?
发布于 2014-11-28 01:58:16
不推荐使用setActionListener方法。
因此,您应该使用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");
}
}https://stackoverflow.com/questions/27175663
复制相似问题