Applying Java Server Faces (JSF) Technology to Jsp

Normally, a jsp contains static and dynamic contents. Static contents are written using html while dynamic contents are executed at server side, and the resultant data is presented again in html format. When a page is presented in a browser, it contains sequence of html tags that are nested to present view elements and data. When we are working with JSF, the presented page is still the same, but the way jsp code is written, and the way it is processed by the container, there is major difference. Let us see what we have in Jsf.

Logical Description of Jsp Compoents:

In next section, let us actually see implementation details of above components.

Implementation Details of Jsp Components:

In this section, we are not going in details of each component. Detail documentation is available in Jsf tag library reference. Here we extract a quick reference for all important components, which mostly we need when we write a Jsp with Jsf framework.

<%@ taglib uri=”http://java.sun.com/jsf/html” prefix=”h” %>

<%@ taglib uri=”http://java.sun.com/jsf/core” prefix=”f” %>

<f:view>

………..

………..

</f:view>

<h:form>

………..

………..

</h:form> 

<h:inputText id=“firstName”></h:inputText>

<h:outputText value=“First Name”></h:outputText>

<h:inputText id=“firstName” value=”#{helloWorldBean.firstName}” required=“true”>

</h:inputText>

<h:commandButton action=”#{helloWorldBean.sayHelloWorld}”

                        value=“Get Complete Name”></h:commandButton>

<h:inputText id=“firstName” value=”#{helloWorldBean.firstName}” required=“true”></h:inputText>

<h:inputText id=“id” value=”#{helloWorldBean.id}” required=“true” converter=”javax.faces.convert.IntegerConverter>

                  </h:inputText>

 

      <h:message id=“errors” for=“firstName” style=“color:red”/>

 

<f:loadBundle var=”bundle_en”

basename=”messages.CustomerMessages” />

<h:outputText value=”#{bundle_in.firstName}”/>

 

Backing Beans:

Similar to Struts and Spring MVC framework, these backing beans are actually Plain Old Java Objects (POJOs). Attributes of these Java classes are liked with components to transfer data between client and server. Other operations can be linked to submit actions on pages. FacesServlet does the job of population of these objects, from the component values and vice versa. It also executes the backing bean method mapped to an action.

Summary:

Jsf does use the Jsp technology to build a view, but now everything is a reusable component with different execution lifecycle.

 

  • Share/Bookmark
JEE, JSF, Tech Notes

If you enjoyed this post, please consider to leave a comment or subscribe to the feed and get future articles delivered to your feed reader.

Leave Comment

(required)

(required)