Nearby lessons
32 of 35Spring - JSF Integration
- Understand Spring - JSF Integration
- See working code examples
- Learn from common mistakes and Q&A
Learn Spring - JSF Integration step by step — simple explanations, complete programs with their output, common beginner mistakes, and exam-style MCQs.
JSF Integration
spring-beans.jar spring-context-support.jar spring-context.jar spring-core.jar spring-jdbc.jar spring-jms.jar spring-orm.jar spring-test.jar spring-tx.jar spring-web.jar spring-webmvc-portlet.jar spring-webmvc-struts.jar spring-webmvc.jar standard-1.0.6.jar struts-core-1.3.10.jar struts-el-1.3.10.jar struts-extras-1.3.10.jar struts-faces-1.3.10.jar struts-mailreader-dao-1.3.10.jar struts-scripting-1.3.10.jar struts-taglib-1.3.10.jar struts-tiles-1.3.10.jar
JSF Introduction
JSF stands for Java Server Faces, it is MVC based web framework, it can be used to prepare web applications in standard mode.
JSF is MVC based web Framework, it has very good focus on Presentation layer in enterprise bapplication development.
JSF is initialially provided by JCP[Java Community Process], later on it was given to SUN Microsystems.
JSF is provided by SUN Microsystems in the form of the following versions.
- JSF1.X
- JSF2.X
- JSf3.X
JSF Features
JSF is view layered Framework, it has very good focus on view layer in MVC based applications.
JSF is component based framework or Technology, it has very good compnent tag library to prepare web applications. JSF is having very good GUI tag library to prepare web applications with very good look
and feel, JSF is providing very good environment to prepare our own custom tags inorder to prepare our own components. JSF is having both client side user interface and Server side user interface, it able to manage User interface at server side by preparing Component Tree at Server side. JSF is having Statefull GUI component, they are able to manage their state at Server side. JSF is having very good Validations Support, it able to allow to define our own Custom Validators. JSF is having very good Convertors support, it able to allow to define own convertors. JSF is having very good Internationalization support inorder prepare web applications w.r.t the Local users JSF is having very good Renderring mechanisms to generate response in different formats as per the requirements, it allows us to prepare our own renderring mechanisms. JSF is having very good Event-Notification model to implement Event Handling, it allows our own custom Events in web applications. JSF is providing very good environment to use Third part vendors provided GUI Components libraries like primefaces, richfaces, ICEFaces,....
JSF Components
To prepare web applications by using JSF then we have to use the following JSF Components.
- View / Presentation Part
- Controller or FacesServlet
- Managed Bean
- Faces Configuration File
- Deployment Descriptor or web.xml
View / Presentation Part
The main intention of View part in web applications is,
- To improve Look And Feel to the web applications.
- To Get Starting point to the web applications inorder to access.
- To get data from users inorder to submit to the Server side application.
- To perform client side data validations by using Java script functions.
- To submit different request types like GET, POST, HEAD,... from client.
In web application , to prepare view part, we will use the technologies like HTML, JSP, Velocity, Freemarker,......
There are two types of View part we are able to use in web applications.
- Information View
- Form based View
Where informational view is able to display information to the user, it will include any form.
EX: status.html, success.html, failure.html,....
Where form based view part is able to include user forms to get data from users and to submit data to server side applications.
In JSF based web applications, to prepare View part we have to use JSF provided tag library.
To prepare View part , JSF has provided the following two types of tags.
- Core Tags
- Html Tags
Where core tag library includes the tags which are used for View representations, Conversions, Validatins,....
EX:
<f:convertNUmber/>
<f:convertDateTime/> <f:validateLength/> <f:validateLongRange/>
Where Html tag library include the tags which are repersenting Html Components
EX:
<h:outputText/>
<h:inputText/> <h:inputSecrete/> <h:inputTextArea/>
In JSP based web applications, to prepare Usaer form we have to use the following steps.
- Declare view part by using <f:view> tag.
- Include Html header part and body part in <f:view> tag.
- Prepare user form by using <h:form> tag.
- Prepare Panelgrid by using <h:panelGrid> tag inorder to prepare layout for GUI component.
- Prepare html components by using the following html tags.
<h:outputText> ---> Label <h:inputText> ----> Text Field. <h:inputSecret> --> Password field. <h:commandButton/>--> Button.
Controller or FacesServlet
In General, in web applications, the main intention of controller is,
- Getting request from Client.
- Identifying Mdel component.
- Instatiating Model component and executing Business logic.
- Identifying View part.
- Forwarding request to View part.
In JSF Based web applications, FacesServlet is acting as controller, it was provided by JSF in the form of a predefined class like "javax.faces.webapp.FacesServlet".
In JSF based web applications, FacesServlet will get Request from client and it will process the request by performing the following request processing lifecycle actions.
- Restore View
- Apply Request values.
- Process Validations.
- Update Model Values.
- Invoke Application.
- Render Response.
Managed Bean
In MVC based applications, the main intention of Bean classes is,
- To manage User form Data.
- To implement Data validations.
- To implement Application Business Logic,....
In JSF Based web applications, Java Bean class is called as Managed Bean class, it is acting as model component.
IN JSF Based web application, To prepare Managed Beans, we have to use the following rules and regulations.
- Managed Bean class must be a POJO class, it must not be extended and implementd any predefined library.
- It will take all properties as per User forms.
- It will include a seperate set of SetXXX() and getXXX() methods for each and every
property.
- It will include buisness methods which are bounded with action attribute in
CommandButton in User forms.
- If we want to provide constructor in Managed Bean class then provid constructor, it must
be public and 0- arg.
- If we want to provide our own comparisions between managed Bean objets then we must
override equals() method
- If we want to generate Hashcode values to Managed Bean objects then we have to
override hashCode() method.
Faces Configuration File
The main intention of Faces Configuration File in JSf is to provide the following configuration details
- Managed Beans configuration.
- Navigations
- Validators
- Convertors.
In Simple JSF applications, we will provide managed beans configuration and navigations in Faces Configuration File. To prepare Faces Configuration file we have to use the following XML tags.
- <faces-config>
- <managed-bean>
- <managed-bean-name> --- </managed-bean-name>
- <managed-bean-class> --- </managed-bean-class>
- <managed-bean-scope> --- </managed-bean-scope>
- </managed-bean>
- <navigation-rule>
- <from-view-id>----</from-view-id>
- <navigation-case>
- <from-outcome>----</from-outcome>
- <to-view-id>----</to-view-id>
- </navigation-case>
- <navigation-case>
- <from-outcome>----</from-outcome>
- <to-view-id>-----</to-view-id>
- </navigation-case>
- </navigation-rule>
- </faces-config>
Where <faces-config> is root tag, it will include JSF configuration details. Where <managed-bean> tag is able to single Managed Bean class configuration. Where <managed-bean-name> is able to take bean logical name of the managed bean
class. Where <managed-bean-class> will take fully qualified name of the Managed bean class. Where <managed-bean-scope> will take a particular scope to keep managed bean
object. Where <navigation-rule> tag will take the total navigation model of a particular bean. Where <from-view-id> tag will take the name and location of the JSP page from which we
are getting request. Where <navigation-case> is providing single forward configuration. Where <from-out-come> tag will take the return value from Business method from
Managed Bean class. Where <ti-view-id> will take the name and location of the target page to which we want to
forward request.
Deployment Descriptor or web.xml
In general, in web applications, deployement descriptor is web.xml file, it able to provide the following configuration details.
- Welcome Files configuration.
- Display Names Configuration.
- Servlets Configuration.
- Filters configuration.
- Listeers Configurations.
- Initialization parameters configuration.
- Context Parameters Configurations.
In JSF based web applications, we have to provide FacesServlet configuration with load-on- startup configuration and we must provide url pattern for FacesServlet i either of the following forms. /faces/* *.jsf *.faces
Deployment Descriptor or web.xml — index.jsp
Example:
Deployment Descriptor or web.xml — loginform.jsp
Deployment Descriptor or web.xml — success.jsp
Deployment Descriptor or web.xml — failure.jsp
Deployment Descriptor or web.xml — LoginBean.java
Deployment Descriptor or web.xml — faces-config.xml
Deployment Descriptor or web.xml — web.xml
Deployment Descriptor or web.xml
If we want to integrate JSF with Spring Framework then we have to use the following steps.
- Prepare Presentation part as per JSF Conventions.
- Prepare Spring Beans and spring configuration file as per Spring Conventions
- Add Dependent Spring Service Bean to Managed Bean of JSF in faces-config.xml
Deployment Descriptor or web.xml — web.xml
Note: The main intention providing Spring Service Bean in faces-config.xml file is to inject Service bean in Jsf Managed Bean inorder to access Business methods.
- Provide "SpringBeanFacesELResolver" configuration in faces-config.xml
- <faces-config>
- <application>
- <el-resolver>
- org.springframework.web.jsf.el.SpringBeanFacesELResolver
- </el-resolver>
- </application>
- </faces-config>
Note: SpringBeanFacesResolver first delegates value lookups to the default resolver of the JSF and then to Spring's WebApplicationContext. This allows to inject springbased dependencies into JSF-managed beans.
- Provide ContextLoaderListener and RequestContextListener in web.xml file
EX:
Deployment Descriptor or web.xml — index.jsp
Note: These Listeners are used to load the complete Spring context at the time of Startup the Server.
Example:
Deployment Descriptor or web.xml — loginform.jsp
Deployment Descriptor or web.xml — success.jsp
Deployment Descriptor or web.xml — failure.jsp
Deployment Descriptor or web.xml — LoginBean.java
Deployment Descriptor or web.xml — UserService.java
Deployment Descriptor or web.xml — applicationContext.xml
Deployment Descriptor or web.xml — faces-config.xml
Deployment Descriptor or web.xml — web.xml
Deployment Descriptor or web.xml
To run above web applications we have to use the following jars
- Jsfjars
- Springjars
- Commons-Logging-version.jar
SF Jars
jsf1.2\jsf-api.jar jsf-impl.jar taglibs-standard-impl-1.2.5.jar taglibs-standard-spec-1.2.5.jar
Spring JARs
spring-aop-4.3.9.RELEASE.jar spring-beans-4.3.9.RELEASE.jar spring-context-4.3.9.RELEASE.jar spring-context-support-4.3.9.RELEASE.jar spring-core-4.3.9.RELEASE.jar spring-expression-4.3.9.RELEASE.jar commons-logiin-1.2.jar MAVEN COURSE MATERIAL
BY Index
MAVEN
Introduction
Maven is a "Yiddish"[German language] word meaning "Accumulator Of Knowledge". Maven was originally designed to simplify building processes in Jakarta Turbine project.
There were several projects and each project contained slightly different ANT build files. JARs were checked into CVS. Apache group then developed Maven which can build multiple projects together, publish projects information, deploy projects, share JARs across several projects and help in collaboration of teams MAVEN is a "Project Management Framework", it is much more than a simple Build tool, its declarative and standard approach simplifies many aspects of the Project Lifecycle. The main Objective of MAVEN is A comprehensive model for projects, which is reusable, maintainable, and easier to comprehend [Understand]. Plugins or tools that interact with this declarative model.
MAVEN follows "Convention over Configuration" Principle, which means that developers are not required to create build process themselves, Developers do not have to mention each and every configuration detail. Maven provides sensible default behavior for projects.
MAVEN does the following activities of the project lifecycle automatically. Provides default Project Structer Download Required Dependencies [Jars files] Compiles Source code Packaging projects as .jar, .war, .ear,.... Starts Server Deploying Projects into Servers. Perform Unit Testing Preparing Test Reports. Preparing Documentations Undeploy applications from Servers Stops Server. Project Object Model [pom.xml file]
- POM Stands for Project Object Model.
ii. POM is the fundamental unit in Maven. iii. POM is an XML file that contains information about the project and configuration details
used by Maven to build the project. iv. POM contains default values for projects ike build directory, which is target; the source
directory, which is src/main/java; the test source directory, which is src/test/java; and so on.
- In MAVEN1 , name of pom file is "project.xml", in MAVEN2 it was renamed to pom.xml.
vi. When we execute MAVEN project then MAVEN will look for the project configurations in pom.xml file and gets the needed things and executes the project.
In Building MAVEN Projects, pom.xml file contains the following configurations.
- Project Description
- Repository
- Dependency Management
- Project Inheritance
- Build Configuration
- Build Profiles
Project Description
In pom file, initial we will identify "Projection Description", it contains Project name, version number, packaged type,.....
- Key ideas of Spring - JSF Integration explained simply
- Ready-to-use code examples
- Exam-style questions at the end