SlideShare ist ein Scribd-Unternehmen logo
1 von 13
1



  The author has made every effort in the preparation of this book to ensure the accuracy of the information.
 However, information in this book is sold without warranty either expressed or implied. The author will not be
     held liable for any damages caused or alleged to be caused either directly or indirectly by this book.




       Ajax, JSF, Facelets, Eclipse & Maven
                     tutorials
   Ajax is a method of employing JavaScript, DHTML, and the XMLHttp behaviour in the
 browser to provide truly dynamic content on a Web page without a page refresh. There are
  quantifiable benefits to be realized for end users and businesses, which include improved
usability and faster applications. In this tutorial I will look at a simple example using Ajax4JSF
                           with JSF, Facelets, Maven2 and Eclipse.




                                                     By




                                         K. Arulkumaran

                                                      &

                                              A. Sivayini




                Website: http://www.lulu.com/java-success


              Feedback email: java-interview@hotmail.com
2

                                                 Table Of Contents


Notations ..................................................................................................................... 3
Tutorial 15 – Ajax4jsf with JSF & Facelets......................................................... 4
3
                                     Notations

Command prompt:




Eclipse:




File Explorer or Windows Explorer:




Internet Explorer:
4
Tutorial 15 – Ajax4jsf with JSF & Facelets


This tutorial will guide you through building a simple Ajax based Web
application. This tutorial assumes that you have gone through Tutorials 1-10
& the source code for tutorials 1-10. Also refer to Ajax4jsf developer guide at
https://ajax4jsf.dev.java.net/nonav/documentation/ajax-
documentation/developerGuide.html ) for further information.


Step 1: This tutorial will extend simpleWeb project we created earlier in Tutorials 1-10. We
will Ajax enable this Web application. We will be using Ajax4jsf (check
https://ajax4jsf.dev.java.net/ & http://labs.jboss.com/jbossajax4jsf/). Firstly add the Ajax4jsf
depedendency jar into pom.xml.

                <!-- AJAX -->
                <dependency>
                      <groupId>net.java.dev.ajax4jsf</groupId>
                      <artifactId>ajax4jsf</artifactId>
                      <version>1.0.6</version>
                </dependency>




The complete pom.xml file should look like:

<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-
v4_0_0.xsd">
         <modelVersion>4.0.0</modelVersion>
         <parent>
                  <groupId>com.mytutorial</groupId>
                  <artifactId>simple-tutorial</artifactId>
                  <version>1.0</version>
         </parent>

        <groupId>com.mytutorial</groupId>
        <artifactId>simpleWeb</artifactId>
        <packaging>war</packaging>
        <version>1.0-SNAPSHOT</version>
        <name>simpleWeb Maven Webapp</name>
        <url>http://maven.apache.org</url>
        <dependencies>
                  <dependency>
                          <groupId>com.mytutorial</groupId>
                          <artifactId>simple</artifactId>
5
        <version>1.0-SNAPSHOT</version>
        <type>jar</type>
</dependency>

<dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>3.8.1</version>
        <scope>test</scope>
</dependency>

<dependency>
        <groupId>commons-digester</groupId>
        <artifactId>commons-digester</artifactId>
        <version>1.8</version>
</dependency>

<dependency>
        <groupId>commons-collections</groupId>
        <artifactId>commons-collections</artifactId>
        <version>3.2</version>
</dependency>

<dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring</artifactId>
        <version>2.0.6</version>
</dependency>

<!-- JSF/JSTL/Facelets -->
<dependency>
         <groupId>javax.faces</groupId>
         <artifactId>jsf-api</artifactId>
         <version>1.2</version>
</dependency>
<dependency>
         <groupId>javax.faces</groupId>
         <artifactId>jsf-impl</artifactId>
         <version>1.2_04</version>
</dependency>
<dependency>
         <groupId>com.sun.facelets</groupId>
         <artifactId>jsf-facelets</artifactId>
         <version>1.1.11</version>
</dependency>
<dependency>
         <groupId>javax.servlet</groupId>
         <artifactId>jstl</artifactId>
         <version>1.1.2</version>
</dependency>
<dependency>
         <groupId>javax.el</groupId>
         <artifactId>el-api</artifactId>
         <version>1.0</version>
         <scope>provided</scope>
</dependency>
<dependency>
         <groupId>com.sun.el</groupId>
         <artifactId>el-ri</artifactId>
         <version>1.0</version>
</dependency>

<!-- AJAX -->
<dependency>
        <groupId>net.java.dev.ajax4jsf</groupId>
        <artifactId>ajax4jsf</artifactId>
        <version>1.0.6</version>
</dependency>
6
        </dependencies>
        <build>

                    <finalName>simpleWeb</finalName>
                    <pluginManagement />
         </build>
</project>


Step 2: Now, you need to go back to the command prompt and run the following command to add the
ajax4jsf jar to your build path.

C:tutorialssimple-tutorialsimpleWeb>mvn eclipse:clean eclipse:eclipse

STEP: WorkAround

The JSF 1.2 requires eclipse web facet 2.5. You need to open the file
“org.eclipse.wst.common.project.facet.core.xml” under C:tutorialssimple-
tutorialsimpleWeb.settings as shown below from version=2.4 to version=2.5. Every time you use
the eclipse:clean command, you will have to manually fix this up as shown below.




Step 3: Refresh the “simpleWeb” project.
7
Step 4: Following changes are required in the deployment descriptor files web.xml & faces-
config.xml as shown below:


faces-config.xml

Comment out the following line:

<view-handler>com.sun.facelets.FaceletViewHandler</view-handler>




web.xml

Following need to be added:

       <!-- ajax4jsf -->

       <context-param>
               <param-name>org.ajax4jsf.SKIN</param-name>
               <param-value>classic</param-value>
       </context-param>

       <context-param>
              <param-name>org.ajax4jsf.VIEW_HANDLERS</param-name>
              <param-value>com.sun.facelets.FaceletViewHandler</param-value>
       </context-param>


       <!-- ajax4jsf -->

       <filter>
                   <filter-name>ajax4jsf</filter-name>
                   <display-name>Ajax4jsf Filter</display-name>
                   <filter-class>org.ajax4jsf.Filter</filter-class>
       </filter>
8
        <filter-mapping>
                  <filter-name>ajax4jsf</filter-name>
                  <servlet-name>Faces Servlet</servlet-name>
        </filter-mapping>


The complete web.xml should look like:

<!DOCTYPE web-app PUBLIC
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd" >
<web-app>
           <!-- JSF        -->
           <context-param>
                     <param-name>javax.faces.STATE_SAVING_METHOD</param-name>
                     <param-value>server</param-value>
           </context-param>
           <context-param>
                     <param-name>javax.faces.CONFIG_FILES</param-name>
                     <param-value>/WEB-INF/faces-config.xml</param-value>
           </context-param>
           <context-param>
                     <param-name>javax.faces.DEFAULT_SUFFIX</param-name>
                     <param-value>.jspx</param-value>
           </context-param>

        <!-- Spring -->
        <context-param>
                  <param-name>contextConfigLocation</param-name>

                  <param-value>
                           <![CDATA[
                           /WEB-INF/applicationContext.xml
                           classpath:applicationContext-mytutorial.xml
                           ]]>
                  </param-value>
        </context-param>

        <!-- Special Debug Output for Development -->
        <context-param>
                   <param-name>facelets.DEVELOPMENT</param-name>
                   <param-value>true</param-value>
        </context-param>
        <!-- Optional JSF-RI Parameters to Help Debug -->
        <context-param>
                   <param-name>com.sun.faces.validateXml</param-name>
                   <param-value>true</param-value>
        </context-param>
        <context-param>
                   <param-name>com.sun.faces.verifyObjects</param-name>
                   <param-value>true</param-value>
        </context-param>

        <!-- ajax4jsf -->

        <context-param>
                  <param-name>org.ajax4jsf.SKIN</param-name>
                  <param-value>classic</param-value>
        </context-param>

        <context-param>
            <param-name>org.ajax4jsf.VIEW_HANDLERS</param-name>
            <param-value>com.sun.facelets.FaceletViewHandler</param-value>
        </context-param>


        <!-- ajax4jsf -->

        <filter>
                   <filter-name>ajax4jsf</filter-name>
                   <display-name>Ajax4jsf Filter</display-name>
                   <filter-class>org.ajax4jsf.Filter</filter-class>
        </filter>
        <filter-mapping>
                   <filter-name>ajax4jsf</filter-name>
                   <servlet-name>Faces Servlet</servlet-name>
        </filter-mapping>
9


        <!-- Listeners -->
        <listener>
                   <listener-class>
                              org.springframework.web.context.ContextLoaderListener
                   </listener-class>
        </listener>

        <listener>
                   <listener-class>
                              org.springframework.web.context.request.RequestContextListener
                   </listener-class>
        </listener>


        <!-- Faces Servlet -->
        <servlet>
                   <servlet-name>Faces Servlet</servlet-name>
                   <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
                   <load-on-startup>1</load-on-startup>
        </servlet>

        <!-- Faces Servlet Mapping -->
        <servlet-mapping>
                  <servlet-name>Faces Servlet</servlet-name>
                  <url-pattern>*.jsf</url-pattern>
        </servlet-mapping>


</web-app>




Step 5: Modify one of the pages to demonstrate Ajax in action using Ajax4JSF. We will
modify the inputname.jspx page to provide some Ajax functionality. We will provide Ajax
support to the <h:inputText …> where the person name is entered and behind the scenes
(with the help of Ajax) as we type in the name the managed bean “personBean” is updated
10
and contains the freshest value. This can be demonstrated by outputting the
#{personBean.personName} as shown below.

<?xml version="1.0" encoding="ISO-8859-1" ?>
<jsp:root xmlns:jsp="http://java.sun.com/JSP/Page"
         xmlns:h="http://java.sun.com/jsf/html"
         xmlns:f="http://java.sun.com/jsf/core"
         xmlns:ui="http://java.sun.com/jsf/facelets"
         xmlns:a4j="https://ajax4jsf.dev.java.net/ajax"
         version="2.0">

         <ui:composition>
                 <html>
                 <head>
                 <meta http-equiv="Content-Type"
                           content="text/html; charset=ISO-8859-1" />
                 <title>Insert title here</title>
                 </head>
                 <body>
                 <f:view>
                           <f:loadBundle basename="com.mytutorial.messages" var="msg" />
                           <h3><h:form id="helloForm">

                                 <h:outputText value="#{msg.prompt}" />
                                 <h:inputText value="#{personBean.personName}" >
                                    <a4j:support event="onkeyup" reRender="rep" />
                                 </h:inputText>

                                 <h:commandButton action="greeting" value="#{msg.button_text}" />

                                 <br/>
                                   Ajax in action by repeating what you type -->
                                 <b>
                                 <h:outputText value="#{personBean.personName}" id="rep" /> </b>

                              </h:form></h3>
                  </f:view>
                  </body>
                  </html>
          </ui:composition>
</jsp:root>
11
Step 6: Make sure that your HSQLDB is running, if not start it.

        Start the HSQL database server by executing the following command in a command
        prompt as shown below:

C:javahsqldb>java -cp ./lib/hsqldb.jar org.hsqldb.Server




Open another command prompt and run the following command:

C:javahsqldb>java -cp ./lib/hsqldb.jar org.hsqldb.util.DatabaseManager




This will spawn a new window as shown:




Step 7: Deploy the “simpleWeb” to Tomcat within eclipse.
12




Step 8: Open an Web browser and type the following URL:

http://localhost:8080/simpleWeb/index.jsf




Click on “Click Me”.
13
As you type the name in “onkeyup” JavaScript event will be fired. Each time this event is fired
on the parent tag, our application sends an AJAX request to the server. This means that the
“personName” on our managed “personBean” is updated with the freshest value of our
input. Isn’t this cool and useful?

Now, click on the “Hello” command button to retrieve data from the database.




That’s all to it.




Please feel free to email any errors to java-interview@hotmail.com. Also stay tuned at
    http://www.lulu.com/java-success for more tutorials and Java/J2EE interview
                                        resources.

Weitere ähnliche Inhalte

Was ist angesagt?

Andy Bosch - JavaServer Faces in the cloud
Andy Bosch -  JavaServer Faces in the cloudAndy Bosch -  JavaServer Faces in the cloud
Andy Bosch - JavaServer Faces in the cloud
Andy Bosch
 
Primefaces Nextgen Lju
Primefaces Nextgen LjuPrimefaces Nextgen Lju
Primefaces Nextgen Lju
Skills Matter
 

Was ist angesagt? (20)

What You Need To Build Cool Enterprise Applications With JSF
What You Need To Build Cool Enterprise Applications With JSFWhat You Need To Build Cool Enterprise Applications With JSF
What You Need To Build Cool Enterprise Applications With JSF
 
Andy Bosch - JavaServer Faces in the cloud
Andy Bosch -  JavaServer Faces in the cloudAndy Bosch -  JavaServer Faces in the cloud
Andy Bosch - JavaServer Faces in the cloud
 
The Rails Way
The Rails WayThe Rails Way
The Rails Way
 
Empowering users: modifying the admin experience
Empowering users: modifying the admin experienceEmpowering users: modifying the admin experience
Empowering users: modifying the admin experience
 
Troubleshooting APEX Performance Issues
Troubleshooting APEX Performance IssuesTroubleshooting APEX Performance Issues
Troubleshooting APEX Performance Issues
 
How to use soap component
How to use soap componentHow to use soap component
How to use soap component
 
How to Build SPA with Vue Router 2.0
How to Build SPA with Vue Router 2.0How to Build SPA with Vue Router 2.0
How to Build SPA with Vue Router 2.0
 
Open mic ibm connections and ibm verse on premise integration 1
Open mic  ibm connections and ibm verse on premise integration 1Open mic  ibm connections and ibm verse on premise integration 1
Open mic ibm connections and ibm verse on premise integration 1
 
Javatwo2012 java frameworkcomparison
Javatwo2012 java frameworkcomparisonJavatwo2012 java frameworkcomparison
Javatwo2012 java frameworkcomparison
 
Vuex
VuexVuex
Vuex
 
Laravel 로 배우는 서버사이드 #5
Laravel 로 배우는 서버사이드 #5Laravel 로 배우는 서버사이드 #5
Laravel 로 배우는 서버사이드 #5
 
MySQL crash course by moshe kaplan
MySQL crash course by moshe kaplanMySQL crash course by moshe kaplan
MySQL crash course by moshe kaplan
 
Websphere portal theme menu framework
Websphere portal theme menu frameworkWebsphere portal theme menu framework
Websphere portal theme menu framework
 
Ionic tabs template explained
Ionic tabs template explainedIonic tabs template explained
Ionic tabs template explained
 
AngularJS vs. Ember.js vs. Backbone.js
AngularJS vs. Ember.js vs. Backbone.jsAngularJS vs. Ember.js vs. Backbone.js
AngularJS vs. Ember.js vs. Backbone.js
 
Uniface Lectures Webinar - Building Responsive Applications with Uniface: Dep...
Uniface Lectures Webinar - Building Responsive Applications with Uniface: Dep...Uniface Lectures Webinar - Building Responsive Applications with Uniface: Dep...
Uniface Lectures Webinar - Building Responsive Applications with Uniface: Dep...
 
Ionic으로 모바일앱 만들기 #4
Ionic으로 모바일앱 만들기 #4Ionic으로 모바일앱 만들기 #4
Ionic으로 모바일앱 만들기 #4
 
Xml sitemap content 500 pages
Xml sitemap content 500 pagesXml sitemap content 500 pages
Xml sitemap content 500 pages
 
Primefaces Nextgen Lju
Primefaces Nextgen LjuPrimefaces Nextgen Lju
Primefaces Nextgen Lju
 
Angular JS blog tutorial
Angular JS blog tutorialAngular JS blog tutorial
Angular JS blog tutorial
 

Andere mochten auch

Logminingsurvey
LogminingsurveyLogminingsurvey
Logminingsurvey
drewz lin
 
IBM Web Content Management - Melhores práticas
IBM Web Content Management - Melhores práticasIBM Web Content Management - Melhores práticas
IBM Web Content Management - Melhores práticas
rodrigoareis
 
Attack_Simulation_and_Threat_Modeling
Attack_Simulation_and_Threat_ModelingAttack_Simulation_and_Threat_Modeling
Attack_Simulation_and_Threat_Modeling
Oluseyi Akindeinde
 
2011 New Product Showcase
2011 New Product Showcase2011 New Product Showcase
2011 New Product Showcase
bmmitt
 

Andere mochten auch (20)

Ticer2005
Ticer2005Ticer2005
Ticer2005
 
Logminingsurvey
LogminingsurveyLogminingsurvey
Logminingsurvey
 
IBM Web Content Management - Melhores práticas
IBM Web Content Management - Melhores práticasIBM Web Content Management - Melhores práticas
IBM Web Content Management - Melhores práticas
 
Xakep
XakepXakep
Xakep
 
Recherche
RechercheRecherche
Recherche
 
Tomislav Capan - Muzika Hr (IT Showoff)
Tomislav Capan - Muzika Hr (IT Showoff)Tomislav Capan - Muzika Hr (IT Showoff)
Tomislav Capan - Muzika Hr (IT Showoff)
 
Unemployment
UnemploymentUnemployment
Unemployment
 
Catalog
CatalogCatalog
Catalog
 
Search engines
Search enginesSearch engines
Search engines
 
Métricas em mídias sociais (versão 2010)
Métricas em mídias sociais (versão 2010)Métricas em mídias sociais (versão 2010)
Métricas em mídias sociais (versão 2010)
 
互联网搜索技巧
互联网搜索技巧互联网搜索技巧
互联网搜索技巧
 
Attack_Simulation_and_Threat_Modeling
Attack_Simulation_and_Threat_ModelingAttack_Simulation_and_Threat_Modeling
Attack_Simulation_and_Threat_Modeling
 
Shanghai big tradeshow calendar 2014 collection by MARKYE@LIERJIA.CN
Shanghai big tradeshow calendar 2014 collection by MARKYE@LIERJIA.CN Shanghai big tradeshow calendar 2014 collection by MARKYE@LIERJIA.CN
Shanghai big tradeshow calendar 2014 collection by MARKYE@LIERJIA.CN
 
document
documentdocument
document
 
2011 New Product Showcase
2011 New Product Showcase2011 New Product Showcase
2011 New Product Showcase
 
Medication Reconciliation in Electronic Health Information Exchange
Medication Reconciliation in Electronic Health Information ExchangeMedication Reconciliation in Electronic Health Information Exchange
Medication Reconciliation in Electronic Health Information Exchange
 
Google
GoogleGoogle
Google
 
Web Application Hacking 2004
Web Application Hacking 2004Web Application Hacking 2004
Web Application Hacking 2004
 
Adobe Digital Publishing Suite by dualpixel
Adobe Digital Publishing Suite by dualpixelAdobe Digital Publishing Suite by dualpixel
Adobe Digital Publishing Suite by dualpixel
 
Asp net (versione 1 e 2)
Asp net (versione 1 e 2)Asp net (versione 1 e 2)
Asp net (versione 1 e 2)
 

Ähnlich wie Ajax, JSF, Facelets, Eclipse & Maven tutorials

JavaDo#09 Spring boot入門ハンズオン
JavaDo#09 Spring boot入門ハンズオンJavaDo#09 Spring boot入門ハンズオン
JavaDo#09 Spring boot入門ハンズオン
haruki ueno
 
Jsf, facelets, spring, hibernate, maven2
Jsf, facelets, spring, hibernate, maven2Jsf, facelets, spring, hibernate, maven2
Jsf, facelets, spring, hibernate, maven2
Raghavan Mohan
 
How to create a skeleton of a Java console application
How to create a skeleton of a Java console applicationHow to create a skeleton of a Java console application
How to create a skeleton of a Java console application
Dmitri Pisarenko
 
Stepbystepguideforbuidlingsimplestrutsapp 090702025438-phpapp02
Stepbystepguideforbuidlingsimplestrutsapp 090702025438-phpapp02Stepbystepguideforbuidlingsimplestrutsapp 090702025438-phpapp02
Stepbystepguideforbuidlingsimplestrutsapp 090702025438-phpapp02
Rati Manandhar
 

Ähnlich wie Ajax, JSF, Facelets, Eclipse & Maven tutorials (20)

JavaDo#09 Spring boot入門ハンズオン
JavaDo#09 Spring boot入門ハンズオンJavaDo#09 Spring boot入門ハンズオン
JavaDo#09 Spring boot入門ハンズオン
 
Jsf, facelets, spring, hibernate, maven2
Jsf, facelets, spring, hibernate, maven2Jsf, facelets, spring, hibernate, maven2
Jsf, facelets, spring, hibernate, maven2
 
JSF, Facelets, Spring-JSF & Maven
JSF, Facelets, Spring-JSF & MavenJSF, Facelets, Spring-JSF & Maven
JSF, Facelets, Spring-JSF & Maven
 
Jsf
JsfJsf
Jsf
 
Pom
PomPom
Pom
 
Pom configuration java xml
Pom configuration java xmlPom configuration java xml
Pom configuration java xml
 
JSF 2.0 Preview
JSF 2.0 PreviewJSF 2.0 Preview
JSF 2.0 Preview
 
#31.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)_스프링프레임워크 강좌, 재직자환급교육,실업자국비지원...
#31.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)_스프링프레임워크 강좌, 재직자환급교육,실업자국비지원...#31.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)_스프링프레임워크 강좌, 재직자환급교육,실업자국비지원...
#31.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)_스프링프레임워크 강좌, 재직자환급교육,실업자국비지원...
 
Java, Eclipse, Maven & JSF tutorial
Java, Eclipse, Maven & JSF tutorialJava, Eclipse, Maven & JSF tutorial
Java, Eclipse, Maven & JSF tutorial
 
AOP sec3.pptx
AOP sec3.pptxAOP sec3.pptx
AOP sec3.pptx
 
Servlets 3.0 - Asynchronous, Extensibility, Ease-of-use @ JavaOne Brazil 2010
Servlets 3.0 - Asynchronous, Extensibility, Ease-of-use @ JavaOne Brazil 2010Servlets 3.0 - Asynchronous, Extensibility, Ease-of-use @ JavaOne Brazil 2010
Servlets 3.0 - Asynchronous, Extensibility, Ease-of-use @ JavaOne Brazil 2010
 
Google app engine by example
Google app engine by exampleGoogle app engine by example
Google app engine by example
 
Spring into rails
Spring into railsSpring into rails
Spring into rails
 
JavaServer Faces 2.0 - JavaOne India 2011
JavaServer Faces 2.0 - JavaOne India 2011JavaServer Faces 2.0 - JavaOne India 2011
JavaServer Faces 2.0 - JavaOne India 2011
 
Jlook web ui framework
Jlook web ui frameworkJlook web ui framework
Jlook web ui framework
 
How to create a skeleton of a Java console application
How to create a skeleton of a Java console applicationHow to create a skeleton of a Java console application
How to create a skeleton of a Java console application
 
Spring Web Service, Spring JMS, Eclipse & Maven tutorials
Spring Web Service, Spring JMS, Eclipse & Maven tutorialsSpring Web Service, Spring JMS, Eclipse & Maven tutorials
Spring Web Service, Spring JMS, Eclipse & Maven tutorials
 
Sel study notes
Sel study notesSel study notes
Sel study notes
 
Web-Performance
Web-PerformanceWeb-Performance
Web-Performance
 
Stepbystepguideforbuidlingsimplestrutsapp 090702025438-phpapp02
Stepbystepguideforbuidlingsimplestrutsapp 090702025438-phpapp02Stepbystepguideforbuidlingsimplestrutsapp 090702025438-phpapp02
Stepbystepguideforbuidlingsimplestrutsapp 090702025438-phpapp02
 

Mehr von Raghavan Mohan

Mehr von Raghavan Mohan (13)

Accelerate with BIRT and Actuate11
Accelerate with BIRT and Actuate11Accelerate with BIRT and Actuate11
Accelerate with BIRT and Actuate11
 
Who is BIRT
Who is BIRTWho is BIRT
Who is BIRT
 
Introduction to BIRT
Introduction to BIRTIntroduction to BIRT
Introduction to BIRT
 
Sachin Tendulkar Resume
Sachin Tendulkar ResumeSachin Tendulkar Resume
Sachin Tendulkar Resume
 
Manmohan Singh Resume
Manmohan Singh ResumeManmohan Singh Resume
Manmohan Singh Resume
 
Senator Barrack Obama Resume
Senator Barrack Obama ResumeSenator Barrack Obama Resume
Senator Barrack Obama Resume
 
Java/J2EE CV Guide
Java/J2EE CV GuideJava/J2EE CV Guide
Java/J2EE CV Guide
 
Java/J2EE Companion
Java/J2EE CompanionJava/J2EE Companion
Java/J2EE Companion
 
Hibernate, Spring, Eclipse, HSQL Database & Maven tutorial
Hibernate, Spring, Eclipse, HSQL Database & Maven tutorialHibernate, Spring, Eclipse, HSQL Database & Maven tutorial
Hibernate, Spring, Eclipse, HSQL Database & Maven tutorial
 
Fast Track to Ajax.
Fast Track to Ajax.Fast Track to Ajax.
Fast Track to Ajax.
 
23617968 digit-fast-track-jan-2009-php
23617968 digit-fast-track-jan-2009-php23617968 digit-fast-track-jan-2009-php
23617968 digit-fast-track-jan-2009-php
 
Quality - Douglas Crockford
Quality - Douglas CrockfordQuality - Douglas Crockford
Quality - Douglas Crockford
 
The JavaScript Programming Language
The JavaScript Programming LanguageThe JavaScript Programming Language
The JavaScript Programming Language
 

Kürzlich hochgeladen

Structuring Teams and Portfolios for Success
Structuring Teams and Portfolios for SuccessStructuring Teams and Portfolios for Success
Structuring Teams and Portfolios for Success
UXDXConf
 

Kürzlich hochgeladen (20)

Structuring Teams and Portfolios for Success
Structuring Teams and Portfolios for SuccessStructuring Teams and Portfolios for Success
Structuring Teams and Portfolios for Success
 
IESVE for Early Stage Design and Planning
IESVE for Early Stage Design and PlanningIESVE for Early Stage Design and Planning
IESVE for Early Stage Design and Planning
 
Choosing the Right FDO Deployment Model for Your Application _ Geoffrey at In...
Choosing the Right FDO Deployment Model for Your Application _ Geoffrey at In...Choosing the Right FDO Deployment Model for Your Application _ Geoffrey at In...
Choosing the Right FDO Deployment Model for Your Application _ Geoffrey at In...
 
ERP Contender Series: Acumatica vs. Sage Intacct
ERP Contender Series: Acumatica vs. Sage IntacctERP Contender Series: Acumatica vs. Sage Intacct
ERP Contender Series: Acumatica vs. Sage Intacct
 
Simplified FDO Manufacturing Flow with TPMs _ Liam at Infineon.pdf
Simplified FDO Manufacturing Flow with TPMs _ Liam at Infineon.pdfSimplified FDO Manufacturing Flow with TPMs _ Liam at Infineon.pdf
Simplified FDO Manufacturing Flow with TPMs _ Liam at Infineon.pdf
 
1111 ChatGPT Prompts PDF Free Download - Prompts for ChatGPT
1111 ChatGPT Prompts PDF Free Download - Prompts for ChatGPT1111 ChatGPT Prompts PDF Free Download - Prompts for ChatGPT
1111 ChatGPT Prompts PDF Free Download - Prompts for ChatGPT
 
Your enemies use GenAI too - staying ahead of fraud with Neo4j
Your enemies use GenAI too - staying ahead of fraud with Neo4jYour enemies use GenAI too - staying ahead of fraud with Neo4j
Your enemies use GenAI too - staying ahead of fraud with Neo4j
 
Portal Kombat : extension du réseau de propagande russe
Portal Kombat : extension du réseau de propagande russePortal Kombat : extension du réseau de propagande russe
Portal Kombat : extension du réseau de propagande russe
 
Designing for Hardware Accessibility at Comcast
Designing for Hardware Accessibility at ComcastDesigning for Hardware Accessibility at Comcast
Designing for Hardware Accessibility at Comcast
 
Oauth 2.0 Introduction and Flows with MuleSoft
Oauth 2.0 Introduction and Flows with MuleSoftOauth 2.0 Introduction and Flows with MuleSoft
Oauth 2.0 Introduction and Flows with MuleSoft
 
Working together SRE & Platform Engineering
Working together SRE & Platform EngineeringWorking together SRE & Platform Engineering
Working together SRE & Platform Engineering
 
Continuing Bonds Through AI: A Hermeneutic Reflection on Thanabots
Continuing Bonds Through AI: A Hermeneutic Reflection on ThanabotsContinuing Bonds Through AI: A Hermeneutic Reflection on Thanabots
Continuing Bonds Through AI: A Hermeneutic Reflection on Thanabots
 
Microsoft CSP Briefing Pre-Engagement - Questionnaire
Microsoft CSP Briefing Pre-Engagement - QuestionnaireMicrosoft CSP Briefing Pre-Engagement - Questionnaire
Microsoft CSP Briefing Pre-Engagement - Questionnaire
 
Introduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdf
Introduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdfIntroduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdf
Introduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdf
 
Linux Foundation Edge _ Overview of FDO Software Components _ Randy at Intel.pdf
Linux Foundation Edge _ Overview of FDO Software Components _ Randy at Intel.pdfLinux Foundation Edge _ Overview of FDO Software Components _ Randy at Intel.pdf
Linux Foundation Edge _ Overview of FDO Software Components _ Randy at Intel.pdf
 
Overview of Hyperledger Foundation
Overview of Hyperledger FoundationOverview of Hyperledger Foundation
Overview of Hyperledger Foundation
 
Integrating Telephony Systems with Salesforce: Insights and Considerations, B...
Integrating Telephony Systems with Salesforce: Insights and Considerations, B...Integrating Telephony Systems with Salesforce: Insights and Considerations, B...
Integrating Telephony Systems with Salesforce: Insights and Considerations, B...
 
A Business-Centric Approach to Design System Strategy
A Business-Centric Approach to Design System StrategyA Business-Centric Approach to Design System Strategy
A Business-Centric Approach to Design System Strategy
 
The Value of Certifying Products for FDO _ Paul at FIDO Alliance.pdf
The Value of Certifying Products for FDO _ Paul at FIDO Alliance.pdfThe Value of Certifying Products for FDO _ Paul at FIDO Alliance.pdf
The Value of Certifying Products for FDO _ Paul at FIDO Alliance.pdf
 
AI presentation and introduction - Retrieval Augmented Generation RAG 101
AI presentation and introduction - Retrieval Augmented Generation RAG 101AI presentation and introduction - Retrieval Augmented Generation RAG 101
AI presentation and introduction - Retrieval Augmented Generation RAG 101
 

Ajax, JSF, Facelets, Eclipse & Maven tutorials

  • 1. 1 The author has made every effort in the preparation of this book to ensure the accuracy of the information. However, information in this book is sold without warranty either expressed or implied. The author will not be held liable for any damages caused or alleged to be caused either directly or indirectly by this book. Ajax, JSF, Facelets, Eclipse & Maven tutorials Ajax is a method of employing JavaScript, DHTML, and the XMLHttp behaviour in the browser to provide truly dynamic content on a Web page without a page refresh. There are quantifiable benefits to be realized for end users and businesses, which include improved usability and faster applications. In this tutorial I will look at a simple example using Ajax4JSF with JSF, Facelets, Maven2 and Eclipse. By K. Arulkumaran & A. Sivayini Website: http://www.lulu.com/java-success Feedback email: java-interview@hotmail.com
  • 2. 2 Table Of Contents Notations ..................................................................................................................... 3 Tutorial 15 – Ajax4jsf with JSF & Facelets......................................................... 4
  • 3. 3 Notations Command prompt: Eclipse: File Explorer or Windows Explorer: Internet Explorer:
  • 4. 4 Tutorial 15 – Ajax4jsf with JSF & Facelets This tutorial will guide you through building a simple Ajax based Web application. This tutorial assumes that you have gone through Tutorials 1-10 & the source code for tutorials 1-10. Also refer to Ajax4jsf developer guide at https://ajax4jsf.dev.java.net/nonav/documentation/ajax- documentation/developerGuide.html ) for further information. Step 1: This tutorial will extend simpleWeb project we created earlier in Tutorials 1-10. We will Ajax enable this Web application. We will be using Ajax4jsf (check https://ajax4jsf.dev.java.net/ & http://labs.jboss.com/jbossajax4jsf/). Firstly add the Ajax4jsf depedendency jar into pom.xml. <!-- AJAX --> <dependency> <groupId>net.java.dev.ajax4jsf</groupId> <artifactId>ajax4jsf</artifactId> <version>1.0.6</version> </dependency> The complete pom.xml file should look like: <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven- v4_0_0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>com.mytutorial</groupId> <artifactId>simple-tutorial</artifactId> <version>1.0</version> </parent> <groupId>com.mytutorial</groupId> <artifactId>simpleWeb</artifactId> <packaging>war</packaging> <version>1.0-SNAPSHOT</version> <name>simpleWeb Maven Webapp</name> <url>http://maven.apache.org</url> <dependencies> <dependency> <groupId>com.mytutorial</groupId> <artifactId>simple</artifactId>
  • 5. 5 <version>1.0-SNAPSHOT</version> <type>jar</type> </dependency> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>3.8.1</version> <scope>test</scope> </dependency> <dependency> <groupId>commons-digester</groupId> <artifactId>commons-digester</artifactId> <version>1.8</version> </dependency> <dependency> <groupId>commons-collections</groupId> <artifactId>commons-collections</artifactId> <version>3.2</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring</artifactId> <version>2.0.6</version> </dependency> <!-- JSF/JSTL/Facelets --> <dependency> <groupId>javax.faces</groupId> <artifactId>jsf-api</artifactId> <version>1.2</version> </dependency> <dependency> <groupId>javax.faces</groupId> <artifactId>jsf-impl</artifactId> <version>1.2_04</version> </dependency> <dependency> <groupId>com.sun.facelets</groupId> <artifactId>jsf-facelets</artifactId> <version>1.1.11</version> </dependency> <dependency> <groupId>javax.servlet</groupId> <artifactId>jstl</artifactId> <version>1.1.2</version> </dependency> <dependency> <groupId>javax.el</groupId> <artifactId>el-api</artifactId> <version>1.0</version> <scope>provided</scope> </dependency> <dependency> <groupId>com.sun.el</groupId> <artifactId>el-ri</artifactId> <version>1.0</version> </dependency> <!-- AJAX --> <dependency> <groupId>net.java.dev.ajax4jsf</groupId> <artifactId>ajax4jsf</artifactId> <version>1.0.6</version> </dependency>
  • 6. 6 </dependencies> <build> <finalName>simpleWeb</finalName> <pluginManagement /> </build> </project> Step 2: Now, you need to go back to the command prompt and run the following command to add the ajax4jsf jar to your build path. C:tutorialssimple-tutorialsimpleWeb>mvn eclipse:clean eclipse:eclipse STEP: WorkAround The JSF 1.2 requires eclipse web facet 2.5. You need to open the file “org.eclipse.wst.common.project.facet.core.xml” under C:tutorialssimple- tutorialsimpleWeb.settings as shown below from version=2.4 to version=2.5. Every time you use the eclipse:clean command, you will have to manually fix this up as shown below. Step 3: Refresh the “simpleWeb” project.
  • 7. 7 Step 4: Following changes are required in the deployment descriptor files web.xml & faces- config.xml as shown below: faces-config.xml Comment out the following line: <view-handler>com.sun.facelets.FaceletViewHandler</view-handler> web.xml Following need to be added: <!-- ajax4jsf --> <context-param> <param-name>org.ajax4jsf.SKIN</param-name> <param-value>classic</param-value> </context-param> <context-param> <param-name>org.ajax4jsf.VIEW_HANDLERS</param-name> <param-value>com.sun.facelets.FaceletViewHandler</param-value> </context-param> <!-- ajax4jsf --> <filter> <filter-name>ajax4jsf</filter-name> <display-name>Ajax4jsf Filter</display-name> <filter-class>org.ajax4jsf.Filter</filter-class> </filter>
  • 8. 8 <filter-mapping> <filter-name>ajax4jsf</filter-name> <servlet-name>Faces Servlet</servlet-name> </filter-mapping> The complete web.xml should look like: <!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd" > <web-app> <!-- JSF --> <context-param> <param-name>javax.faces.STATE_SAVING_METHOD</param-name> <param-value>server</param-value> </context-param> <context-param> <param-name>javax.faces.CONFIG_FILES</param-name> <param-value>/WEB-INF/faces-config.xml</param-value> </context-param> <context-param> <param-name>javax.faces.DEFAULT_SUFFIX</param-name> <param-value>.jspx</param-value> </context-param> <!-- Spring --> <context-param> <param-name>contextConfigLocation</param-name> <param-value> <![CDATA[ /WEB-INF/applicationContext.xml classpath:applicationContext-mytutorial.xml ]]> </param-value> </context-param> <!-- Special Debug Output for Development --> <context-param> <param-name>facelets.DEVELOPMENT</param-name> <param-value>true</param-value> </context-param> <!-- Optional JSF-RI Parameters to Help Debug --> <context-param> <param-name>com.sun.faces.validateXml</param-name> <param-value>true</param-value> </context-param> <context-param> <param-name>com.sun.faces.verifyObjects</param-name> <param-value>true</param-value> </context-param> <!-- ajax4jsf --> <context-param> <param-name>org.ajax4jsf.SKIN</param-name> <param-value>classic</param-value> </context-param> <context-param> <param-name>org.ajax4jsf.VIEW_HANDLERS</param-name> <param-value>com.sun.facelets.FaceletViewHandler</param-value> </context-param> <!-- ajax4jsf --> <filter> <filter-name>ajax4jsf</filter-name> <display-name>Ajax4jsf Filter</display-name> <filter-class>org.ajax4jsf.Filter</filter-class> </filter> <filter-mapping> <filter-name>ajax4jsf</filter-name> <servlet-name>Faces Servlet</servlet-name> </filter-mapping>
  • 9. 9 <!-- Listeners --> <listener> <listener-class> org.springframework.web.context.ContextLoaderListener </listener-class> </listener> <listener> <listener-class> org.springframework.web.context.request.RequestContextListener </listener-class> </listener> <!-- Faces Servlet --> <servlet> <servlet-name>Faces Servlet</servlet-name> <servlet-class>javax.faces.webapp.FacesServlet</servlet-class> <load-on-startup>1</load-on-startup> </servlet> <!-- Faces Servlet Mapping --> <servlet-mapping> <servlet-name>Faces Servlet</servlet-name> <url-pattern>*.jsf</url-pattern> </servlet-mapping> </web-app> Step 5: Modify one of the pages to demonstrate Ajax in action using Ajax4JSF. We will modify the inputname.jspx page to provide some Ajax functionality. We will provide Ajax support to the <h:inputText …> where the person name is entered and behind the scenes (with the help of Ajax) as we type in the name the managed bean “personBean” is updated
  • 10. 10 and contains the freshest value. This can be demonstrated by outputting the #{personBean.personName} as shown below. <?xml version="1.0" encoding="ISO-8859-1" ?> <jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core" xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:a4j="https://ajax4jsf.dev.java.net/ajax" version="2.0"> <ui:composition> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" /> <title>Insert title here</title> </head> <body> <f:view> <f:loadBundle basename="com.mytutorial.messages" var="msg" /> <h3><h:form id="helloForm"> <h:outputText value="#{msg.prompt}" /> <h:inputText value="#{personBean.personName}" > <a4j:support event="onkeyup" reRender="rep" /> </h:inputText> <h:commandButton action="greeting" value="#{msg.button_text}" /> <br/> Ajax in action by repeating what you type --> <b> <h:outputText value="#{personBean.personName}" id="rep" /> </b> </h:form></h3> </f:view> </body> </html> </ui:composition> </jsp:root>
  • 11. 11 Step 6: Make sure that your HSQLDB is running, if not start it. Start the HSQL database server by executing the following command in a command prompt as shown below: C:javahsqldb>java -cp ./lib/hsqldb.jar org.hsqldb.Server Open another command prompt and run the following command: C:javahsqldb>java -cp ./lib/hsqldb.jar org.hsqldb.util.DatabaseManager This will spawn a new window as shown: Step 7: Deploy the “simpleWeb” to Tomcat within eclipse.
  • 12. 12 Step 8: Open an Web browser and type the following URL: http://localhost:8080/simpleWeb/index.jsf Click on “Click Me”.
  • 13. 13 As you type the name in “onkeyup” JavaScript event will be fired. Each time this event is fired on the parent tag, our application sends an AJAX request to the server. This means that the “personName” on our managed “personBean” is updated with the freshest value of our input. Isn’t this cool and useful? Now, click on the “Hello” command button to retrieve data from the database. That’s all to it. Please feel free to email any errors to java-interview@hotmail.com. Also stay tuned at http://www.lulu.com/java-success for more tutorials and Java/J2EE interview resources.