Friday, May 9, 2008

How to read a Java Session Back bean of a JSF page from JSP pages


In this section I am describing about accessing a JSF back bean from a JSP page.
Lets us take an example of a java back bean ServerInfo for a JSF page

// File Name :
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


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
<h:form id="serverForm">
<h:outputLabel for="serverName">
<h:outputText value="Enter the Server Name"/>
<h:inputText id="serverName" value="#{ServerInfoBean.server}" required="true"/>
<h:message for="serverName"/>
<h:outputLabel for="environment">
<h:outputText value="Select Environment"/>

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)



Post a Comment

I love to entertain onymous user Comment !


 © 2006-2010