引用属性
属性 | 功能 |
---|---|
action | 它用于引用托管Bean方法, 该方法对组件执行导航处理并返回逻辑结果String。 |
actionListener | 它用于引用处理操作事件的托管bean方法。 |
validator | 它用于引用对组件值执行验证的托管Bean方法。 |
valueChangeListener | 它用于引用处理值更改事件的托管bean方法。 |
引用Bean方法
// index.xhtml
<h:form>
<h:outputLabel for="User name">User Name</h:outputLabel>
<h:inputText id="name-id" value="#{user.name}"/><br/>
<h:outputLabel for="mobile">Enter Mobile</h:outputLabel>
<h:inputText id="mobile-id" value="#{user.mobile}"/><br/>
<h:commandButton action="#{user.submit()}" value="submit"></h:commandButton>
</h:form>
// User.java
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
@ManagedBean
@RequestScoped
public class User {
String name;
String mobile;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getMobile() {
return mobile;
}
public void setMobile(String mobile) {
this.mobile = mobile;
}
// It is used to perform navigation process
public String submit(){
return "response.xhtml";
}
}
// response.xhtml
<h:body>
<h1>
Hello #{user.name}
</h1>
<h:outputLabel value="Your Mobile is: #{user.mobile}"/>
</h:body>
输出:
//索引页
//响应页面
评论前必须登录!
注册