• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Java Server Faces 1.2 presented (2007)
 

Java Server Faces 1.2 presented (2007)

on

  • 926 views

An overview on JSF 1.2 from 2007.

An overview on JSF 1.2 from 2007.

Statistics

Views

Total Views
926
Views on SlideShare
926
Embed Views
0

Actions

Likes
2
Downloads
0
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as OpenOffice

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    Java Server Faces 1.2 presented (2007) Java Server Faces 1.2 presented (2007) Presentation Transcript

    • JavaServer Faces 1.2 Peter Antman, CTO, 2007 Mogul
    • Java Server Faces
      • JSF
      • A specification , several implementations
      • A user interface (UI) framework for Java Web applications
      • Designed much like a “fat” UI framework such as Swing and SWT
      • First RI released 2002
      • 1.0 specification released March 2004, not part of J2EE
      • 1.2 spec released spring 2006
      • 1.2 is part of J2EE 1.5
      • Is taking of (maybe)
    • New in JSF 1.2
      • JSF and JSF now shares expression language
      • Missmatch with JSP fixed (new JSP ViewHandler and tag base class)
      • Works with JSTL forEach
      • Multiple windows and back-button problems fixed
    • Implementations and add-ons
      • Major implementations
        • SUN RI (1.2)
        • MyFaces (1.0)
      • Component libraries
        • Tomahawk
        • Tobago
      • Ajax support
        • Ajax4jsf
        • Dynamic Faces
      • JSP alternatives
        • Facelets
    • Core design
      • Build on Model-View-Controller (MVC) pattern
      • Component based
        • standard GUI components (connects view and model)
        • Loose coupling to models through value- and method-binding technology
      • Lifecycle managed
        • Clearly defined cycle for request/response handling
      • Event driven
        • a request triggers event handlers that update models
      • Built in navigation model
      • Not tied to any specific view technology
      • By design geared at server side execution
    • Building blocks <f:view> <h:form> <h:outputText value=&quot;#{test2.value}&quot; <h:inputText value=&quot;#{test2.value}&quot; <h:commandButton action=&quot;#{test2.valueUpdated}&quot; </h:form> Submit UIForm <navigation-rule> <navigation-case> <from-outcome>login <to-view-id>/login.jsp Browser JSP Component Tree <faces-config> faces-config Request Response value binding method binding 1. Restore View 2. Apply Request Values 3. Process Validation 4. Update Model Values 5. Invoke Application 6. Render Response UIViewRoot UIOutput UIInput Converter Validator ActionEvent getValue() setValue() valueUpdated() UICommand <managed-bean> <managed-bean-name>test2 <managed-bean-class>Test2 <managed-bean-scope>session RenderKit Navigation Handler Faces Servlet
    • Configure web application in web.xml
      • Where should state be saved
      <context-param> <param-name>javax.faces.STATE_SAVING_METHOD</param-name> <param-value>client</param-value> </context-param>
      • Add FacesServlet
      <servlet> <servlet-name>Faces Servlet</servlet-name> <servlet-class>javax.faces.webapp.FacesServlet</servlet-class> <load-on-startup>1</load-on-startup> </servlet>
      • Configure mapping
      <servlet-mapping> <servlet-name>Faces Servlet</servlet-name> <url-pattern>/faces/*</url-pattern> </servlet-mapping >
    • View - JSP
      • Add taglibs
      <%@ taglib uri=&quot;http://java.sun.com/jsf/core&quot; prefix=&quot;f&quot; %> <%@ taglib uri=&quot;http://java.sun.com/jsf/html&quot; prefix=&quot;h&quot;%>
      • Start with <f:view>
      <f:view>
      • Build page with HTML, JSTL and JSF components
      <h:form> <h:outputText value=&quot;#{test2.value}&quot;/> <h:inputText value=&quot;#{test2.value}&quot; id=&quot;name&quot;/> <h:commandButton action=&quot;#{test2.valueUpdated}&quot; value=&quot;Submit&quot;/> </h:form>
    • Validation - builtin
      • Use builtin validators
      • Ad an id to enclosing element
      • Nest validator
      • Use a message for the element where any errors will appear
      <h:inputText id=&quot;in&quot; value=&quot;#{test2.value}&quot;> <f:validateLength minimum=&quot;2&quot; maximum=&quot;4&quot;/> </h:inputText> <h:message for=&quot;in&quot; />
    • Validator - custom
      • Implement Validator
      public void validate(FacesContext, UIComponent comp, Object value)
      • Add to faces-config
      • Use generic method
      <f:validator validatorId=”my.validator.MYID”/> <f:attribute name=”myValidatorConf” value=”SomeValue”/>
      • Or develop a custom tag
      • Also possible to do ones own Converters
    • JSF – Core JSP tags
        • f:actionListener
        • f:attribute
        • f:convertDateTime
        • f:converter
        • f:convertNumber
        • f:facet
        • f:loadBundle
        • f:param
        • f:selectItem
        • f:selectItems
        • f:subview
        • f:validateDoubleRange
        • f:validateLength
        • f:validateLongRange
        • f:validator
        • f:valueChangeListener
        • f:verbatim
        • f:view
    • JSF – HTML JSP tags
        • h:column
        • h:commandButton
        • h:commandLink
        • h:dataTable
        • h:form
        • h:graphicImage
        • h:inputHidden
        • h:inputSecret
        • h:inputText
        • h:inputTextarea
        • h:message
        • h:messages
        • h:outputFormat
        • h:outputLabel
        • h:outputLink
        • h:outputText
        • h:panelGrid
        • h:panelGroup
        • h:selectBooleanCheckbox
        • h:selectManyCheckbox
        • h:selectManyListbox
        • h:selectManyMenu
        • h:selectOneListbox
        • h:selectOneMenu
        • h:selectOneRadio
    • Managed Beans
      • POJOS
      • Must be defined in faces-config
      • Used through value- and method bindings
      • Created by container
      • In- and outjection through EL
      • Inter bean references through EL
      • May use J2EE annotations for life cycle callback, resource and EJB reference injection
      • Not yet any annotations to skip faces-config
    • Managed Beans – WebWork style
      • Same class handles values and action
      public void setValue(String v) { this.v = v; } public String getValue() { return v; } public String valueUpdated() { return &quot;sucess&quot;; }
      • Just define it by name in faces-config and scope its available in
      </managed-bean> <managed-bean> <managed-bean-name>test2</managed-bean-name> <managed-bean-class>Test2</managed-bean-class> <managed-bean-scope>request</managed-bean-scope> </managed-bean>
    • Managed Beans – Struts style
      • Entity bean and Business logic separate
      <managed-bean> <managed-bean-name> valueBean </managed-bean-name> <managed-bean-class>Value</managed-bean-class> <managed-bean-scope>none</managed-bean-scope>
      • Used by action target
      <managed-bean> <managed-bean-name>test3</managed-bean-name> <managed-bean-class>enterprise.jsf_jpa_war.Test3</managed-bean-class> <managed-bean-scope>request</managed-bean-scope> <managed-property> <property-name>value</property-name> <value> #{valueBean} </value> </managed-property>
      • JSP
      <h:outputText value=&quot;#{ valueBean.value }&quot;/> <h:commandButton action=&quot;#{ test3.valueUpdated }&quot; value=&quot;Submit&quot;/>
    • Bindings
      • Bind a value (set or get)
      <h:outputText value=&quot; #{test2.value} &quot;/> <h:inputText id=&quot;in&quot; value=&quot; #{test2.value} &quot;>
      • Bind an ActionEvent
      <h:commandButton action=&quot; #{test2.valueUpdated} &quot; value=&quot;Submit&quot;/>
      • Binding in faces-config
      <value> #{valueBean} </value>
    • Using JEE 5 Annotations
      • When running in a Java EE 5 container one may use annotations in managed beans to:
        • Inject resources and EJB references
        • Declare life cycle callbacks
      • May be used both at attribute and method level
      public MyClass { private @EJB myEjb; private DataSource ds; @Resource (name=dataSource) public void setDataSource(DataSource ds) {} @PostConstruc t public void init() {} @PreDestroy public void destroy() {} }
    • Navigation
      • Navigation may be done declaratively or programmatically
      • Declaratively by declaring navigation rules
        • in faces-config
      <navigation-rule> <from-view-id>/test3.jsp</from-view-id> optional/wildcard <navigation-case> <from-action>#{test3.valueUpdated}</from-action> optional <from-outcome>error</from-outcome> <to-view-id>/test2.jsp</to-view-id> <redirect/> optional/clean state
        • and returning strings from actions
      public String valueUpdated() { if (//Some error) return &quot;error&quot;; else return &quot;sucess&quot;;
      • Programmatically by creating new views with the ViewHandler
    • Localization
      • Internationalization support built in
      • A ViewRoot holds a locale
      UIViewRoot.getLocale()
      • Which locale in use are governed by a combination of
        • Browser header Accept-Language
        • The supported locales configured
        • A programatically set locale
      • Use a ResourceBundle to localized messages
      • Use converters such as DateTimeConverter to handle localized input
    • Localization, cont
      • Configure available locales in faces-config.xml
      <application> <locale-config> <default-locale>en</default-locale> <supported-locale>sv</supported-locale> </locale-config> </application>
      • Create resource bundles and make them available in web app classpath (WEB-INF/classes)
        • create one bundle for each locale, ie myBundle_en, myBundle_sv
        • According to doc a “default” bundle should be possible to use, i.e myBundle.properties. That is not my experience. A default en locale but a swedish one available gives the following:
      curl -v -H &quot;Accept-Language:fr&quot; < Content-Language: en Meddelande 1 <input (from myBundle_sv)
    • Localization, cont 2
      • Use <f:loadBundle> in JSP pages to get access to localized messages
        • specify bundle name
        • specify a variable to make bunde available in as a Map
        • don't use “.” notation for properties/key (conflicts with EL)
      <f:view> <f:loadBundle basename=&quot; com.mypack.mytestres &quot; var=&quot; msg &quot;/> <h:form> <h:outputText value=&quot; #{msg.myKey1} &quot;/>
      • Or access locale and bundle programatically
      Locale locale = context.getViewRoot().getLocale() ResourceBundle rb = ResourceBundle(“com.mypack.mytestres”, locale);
      • A locale may also be “overridden” in a page by setting the locale of the RootView:
      <f.view locale=”#{profile.locale}”>
    • Ajax
      • ajax4jsf
      • https://ajax4jsf.dev.java.net/nonav/ajax/ajax-jsf/
      • Extension to JSF that adds Ajax support
      • implemented using a component library that adds AJAX capability to existing pages without writing any JavaScript code
      • Define events that will be invoked “ajax”-style
      • Define JSF component that are target of event (repaint)
    • Ajax - installation
      • Add the following to web.xml:
      <filter> <display-name>Ajax4jsf Filter</display-name> <filter-name>ajax4jsf</filter-name> <filter-class>org.ajax4jsf.Filter</filter-class> </filter> <filter-mapping> <filter-name>ajax4jsf</filter-name> <servlet-name>Faces Servlet</servlet-name> <dispatcher>REQUEST</dispatcher> <dispatcher>FORWARD</dispatcher> <dispatcher>INCLUDE</dispatcher> </filter-mapping>
      • Add the following jars to WEB-INF/lib
        • ajax4jsf
        • oscache-2.3.2
        • commons-logging-1.1
        • commons-collection-3.2
        • commons-digester-1.8
        • commons-beanutils-1.7.0
    • Ajaxifyed JSF page <%@page contentType=&quot;text/html&quot;%> <%@page pageEncoding=&quot;UTF-8&quot;%> <%@ taglib uri=&quot;https://ajax4jsf.dev.java.net/ajax&quot; prefix=&quot;a4j&quot;%> <%@ taglib uri=&quot;http://java.sun.com/jsf/core&quot; prefix=&quot;f&quot; %> <%@ taglib uri=&quot;http://java.sun.com/jsf/html&quot; prefix=&quot;h&quot;%> <!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.01 Transitional//EN&quot; &quot;http://www.w3.org/TR/html4/loose.dtd&quot;> <f:view> <h:form> <h:outputText id=&quot;out&quot; value=&quot;#{test2.value}&quot;/> <h:inputText id=&quot;in&quot; value=&quot;#{test2.value}&quot;> <a4j:support event=&quot;onkeyup&quot; reRender=&quot;out&quot; /> </h:inputText> <h:message for=&quot;in&quot;/> </h:form> </f:view>
    • Ajax webpage
    • Facelets
      • https://facelets.dev.java.net/
      • Facelets, an alternative to JSP
      • May use JSF 1.2 in a non JSP 2.1 container
      • Pure XML
      • Compiles XML to a JSF tree
      • Easier Tag handlers
      • May use EL such as #{myBean.value} almost anywhere
      • Work well with HTML design (xhtml)
        • view directly in browser
        • alias tags (<input type=&quot;text&quot; jsfc=&quot;h:inputText&quot; value=&quot;#{hello.world}&quot; />)
      • Several types of support for templating
        • ui:composition, ui:define and ui:param
        • ui:insert and ui:include
        • xml taglibs
      • NetBeans and Facelets: https://nbfaceletssupport.dev.java.net/
    • Facelets template <!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot; &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot;> <html xmlns=&quot;http://www.w3.org/1999/xhtml&quot; xmlns:ui=&quot;http://java.sun.com/jsf/facelets &quot;> <head> <meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=iso-8859-1&quot; /> <title>Demo</title> <style type=&quot;text/css&quot;> body { font-family: Verdana, Arial, Helvetica, sans-serif; font-size: small; } </style> </head> <body> <h1> < ui:insert name=&quot;title&quot; >Default Title</ui:insert> </h1> <p> < ui:insert name=&quot;body&quot; >Default Body</ui:insert> </p> </body> </html>
    • Facelets example <!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot; &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot;> <html xmlns=&quot;http://www.w3.org/1999/xhtml&quot; xmlns:ui=&quot;http://java.sun.com/jsf/facelets &quot; xmlns:h=&quot;http://java.sun.com/jsf/html &quot;> <body> < ui:composition template=&quot;/template.xhtml &quot;> <ui:define name=&quot;title&quot;> Message: #{myBean.value} </ui:define> <ui:define name=&quot;body&quot;> <h:form id=&quot;helloForm&quot;> <h:inputText type=&quot;text&quot; id=&quot;userNo&quot; value=&quot;#{myBean.value}&quot;/> <br/> <h:commandButton type=&quot;submit&quot; id=&quot;submit&quot; action=&quot;success&quot; value=&quot;Submit&quot; /> <br/> <h:message showSummary=&quot;true&quot; showDetail=&quot;false&quot; style=&quot;color: red; font-weight: bold;&quot; id=&quot;errors1&quot; for=&quot;userNo&quot;/> </h:form> </ui:define> </ui:composition> </body> </html>
    • Much more possible to do
      • Internationalization
      • Add your own ActionListener
      • Work with ValueChangeListeners
      • Use the PhaseListener API
      • Write your own UI components
      • Create new RenderKit
    • Resources
      • http://java.sun.com/javaee/javaserverfaces/
      • http://www.exadel.com/tutorial/jsf/jsftags-guide.html
      • http://myfaces.apache.org
      • http://www.theserverside.com/news/thread.tss?thread_id=33326
    • Stuff to think about
      • * What is JSF?
      • * How does it work (life cycle, managed beans, ...)?
      • * Where is the connection between JSP and JSF?
      • * How does JSF compare to eg Struts or Shale?
      • * What are Facelets and why does it make sense to use it?
      • * What tool support exists for JSF?
      • * How to test/debug JSF?
      • * JSF and Ajax
      • Seam
      • * Seam experiences
      • * Why the buzz
      • Design
      • * Designing EJB 3/J2EE applications
      • Tool
      • * Maven 2 vs Ant
    • Stuff to think about (cont)
      • Testing
      • * Test roundripp timing
      • * Cactus vs Embedded
      • * Tool support
      • * POJO
      • * Persistence (DBUnit)'
      • * Integrations tests
      • * GUI testing
      • Production
      • * JBoss4/JBoss5 problems
      • * MyFacec/Faces RI
      • * Support for J2EE 1.5
    • mogul .slut på presentation Kontakt: [email_address]