JSF Referencing Managed Bean Method

# Referencing Attributes

Attribute Function
action It is used to refer a managed bean method that performs navigation processing for the component and returns a logical outcome String.
actionListener It is used to refer a managed bean method that handles action events.
validator It is used to refer a managed bean method that performs validation on the component's value.
valueChangeListener It is used to refer a managed bean method that handles value-change events.

# Referring Bean Method

// 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>

Output:

// index Page

JSF Referencing managed bean method 1

// Response Page

JSF Referencing managed bean method 2