用你关联的按钮
action
,这是backing bean中的一种方法
您可以在backing bean中设置参数,并在按下按钮时从链接到的方法中读取它们。
行动
. action方法应返回
String
,导航处理程序将根据中的配置读取,以检查是否必须移动到新页。
faces-config.xml
.
<h:form>
<h:commandButton value="Press here" action="#{myBean.action}">
<f:setPropertyActionListener target="#{myBean.propertyName1}" value="propertyValue1" />
<f:setPropertyActionListener target="#{myBean.propertyName2}" value="propertyValue2" />
</h:commandButton>
</h:form>
背豆:
package mypackage;
public class MyBean {
// Init --------------------------------------------------------------------------------------
private String propertyName1;
private String propertyName2;
// Actions -----------------------------------------------------------------------------------
public void action() {
System.out.println("propertyName1: " + propertyName1);
System.out.println("propertyName2: " + propertyName2);
}
// Setters -----------------------------------------------------------------------------------
public void setPropertyName1(String propertyName1) {
this.propertyName1 = propertyName1;
}
public void setPropertyName2(String propertyName2) {
this.propertyName2 = propertyName2;
}
}
这个例子取自
here
(俾路支博客,可能他会来告诉你检查链接,但我更快!P)
当然,要做到这一点,必须将bean设置为
session scoped
. 如果你想的话
request scoped
你可以按照步骤
here