วันจันทร์ที่ 9 มีนาคม พ.ศ. 2552

JSF: How can I set the action and actionListener in Backing Beans ?

[ Set the action ]
public String button_action() {
Hyperlink hyperTmp = new Hyperlink();
// Create method expression
MethodExpression me = (MethodExpression)this.getApplication().getExpressionFactory().createMethodExpression(
getFacesContext().getELContext(), "#{Page1.LinkTest_action}", String.class,new Class[] {});

hyperTmp.setActionExpression(me);
}

public String LinkTest_action() {
// TODO: Process the action
}

[ Set the actionListener ]


public String button_action() {
Hyperlink hyperTmp = new Hyperlink();
// Create method expression
MethodExpression me = (MethodExpression) this.getApplication().getExpressionFactory().createMethodExpression(
getFacesContext().getELContext(), "#{Page1.
LinkTest_actionListener}", null, new Class[]{ActionEvent.class});
hyperTmp.setActionListenerExpression(me);
}

public void LinkTest_actionListener(ActionEvent actionEvent) {
Hyperlink hyperTmp = (Hyperlink) actionEvent.getComponent();
}

อ้างอิง

ไม่มีความคิดเห็น: