我願意稱這樣的方法:如何使用<h:commandButton action =「#{method here}」/>?
<h:commandButton value="Register" action="#{account.action}"/>
有了這樣的後續類:
package com.sources;
public class Account {
private String password1;
private String password2;
public String getPassword1() {
return password1;
}
public void setPassword1(final String password1) {
this.password1 = password1;
}
public String getPassword2() {
return password2;
}
public void setPassword2(final String password2) {
this.password2 = password2;
}
public void action() {
//if the passwords matchs
//change page
//else
//display an error on the xhtml page
}
}
在該方法中,我想改變頁面或顯示錯誤,這取決於關於註冊的有效性。
改變頁面將是一樣的跟隨動作,但堪稱方法#{account.action}
:
<h:commandButton value="Register" action="connect"/>