Lets us take an example of a java back bean ServerInfo for a JSF page
// File Name : ServerInfo.java
package thomson.com;
public class ServerInfo {
String server;
String environment;
public String getServer() {
return server;
}
public void setServer(String server) {
this.server = server;
}
}
Bean is defined on faces-config.xml as following
<navigation-rule>
<from-view-id>/index.jsp</from-view-id>
<navigation-case>
<to-view-id>/process.jsp</to-view-id>
</navigation-case>
</navigation-rule>
<managed-bean>
<managed-bean-name>ServerInfoBean</managed-bean-name>
<managed-bean-class>thomson.com.ServerInfo</managed-bean-class>
<managed-bean-scope>session</managed-bean-scope>
</managed-bean>
Now lets take an example of JSF page section that sets up the java bean ServerInfoBean from the input text of the form as shown below
//File name: index.jsp
<f:view>
<h:form id="serverForm">
<h:outputLabel for="serverName">
<h:outputText value="Enter the Server Name"/>
</h:outputLabel>
<h:inputText id="serverName" value="#{ServerInfoBean.server}" required="true"/>
<h:message for="serverName"/>
<br>
<h:outputLabel for="environment">
<h:outputText value="Select Environment"/>
</h:outputLabel>
</h:form>
</f:view>
Now in process.jsp the back bean can be accessed as shown below
File name : process.jsp
..
<%
ServerInfo mbean = (ServerInfo) request.getSession().getAttribute("ServerInfoBean");
String server = mbean.getServer();
Out.print(“server name read from the jsf back bean =” +server)
%>