SlideShare ist ein Scribd-Unternehmen logo
1 von 40
Introduction to JavaServerFaces
          & MyFaces
          Anudeep Jassal




                                  1
Topics of Discussion
What is JSF?
JSF Architecture.
How does JSF work.
What is MyFaces?




                       2
What is Java Server Faces?
 JSF is a new and upcoming web application
  framework that accomplishes the MVC paradigm
  It is similar to Struts but has features and concepts
  that are beyond those of Struts - especially the
  component orientation.
 Provides set of reusable custom components.
 Provides set of JSP tags to access those
  components.


                                                          3
JSF Architecture
 JSF follows MVC framework
 Model: objects and properties of application
 View: Renderers take care of view.
 Controller: FacesServlet/ JSF infrastructure
  defines the flow of the application.



                                                 4
How JSF works
A form is displayed
   Form uses <f:view> and <h:form>
The form is submitted to itself.
The bean is instantiated. Listed in the
managed-bean section of faces-config.xml
The action controller method is invoked.
The action method returns a condition.
The result page is displayed.
                                           5
Login page




             6
Welcome page




               7
Example files
index.jsp,welcome.jsp – define the login and
  welcome screens.
UserBean.java – manages user data
faces-config.xml – configuration file for the
  application.
web.xml – deployment descriptor.




                                                8
JSF Example(index.jsp)
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
<f:loadBundle basename=“com.corejsf.bundle.Messages" var="Message"/>
<f:view>
…
    <h:form>
     <h3><h:outputText value="#{Message.inputname_header}"/></h3>
     <table>
     <tr>
     <td>Name:</td>
     <h:inputText value="#{user.name}“ required=“true”/>
     <f:validateLength minimum="2" maximum="20"/>
     …
     <td>Password:</td>
     <h:inputSecret value="#{user.password}"/>
     …
    <h:commandButton value="Login" action="login"/>
    </h:form>
</f:view>
                                                                       9
index.jsp

    Tag Libraries: core and html.
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>

    Core tags are used to perform core actions and display nothing to the
    user. Html tags are used to render html elements(text, form elements
    etc) to the user.
    <f:loadBundle> is a core tag. Loads properties file and makes it value
    available to variable message.
<f:loadBundle basename=“com.corejsf..bundle.Messages" var="Message"/>

    All JSF components must be nested inside <f:view> core tag.
<f:view>
    <h:form>
      <h3><h:outputText value="#{Message.inputname_header}"/></h3>
      <h:inputText value="#{user.name}“ required=“true”/>
      <f:validateLength minimum="2" maximum="20"/>
     <h:inputSecret value="#{user.password}"/>
     <h:commandButton value="Login" action="login"/>
   </h:form>
</f:view>
                                                                             10
Example (Cntd.)
    Any attribute value that starts with # and is wrapped in {} is
    dynamically substituted in
#{Message.inputname_header}

    <h:form> represents form element
    Form action is defined in the <h:commandButton> element.
<h:commandButton value="Login" action="login"/>

    <h:inputText> for name field renders a textbox. Required attribute tells
    the value must be provided by the user. Thus validating the field.
<h:inputText value="#{user.userName}" required="true">

    Nested core tag provides range validation.
<f:validateLength minimum="2" maximum="20"/>




                                                                               11
UserBean.java
public class UserBean {
public String getName() { . . . }
public void setName(String newValue) {. . . }
public String getPassword() { . . . }
public void setPassword(String newValue) { . . . }
...
}




                                                     12
Configuration file (faces-config.xml)
<?xml version="1.0"?>

<!DOCTYPE faces-config PUBLIC
"-//Sun Microsystems, Inc.//DTD JavaServer Faces Config 1.0//EN"
"http://java.sun.com/dtd/web-facesconfig_1_0.dtd">

<faces-config>
    <navigation-rule>
       <from-view-id>/index.jsp</from-view-id>
      <navigation-case>
      <from-outcome>login</from-outcome>
      <to-view-id>/welcome.jsp</to-view-id>
      </ navigation-case>
    </navigation-rule>

    <managed-bean>
       <managed-bean-name>user</managed-bean-name>
       <managed-bean-class>com.corejsf.UserBean</managed-bean-class>
       <managed-bean-scope>session</managed-bean-scope>
    </managed-bean>
</faces-config>




                                                                       13
Configuration File(Cntd.)
   faces-config.xml defines how one page will navigate to
   next. Also specifies managed beans.
<navigation-rule>
    <from-view-id>/index.jsp</from-view-id>
    <navigation-case>
        <from-outcome>login</from-outcome>
        <to-view-id>/welcome.jsp</to-view-id>
    </navigation-case>
</navigation-rule

   <from-view-id> page you are currently on.
   <to-view-id> next page to display.
   <from-outcome> value matches the action attribute of the
   command button of index.jsp
<h:commandButton value="Login" action="login"/>


                                                              14
Configuration file (Cntd.)
   Managed bean is the model of the framework.
   <managed-bean-name> is the name the views use to
   reference the bean.<managed-bean-name>user</managed-bean-name>
<h:inputText value="#{user.name}“ required=“true”/>

   <managed-bean-class> is the fully classified name for the
   bean.
<managed-bean-class> com.corejsf.UserBean </managed-bean-class>

<managed-bean-scope>session</managed-bean-scope>




                                                                    15
Web.xml (Deployment Descriptor)

<context-param>
<param-name>
   javax.faces.CONFIG_FILES</param-name>
<param-value>
   /WEB-INF/faces-config.xml
</param-value>
   <description>
   </description>
</context-param>
<servlet>
     <servlet-name>Faces Servlet</servlet-name>
     <servlet-class>
         javax.faces.webapp.FacesServlet
     </servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
     <servlet-name>Faces Servlet</servlet-name>
<url-pattern *.faces </url-pattern>
</servlet-mapping>                                16
Web.xml (Cntd.)
   Javax.faces.CONFIG_FILES parameter tells where the JSF
   configuration file exists.
<param-name>
    javax.faces.CONFIG_FILES
</param-name>
<param-value>
   /WEB-INF/examples-config.xml
</param-value>
   Javax.faces.STATE_SAVING_METHOD specifies where the state
   must be saved: client or server.
<param-name>
    javax.faces.STATE_SAVING_METHOD
</param-name>
<param-value>server</param-value>
   The servlet-mapping and servlet blocks specify that any URL that ends
   in a .jsf extension should be redirected through a servlet called
   javax.faces.webapp.FacesServlet.

                                                                           17
What is Apache MyFaces?
First free open source implementation of
JSF.
Provides rich set of prefabricated
components.




                                           18
MyFaces Component Libraries
Tomahawk
•   Original MyFaces component library.
Tobago
•   Apache Library now under MyFaces umbrella.
Trinidad
•   Originally Oracle ADF components.



                                                 19
Using MyFaces Tomahawk Components

   Add jar files to WEB-INF/lib
    • Tomahawk.jar
    • Commons-fileupload.jar
    • Commons-validator.jar
    • Oro-xxx-jar
   Import the extended tag library
<%@ taglib uri=http://myfaces.apache.org/tomahawk prefix="t"%>
   Enable extensions filter
    •   Add a filter and two filter mappings in web.xml
         -   Delivers JavaScript code and style sheets. Components which use
             JavaScript will fail without these entries in web.xml


                                                                               20
Date Component

Input Text control for dates.
Attributes
 • Value – the Date value.

 • Type – Defines the content type. Date,time or both

 • popupCalendar - If true, button added that pops up
   JavaScript calendar for input. Default is false




                                                        21
t:inputDate example

    Main JSP page
<h:form>
    Date: <t:inputDate value=“#{sample.date}” popupCalendar="true"/><BR>
<h:commandButton action="show-date"/>
</h:form>

    Bean
package coreservlets
import java.util.*;
public class SampleBean {
private Date date;
public Date getDate() { return(date); }
public void setDate(Date date) {
this.date = date;
}



                                                                           22
Example (Cntd.)

    faces-config.xml
<managed-bean>
    <managed-bean-name>sample</managed-bean-name>
<managed-bean-class>
    coreservlets.SampleBean
</managed-bean-class>
<managed-bean-scope>request</managed-bean-scope>
</managed-bean>
<navigation-rule>
    <from-view-id>/date.jsp</from-view-id>
<navigation-case>
<from-outcome>show-date</from-outcome>
    <to-view-id>/WEB-INF/results/show-date.jsp</to-view-id>
</navigation-case>
</navigation-rule>

    Result Page
<H2>You selected the following date:<BR>
<h:outputText value="#{sample.date}"/></H2>




                                                              23
24
Tabbed Pane
Description- for switching panels.
Attributes
 • bgColor – the background color of the active tab
 • activeTabStyleClass,inactiveTabStyleClass
t:panelTab contains per tab content. HTML goes within
<f:verbatim>
Shared content is outside t:panelTab but within
t:panelTabbedPane
Everything must be inside h:form
Non tab content goes outside t:panelTabbedPane


                                                        25
Example t:panelTabbedPane

<h:form>
<t:panelTabbedPane bgcolor="#FFFFCC">
   <t:panelTab label="Tab 1">
        <f:verbatim><H1>Tab 1</H1></f:verbatim>
   </t:panelTab>
   <t:panelTab label="Tab 2">
        <f:verbatim><H1>Tab 2</H1></f:verbatim>
   </t:panelTab>
   <t:panelTab label="Tab 3">
        <f:verbatim><H1>Tab 3</H1></f:verbatim>
   </t:panelTab>
   <h:commandButton value="Common Button" action="..."/>
</t:panelTabbedPane>
</h:form>


                                                           26
27
t:inputHTML
Inline HTML based word processor




                                   28
Usage
<t:inputHtml value="String" style="CSSClass"
   fallback="{true|false}" type="Constant"
   allowExternalLinks="{true|false}"
   addKupuLogo="{true|false}"
   showAllToolBoxes="{true|false}"
   allowEditSource="{true|false}"
   showPropertiesToolBox="{true|false}"
   showLinksToolBox="{true|false}"
   showImagesToolBox="{true|false}"
   showTablesToolBox="{true|false}"
   showDebugToolBox="{true|false}"
   showCleanupExpressionsToolBox="{true|false}"/>



                                                    29
JSCookMenu
Renders a nested navigation menu.




                                    30
Popup Component
Renders a popup which displays on a mouse
event.




                                            31
Tomahawk Validators
Widely used validators
 validateRegExpr
 validateEmail

 validateCreditCard

 validateEquals




                         32
validateRegExpr
    Attributes:
        pattern – required
        message - optional
    Example
<TABLE BGCOLOR="WHITE">
<h:form>
    <TR><TD>
       <B>ZIP Code:</B>
       <t:inputText value="#{order.zipCode}“ required="true" id="ZIP">
          <t:validateRegExpr pattern="d{5}"
               message="ZIP Code must be 5 digits"/>
       </t:inputText>
       <TD><h:message for="ZIP" styleClass="red"/></TD>
    </TD></TR>
</h:form>
</TABLE>
                                                                         33
validateEmail
   Attributes: no attributes are required
   Example
<TR><TD>
     <B>Email:</B>
     <t:inputText value="#{order.email}“ required="true" id="email">
         <t:validateEmail
                message="Invalid email address"/>
     </t:inputText>
     <TD><h:message for="email" styleClass="red"/></TD>
</TD></TR>




                                                                       34
validateCreditCard
Attributes: no attributes are required.
   You can specify that only Visa, MasterCard etc
    are acceptable.
Example:
<TR><TD>
      <B>Credit Card:</B>
      <t:inputSecret value="#{order.creditCard}“ required="true" id="card1">
         <t:validateCreditCard
                message="Invalid credit card number"/>
      </t:inputSecret>
      <TD><h:message for="card1" styleClass="red"/></TD>
</TD></TR>


                                                                               35
validateEquals(custom validator for equal inputs)

    Attributes:
      for: Required
      message: Optional
    Example
<t:inputSecret value="#{order.creditCard}“ required="true" id="card1">
      <t:validateCreditCard message="Invalid credit card number"/>
</t:inputSecret>
      <TD><h:message for="card1" styleClass="red"/></TD>
      </TD></TR>
<TR><TD>
      <B>Confirm Credit Card:</B>
      <t:inputSecret required="true" id="card2">
            <t:validateEqual for="card1"
                  message="The two credit card entries do not match"/>
      </t:inputSecret>
<TD><h:message for="card2" styleClass="red"/></TD>


                                                                         36
Advantages of JSF
The big advantage of using JSF is that it
provides reusable components.
It has drag and drop IDE support.
Provides built-in form validation.
Provides set of APIs and associated custom
tags to create HTML forms that have
complex interface.

                                             37
Disadvantages of JSF
Bad Documentation
   Compared to the standard servlet and JSP APIs, JSF
    has fewer online resources, and many first-time users
    find the online JSF documentation confusing and
    poorly organized.
Undeveloped tool support
 There are many IDEs with strong support for standard
servlet and JSP technology. Support for JSF is only
beginning to emerge, and final level is yet to be
determined.

                                                            38
References
http://www.devx.com/Java/Article/28420
http://myfaces.apache.org/tomahawk/
http://java.sun.com/developer/EJTechTips/2004/tt0324.html#2
http://asia.apachecon.com/wp-
content/presentations/ApacheConAsia2006_MyFaces_Tutorial.pdf
http://www.oracle.com/technology/obe/obe1013jdev/10131/jsfintro/jsfintro.ht
m
http://learningjsf.wordpress.com/
http://www.eclipse.org/webtools/jsf/dev_resource/JSFTutorial-
RC3/JSFTools_tutorial.html
http://courses.coreservlets.com/Course-Materials/jsf.html
http://developers.sun.com/prodtech/javatools/jscreator/reference/techart/2/writi
ng_custom_components.html
http://www.javaworld.com/javaworld/jw-07-2006/jw-0731-myfaces.html


                                                                                   39
Questions?




             40

Weitere ähnliche Inhalte

Was ist angesagt?

Design Pattern - MVC, MVP and MVVM
Design Pattern - MVC, MVP and MVVMDesign Pattern - MVC, MVP and MVVM
Design Pattern - MVC, MVP and MVVMMudasir Qazi
 
A Brief Introduction to React.js
A Brief Introduction to React.jsA Brief Introduction to React.js
A Brief Introduction to React.jsDoug Neiner
 
Welcome to Blazor
Welcome to BlazorWelcome to Blazor
Welcome to Blazordark_wisdom
 
Testing with JUnit 5 and Spring
Testing with JUnit 5 and SpringTesting with JUnit 5 and Spring
Testing with JUnit 5 and SpringVMware Tanzu
 
Spring boot
Spring bootSpring boot
Spring bootsdeeg
 
The New JavaScript: ES6
The New JavaScript: ES6The New JavaScript: ES6
The New JavaScript: ES6Rob Eisenberg
 
TP Git avancé DevoxxFR 2018 (exercices)
TP Git avancé DevoxxFR 2018 (exercices)TP Git avancé DevoxxFR 2018 (exercices)
TP Git avancé DevoxxFR 2018 (exercices)Jérôme Tamborini
 
Workshop spring session 2 - La persistance au sein des applications Java
Workshop spring   session 2 - La persistance au sein des applications JavaWorkshop spring   session 2 - La persistance au sein des applications Java
Workshop spring session 2 - La persistance au sein des applications JavaAntoine Rey
 
Introduction à spring boot
Introduction à spring bootIntroduction à spring boot
Introduction à spring bootAntoine Rey
 
Spring boot introduction
Spring boot introductionSpring boot introduction
Spring boot introductionRasheed Waraich
 
What is WebElement in Selenium | Web Elements & Element Locators | Edureka
What is WebElement in Selenium | Web Elements & Element Locators | EdurekaWhat is WebElement in Selenium | Web Elements & Element Locators | Edureka
What is WebElement in Selenium | Web Elements & Element Locators | EdurekaEdureka!
 

Was ist angesagt? (20)

Introduction à Angular
Introduction à AngularIntroduction à Angular
Introduction à Angular
 
Design Pattern - MVC, MVP and MVVM
Design Pattern - MVC, MVP and MVVMDesign Pattern - MVC, MVP and MVVM
Design Pattern - MVC, MVP and MVVM
 
A Brief Introduction to React.js
A Brief Introduction to React.jsA Brief Introduction to React.js
A Brief Introduction to React.js
 
Spring Boot
Spring BootSpring Boot
Spring Boot
 
Welcome to Blazor
Welcome to BlazorWelcome to Blazor
Welcome to Blazor
 
Testing with JUnit 5 and Spring
Testing with JUnit 5 and SpringTesting with JUnit 5 and Spring
Testing with JUnit 5 and Spring
 
Java Spring Framework
Java Spring FrameworkJava Spring Framework
Java Spring Framework
 
Support de Cours JSF2 Première partie Intégration avec Spring
Support de Cours JSF2 Première partie Intégration avec SpringSupport de Cours JSF2 Première partie Intégration avec Spring
Support de Cours JSF2 Première partie Intégration avec Spring
 
Java 11 to 17 : What's new !?
Java 11 to 17 : What's new !?Java 11 to 17 : What's new !?
Java 11 to 17 : What's new !?
 
Spring boot
Spring bootSpring boot
Spring boot
 
Cours design pattern m youssfi partie 5 adapter
Cours design pattern m youssfi partie 5 adapterCours design pattern m youssfi partie 5 adapter
Cours design pattern m youssfi partie 5 adapter
 
The New JavaScript: ES6
The New JavaScript: ES6The New JavaScript: ES6
The New JavaScript: ES6
 
Spring framework core
Spring framework coreSpring framework core
Spring framework core
 
TP Git avancé DevoxxFR 2018 (exercices)
TP Git avancé DevoxxFR 2018 (exercices)TP Git avancé DevoxxFR 2018 (exercices)
TP Git avancé DevoxxFR 2018 (exercices)
 
Workshop spring session 2 - La persistance au sein des applications Java
Workshop spring   session 2 - La persistance au sein des applications JavaWorkshop spring   session 2 - La persistance au sein des applications Java
Workshop spring session 2 - La persistance au sein des applications Java
 
Servlets et JSP
Servlets et JSPServlets et JSP
Servlets et JSP
 
Introduction à spring boot
Introduction à spring bootIntroduction à spring boot
Introduction à spring boot
 
Spring Web MVC
Spring Web MVCSpring Web MVC
Spring Web MVC
 
Spring boot introduction
Spring boot introductionSpring boot introduction
Spring boot introduction
 
What is WebElement in Selenium | Web Elements & Element Locators | Edureka
What is WebElement in Selenium | Web Elements & Element Locators | EdurekaWhat is WebElement in Selenium | Web Elements & Element Locators | Edureka
What is WebElement in Selenium | Web Elements & Element Locators | Edureka
 

Andere mochten auch

PolyTalk Interpreters Network
PolyTalk Interpreters NetworkPolyTalk Interpreters Network
PolyTalk Interpreters Networkltls
 
Logistica mundial
Logistica mundialLogistica mundial
Logistica mundialSonia Godoy
 
Reprise Media Inside Panama
Reprise Media Inside PanamaReprise Media Inside Panama
Reprise Media Inside Panamaweb marketing
 
Cuadro comparativo del antiguo código y el actual
Cuadro comparativo del antiguo código y el actualCuadro comparativo del antiguo código y el actual
Cuadro comparativo del antiguo código y el actualdaiana suligoy
 
Diagnostico organizacional diapositivas
Diagnostico organizacional diapositivasDiagnostico organizacional diapositivas
Diagnostico organizacional diapositivasCelestealvarezatencia
 
Control y Robotica
Control y RoboticaControl y Robotica
Control y RoboticaKoldo Parra
 
Unidad 22 Puert Y Vent[1]
Unidad 22 Puert Y Vent[1]Unidad 22 Puert Y Vent[1]
Unidad 22 Puert Y Vent[1]catedra diez
 
OBSERVACIÓN Y ANÁLISIS BIOMECÁNICO Y ESTADÍSTICO DEL LANZAMIENTO DE TIRO LIBR...
OBSERVACIÓN Y ANÁLISIS BIOMECÁNICO Y ESTADÍSTICO DEL LANZAMIENTO DE TIRO LIBR...OBSERVACIÓN Y ANÁLISIS BIOMECÁNICO Y ESTADÍSTICO DEL LANZAMIENTO DE TIRO LIBR...
OBSERVACIÓN Y ANÁLISIS BIOMECÁNICO Y ESTADÍSTICO DEL LANZAMIENTO DE TIRO LIBR...Otilio Valencia
 

Andere mochten auch (14)

Rasta 1
Rasta 1Rasta 1
Rasta 1
 
PolyTalk Interpreters Network
PolyTalk Interpreters NetworkPolyTalk Interpreters Network
PolyTalk Interpreters Network
 
Logistica mundial
Logistica mundialLogistica mundial
Logistica mundial
 
Reprise Media Inside Panama
Reprise Media Inside PanamaReprise Media Inside Panama
Reprise Media Inside Panama
 
Cuadro comparativo del antiguo código y el actual
Cuadro comparativo del antiguo código y el actualCuadro comparativo del antiguo código y el actual
Cuadro comparativo del antiguo código y el actual
 
Fase 2
Fase 2Fase 2
Fase 2
 
Cara fax
Cara faxCara fax
Cara fax
 
Herramientas de-diagnostico-y-monitoreo
Herramientas de-diagnostico-y-monitoreoHerramientas de-diagnostico-y-monitoreo
Herramientas de-diagnostico-y-monitoreo
 
Diagnostico organizacional diapositivas
Diagnostico organizacional diapositivasDiagnostico organizacional diapositivas
Diagnostico organizacional diapositivas
 
LUX
LUXLUX
LUX
 
Control y Robotica
Control y RoboticaControl y Robotica
Control y Robotica
 
Unidad 22 Puert Y Vent[1]
Unidad 22 Puert Y Vent[1]Unidad 22 Puert Y Vent[1]
Unidad 22 Puert Y Vent[1]
 
Sommergluecksmomente 2015 Italien
Sommergluecksmomente 2015 ItalienSommergluecksmomente 2015 Italien
Sommergluecksmomente 2015 Italien
 
OBSERVACIÓN Y ANÁLISIS BIOMECÁNICO Y ESTADÍSTICO DEL LANZAMIENTO DE TIRO LIBR...
OBSERVACIÓN Y ANÁLISIS BIOMECÁNICO Y ESTADÍSTICO DEL LANZAMIENTO DE TIRO LIBR...OBSERVACIÓN Y ANÁLISIS BIOMECÁNICO Y ESTADÍSTICO DEL LANZAMIENTO DE TIRO LIBR...
OBSERVACIÓN Y ANÁLISIS BIOMECÁNICO Y ESTADÍSTICO DEL LANZAMIENTO DE TIRO LIBR...
 

Ähnlich wie Jsf

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 2011Arun Gupta
 
Spark IT 2011 - Simplified Web Development using Java Server Faces 2.0
Spark IT 2011 - Simplified Web Development using Java Server Faces 2.0Spark IT 2011 - Simplified Web Development using Java Server Faces 2.0
Spark IT 2011 - Simplified Web Development using Java Server Faces 2.0Arun Gupta
 
Hyperproductive JSF 2.0 @ JavaOne Brazil 2010
Hyperproductive JSF 2.0 @ JavaOne Brazil 2010Hyperproductive JSF 2.0 @ JavaOne Brazil 2010
Hyperproductive JSF 2.0 @ JavaOne Brazil 2010Arun Gupta
 
Ajax, JSF, Facelets, Eclipse & Maven tutorials
Ajax, JSF, Facelets, Eclipse & Maven tutorialsAjax, JSF, Facelets, Eclipse & Maven tutorials
Ajax, JSF, Facelets, Eclipse & Maven tutorialsRaghavan Mohan
 
Java Web Development with Stripes
Java Web Development with StripesJava Web Development with Stripes
Java Web Development with StripesSamuel Santos
 
Step By Step Guide For Buidling Simple Struts App
Step By Step Guide For Buidling Simple Struts AppStep By Step Guide For Buidling Simple Struts App
Step By Step Guide For Buidling Simple Struts AppSyed Shahul
 
AnkaraJUG Kasım 2012 - PrimeFaces
AnkaraJUG Kasım 2012 - PrimeFacesAnkaraJUG Kasım 2012 - PrimeFaces
AnkaraJUG Kasım 2012 - PrimeFacesAnkara JUG
 
In The Brain of Cagatay Civici: Exploring JavaServer Faces 2.0 and PrimeFaces
In The Brain of Cagatay Civici: Exploring JavaServer Faces 2.0 and PrimeFaces In The Brain of Cagatay Civici: Exploring JavaServer Faces 2.0 and PrimeFaces
In The Brain of Cagatay Civici: Exploring JavaServer Faces 2.0 and PrimeFaces Skills Matter
 
How to disassemble one monster app into an ecosystem of 30
How to disassemble one monster app into an ecosystem of 30How to disassemble one monster app into an ecosystem of 30
How to disassemble one monster app into an ecosystem of 30fiyuer
 
#31.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)_스프링프레임워크 강좌, 재직자환급교육,실업자국비지원...
#31.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)_스프링프레임워크 강좌, 재직자환급교육,실업자국비지원...#31.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)_스프링프레임워크 강좌, 재직자환급교육,실업자국비지원...
#31.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)_스프링프레임워크 강좌, 재직자환급교육,실업자국비지원...탑크리에듀(구로디지털단지역3번출구 2분거리)
 
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 2010Arun Gupta
 
Overview of The Scala Based Lift Web Framework
Overview of The Scala Based Lift Web FrameworkOverview of The Scala Based Lift Web Framework
Overview of The Scala Based Lift Web FrameworkIndicThreads
 
Scala based Lift Framework
Scala based Lift FrameworkScala based Lift Framework
Scala based Lift Frameworkvhazrati
 
Rich Portlet Development in uPortal
Rich Portlet Development in uPortalRich Portlet Development in uPortal
Rich Portlet Development in uPortalJennifer Bourey
 
Javascript ui for rest services
Javascript ui for rest servicesJavascript ui for rest services
Javascript ui for rest servicesIoan Eugen Stan
 

Ähnlich wie Jsf (20)

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
 
Spark IT 2011 - Simplified Web Development using Java Server Faces 2.0
Spark IT 2011 - Simplified Web Development using Java Server Faces 2.0Spark IT 2011 - Simplified Web Development using Java Server Faces 2.0
Spark IT 2011 - Simplified Web Development using Java Server Faces 2.0
 
The Rails Way
The Rails WayThe Rails Way
The Rails Way
 
Hyperproductive JSF 2.0 @ JavaOne Brazil 2010
Hyperproductive JSF 2.0 @ JavaOne Brazil 2010Hyperproductive JSF 2.0 @ JavaOne Brazil 2010
Hyperproductive JSF 2.0 @ JavaOne Brazil 2010
 
Ajax, JSF, Facelets, Eclipse & Maven tutorials
Ajax, JSF, Facelets, Eclipse & Maven tutorialsAjax, JSF, Facelets, Eclipse & Maven tutorials
Ajax, JSF, Facelets, Eclipse & Maven tutorials
 
Java Web Development with Stripes
Java Web Development with StripesJava Web Development with Stripes
Java Web Development with Stripes
 
JSF 2.0 Preview
JSF 2.0 PreviewJSF 2.0 Preview
JSF 2.0 Preview
 
Step By Step Guide For Buidling Simple Struts App
Step By Step Guide For Buidling Simple Struts AppStep By Step Guide For Buidling Simple Struts App
Step By Step Guide For Buidling Simple Struts App
 
AnkaraJUG Kasım 2012 - PrimeFaces
AnkaraJUG Kasım 2012 - PrimeFacesAnkaraJUG Kasım 2012 - PrimeFaces
AnkaraJUG Kasım 2012 - PrimeFaces
 
Unit 07: Design Patterns and Frameworks (3/3)
Unit 07: Design Patterns and Frameworks (3/3)Unit 07: Design Patterns and Frameworks (3/3)
Unit 07: Design Patterns and Frameworks (3/3)
 
In The Brain of Cagatay Civici: Exploring JavaServer Faces 2.0 and PrimeFaces
In The Brain of Cagatay Civici: Exploring JavaServer Faces 2.0 and PrimeFaces In The Brain of Cagatay Civici: Exploring JavaServer Faces 2.0 and PrimeFaces
In The Brain of Cagatay Civici: Exploring JavaServer Faces 2.0 and PrimeFaces
 
Jsf2.0 -4
Jsf2.0 -4Jsf2.0 -4
Jsf2.0 -4
 
How to disassemble one monster app into an ecosystem of 30
How to disassemble one monster app into an ecosystem of 30How to disassemble one monster app into an ecosystem of 30
How to disassemble one monster app into an ecosystem of 30
 
#31.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)_스프링프레임워크 강좌, 재직자환급교육,실업자국비지원...
#31.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)_스프링프레임워크 강좌, 재직자환급교육,실업자국비지원...#31.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)_스프링프레임워크 강좌, 재직자환급교육,실업자국비지원...
#31.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)_스프링프레임워크 강좌, 재직자환급교육,실업자국비지원...
 
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
 
Overview Of Lift Framework
Overview Of Lift FrameworkOverview Of Lift Framework
Overview Of Lift Framework
 
Overview of The Scala Based Lift Web Framework
Overview of The Scala Based Lift Web FrameworkOverview of The Scala Based Lift Web Framework
Overview of The Scala Based Lift Web Framework
 
Scala based Lift Framework
Scala based Lift FrameworkScala based Lift Framework
Scala based Lift Framework
 
Rich Portlet Development in uPortal
Rich Portlet Development in uPortalRich Portlet Development in uPortal
Rich Portlet Development in uPortal
 
Javascript ui for rest services
Javascript ui for rest servicesJavascript ui for rest services
Javascript ui for rest services
 

Kürzlich hochgeladen

What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxBkGupta21
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionDilum Bandara
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfMounikaPolabathina
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
What is Artificial Intelligence?????????
What is Artificial Intelligence?????????What is Artificial Intelligence?????????
What is Artificial Intelligence?????????blackmambaettijean
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embeddingZilliz
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsNathaniel Shimoni
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 

Kürzlich hochgeladen (20)

What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptx
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An Introduction
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdf
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
What is Artificial Intelligence?????????
What is Artificial Intelligence?????????What is Artificial Intelligence?????????
What is Artificial Intelligence?????????
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embedding
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directions
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 

Jsf

  • 1. Introduction to JavaServerFaces & MyFaces Anudeep Jassal 1
  • 2. Topics of Discussion What is JSF? JSF Architecture. How does JSF work. What is MyFaces? 2
  • 3. What is Java Server Faces?  JSF is a new and upcoming web application framework that accomplishes the MVC paradigm It is similar to Struts but has features and concepts that are beyond those of Struts - especially the component orientation.  Provides set of reusable custom components.  Provides set of JSP tags to access those components. 3
  • 4. JSF Architecture  JSF follows MVC framework  Model: objects and properties of application  View: Renderers take care of view.  Controller: FacesServlet/ JSF infrastructure defines the flow of the application. 4
  • 5. How JSF works A form is displayed  Form uses <f:view> and <h:form> The form is submitted to itself. The bean is instantiated. Listed in the managed-bean section of faces-config.xml The action controller method is invoked. The action method returns a condition. The result page is displayed. 5
  • 8. Example files index.jsp,welcome.jsp – define the login and welcome screens. UserBean.java – manages user data faces-config.xml – configuration file for the application. web.xml – deployment descriptor. 8
  • 9. JSF Example(index.jsp) <%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %> <%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %> <f:loadBundle basename=“com.corejsf.bundle.Messages" var="Message"/> <f:view> … <h:form> <h3><h:outputText value="#{Message.inputname_header}"/></h3> <table> <tr> <td>Name:</td> <h:inputText value="#{user.name}“ required=“true”/> <f:validateLength minimum="2" maximum="20"/> … <td>Password:</td> <h:inputSecret value="#{user.password}"/> … <h:commandButton value="Login" action="login"/> </h:form> </f:view> 9
  • 10. index.jsp Tag Libraries: core and html. <%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %> <%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %> Core tags are used to perform core actions and display nothing to the user. Html tags are used to render html elements(text, form elements etc) to the user. <f:loadBundle> is a core tag. Loads properties file and makes it value available to variable message. <f:loadBundle basename=“com.corejsf..bundle.Messages" var="Message"/> All JSF components must be nested inside <f:view> core tag. <f:view> <h:form> <h3><h:outputText value="#{Message.inputname_header}"/></h3> <h:inputText value="#{user.name}“ required=“true”/> <f:validateLength minimum="2" maximum="20"/> <h:inputSecret value="#{user.password}"/> <h:commandButton value="Login" action="login"/> </h:form> </f:view> 10
  • 11. Example (Cntd.) Any attribute value that starts with # and is wrapped in {} is dynamically substituted in #{Message.inputname_header} <h:form> represents form element Form action is defined in the <h:commandButton> element. <h:commandButton value="Login" action="login"/> <h:inputText> for name field renders a textbox. Required attribute tells the value must be provided by the user. Thus validating the field. <h:inputText value="#{user.userName}" required="true"> Nested core tag provides range validation. <f:validateLength minimum="2" maximum="20"/> 11
  • 12. UserBean.java public class UserBean { public String getName() { . . . } public void setName(String newValue) {. . . } public String getPassword() { . . . } public void setPassword(String newValue) { . . . } ... } 12
  • 13. Configuration file (faces-config.xml) <?xml version="1.0"?> <!DOCTYPE faces-config PUBLIC "-//Sun Microsystems, Inc.//DTD JavaServer Faces Config 1.0//EN" "http://java.sun.com/dtd/web-facesconfig_1_0.dtd"> <faces-config> <navigation-rule> <from-view-id>/index.jsp</from-view-id> <navigation-case> <from-outcome>login</from-outcome> <to-view-id>/welcome.jsp</to-view-id> </ navigation-case> </navigation-rule> <managed-bean> <managed-bean-name>user</managed-bean-name> <managed-bean-class>com.corejsf.UserBean</managed-bean-class> <managed-bean-scope>session</managed-bean-scope> </managed-bean> </faces-config> 13
  • 14. Configuration File(Cntd.) faces-config.xml defines how one page will navigate to next. Also specifies managed beans. <navigation-rule> <from-view-id>/index.jsp</from-view-id> <navigation-case> <from-outcome>login</from-outcome> <to-view-id>/welcome.jsp</to-view-id> </navigation-case> </navigation-rule <from-view-id> page you are currently on. <to-view-id> next page to display. <from-outcome> value matches the action attribute of the command button of index.jsp <h:commandButton value="Login" action="login"/> 14
  • 15. Configuration file (Cntd.) Managed bean is the model of the framework. <managed-bean-name> is the name the views use to reference the bean.<managed-bean-name>user</managed-bean-name> <h:inputText value="#{user.name}“ required=“true”/> <managed-bean-class> is the fully classified name for the bean. <managed-bean-class> com.corejsf.UserBean </managed-bean-class> <managed-bean-scope>session</managed-bean-scope> 15
  • 16. Web.xml (Deployment Descriptor) <context-param> <param-name> javax.faces.CONFIG_FILES</param-name> <param-value> /WEB-INF/faces-config.xml </param-value> <description> </description> </context-param> <servlet> <servlet-name>Faces Servlet</servlet-name> <servlet-class> javax.faces.webapp.FacesServlet </servlet-class> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>Faces Servlet</servlet-name> <url-pattern *.faces </url-pattern> </servlet-mapping> 16
  • 17. Web.xml (Cntd.) Javax.faces.CONFIG_FILES parameter tells where the JSF configuration file exists. <param-name> javax.faces.CONFIG_FILES </param-name> <param-value> /WEB-INF/examples-config.xml </param-value> Javax.faces.STATE_SAVING_METHOD specifies where the state must be saved: client or server. <param-name> javax.faces.STATE_SAVING_METHOD </param-name> <param-value>server</param-value> The servlet-mapping and servlet blocks specify that any URL that ends in a .jsf extension should be redirected through a servlet called javax.faces.webapp.FacesServlet. 17
  • 18. What is Apache MyFaces? First free open source implementation of JSF. Provides rich set of prefabricated components. 18
  • 19. MyFaces Component Libraries Tomahawk • Original MyFaces component library. Tobago • Apache Library now under MyFaces umbrella. Trinidad • Originally Oracle ADF components. 19
  • 20. Using MyFaces Tomahawk Components Add jar files to WEB-INF/lib • Tomahawk.jar • Commons-fileupload.jar • Commons-validator.jar • Oro-xxx-jar Import the extended tag library <%@ taglib uri=http://myfaces.apache.org/tomahawk prefix="t"%> Enable extensions filter • Add a filter and two filter mappings in web.xml - Delivers JavaScript code and style sheets. Components which use JavaScript will fail without these entries in web.xml 20
  • 21. Date Component Input Text control for dates. Attributes • Value – the Date value. • Type – Defines the content type. Date,time or both • popupCalendar - If true, button added that pops up JavaScript calendar for input. Default is false 21
  • 22. t:inputDate example Main JSP page <h:form> Date: <t:inputDate value=“#{sample.date}” popupCalendar="true"/><BR> <h:commandButton action="show-date"/> </h:form> Bean package coreservlets import java.util.*; public class SampleBean { private Date date; public Date getDate() { return(date); } public void setDate(Date date) { this.date = date; } 22
  • 23. Example (Cntd.) faces-config.xml <managed-bean> <managed-bean-name>sample</managed-bean-name> <managed-bean-class> coreservlets.SampleBean </managed-bean-class> <managed-bean-scope>request</managed-bean-scope> </managed-bean> <navigation-rule> <from-view-id>/date.jsp</from-view-id> <navigation-case> <from-outcome>show-date</from-outcome> <to-view-id>/WEB-INF/results/show-date.jsp</to-view-id> </navigation-case> </navigation-rule> Result Page <H2>You selected the following date:<BR> <h:outputText value="#{sample.date}"/></H2> 23
  • 24. 24
  • 25. Tabbed Pane Description- for switching panels. Attributes • bgColor – the background color of the active tab • activeTabStyleClass,inactiveTabStyleClass t:panelTab contains per tab content. HTML goes within <f:verbatim> Shared content is outside t:panelTab but within t:panelTabbedPane Everything must be inside h:form Non tab content goes outside t:panelTabbedPane 25
  • 26. Example t:panelTabbedPane <h:form> <t:panelTabbedPane bgcolor="#FFFFCC"> <t:panelTab label="Tab 1"> <f:verbatim><H1>Tab 1</H1></f:verbatim> </t:panelTab> <t:panelTab label="Tab 2"> <f:verbatim><H1>Tab 2</H1></f:verbatim> </t:panelTab> <t:panelTab label="Tab 3"> <f:verbatim><H1>Tab 3</H1></f:verbatim> </t:panelTab> <h:commandButton value="Common Button" action="..."/> </t:panelTabbedPane> </h:form> 26
  • 27. 27
  • 28. t:inputHTML Inline HTML based word processor 28
  • 29. Usage <t:inputHtml value="String" style="CSSClass" fallback="{true|false}" type="Constant" allowExternalLinks="{true|false}" addKupuLogo="{true|false}" showAllToolBoxes="{true|false}" allowEditSource="{true|false}" showPropertiesToolBox="{true|false}" showLinksToolBox="{true|false}" showImagesToolBox="{true|false}" showTablesToolBox="{true|false}" showDebugToolBox="{true|false}" showCleanupExpressionsToolBox="{true|false}"/> 29
  • 30. JSCookMenu Renders a nested navigation menu. 30
  • 31. Popup Component Renders a popup which displays on a mouse event. 31
  • 32. Tomahawk Validators Widely used validators  validateRegExpr  validateEmail  validateCreditCard  validateEquals 32
  • 33. validateRegExpr Attributes:  pattern – required  message - optional Example <TABLE BGCOLOR="WHITE"> <h:form> <TR><TD> <B>ZIP Code:</B> <t:inputText value="#{order.zipCode}“ required="true" id="ZIP"> <t:validateRegExpr pattern="d{5}" message="ZIP Code must be 5 digits"/> </t:inputText> <TD><h:message for="ZIP" styleClass="red"/></TD> </TD></TR> </h:form> </TABLE> 33
  • 34. validateEmail Attributes: no attributes are required Example <TR><TD> <B>Email:</B> <t:inputText value="#{order.email}“ required="true" id="email"> <t:validateEmail message="Invalid email address"/> </t:inputText> <TD><h:message for="email" styleClass="red"/></TD> </TD></TR> 34
  • 35. validateCreditCard Attributes: no attributes are required.  You can specify that only Visa, MasterCard etc are acceptable. Example: <TR><TD> <B>Credit Card:</B> <t:inputSecret value="#{order.creditCard}“ required="true" id="card1"> <t:validateCreditCard message="Invalid credit card number"/> </t:inputSecret> <TD><h:message for="card1" styleClass="red"/></TD> </TD></TR> 35
  • 36. validateEquals(custom validator for equal inputs) Attributes:  for: Required  message: Optional Example <t:inputSecret value="#{order.creditCard}“ required="true" id="card1"> <t:validateCreditCard message="Invalid credit card number"/> </t:inputSecret> <TD><h:message for="card1" styleClass="red"/></TD> </TD></TR> <TR><TD> <B>Confirm Credit Card:</B> <t:inputSecret required="true" id="card2"> <t:validateEqual for="card1" message="The two credit card entries do not match"/> </t:inputSecret> <TD><h:message for="card2" styleClass="red"/></TD> 36
  • 37. Advantages of JSF The big advantage of using JSF is that it provides reusable components. It has drag and drop IDE support. Provides built-in form validation. Provides set of APIs and associated custom tags to create HTML forms that have complex interface. 37
  • 38. Disadvantages of JSF Bad Documentation  Compared to the standard servlet and JSP APIs, JSF has fewer online resources, and many first-time users find the online JSF documentation confusing and poorly organized. Undeveloped tool support  There are many IDEs with strong support for standard servlet and JSP technology. Support for JSF is only beginning to emerge, and final level is yet to be determined. 38