Advanced Jsf

16,723
-1

Published on

jsf myfaces trinidad jpa spring derby apache web2.0 ajax

Published in: Technology
0 Comments
17 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
16,723
On Slideshare
0
From Embeds
0
Number of Embeds
5
Actions
Shares
0
Downloads
0
Comments
0
Likes
17
Embeds 0
No embeds

No notes for slide

Advanced Jsf

  1. 1. Advanced JavaServer Faces Matthias Wessendorf | matzew@apache.org http://matthiaswessendorf.wordpress.com
  2. 2. Matthias Wessendorf <ul><li>Oracle </li></ul><ul><ul><li>ADFv team (ADF Faces) </li></ul></ul><ul><li>Apache Software Foundation </li></ul><ul><ul><li>Apache MyFaces (Trinidad | Core) </li></ul></ul><ul><ul><li>Apache Shale </li></ul></ul><ul><li>Author </li></ul><ul><ul><li>Java- & Eclipse-Magazine </li></ul></ul><ul><ul><li>Books on Struts, J2ME&WebServices </li></ul></ul><ul><li>Speaker </li></ul><ul><ul><li>Oracle Open World </li></ul></ul><ul><ul><li>ApacheCon </li></ul></ul><ul><ul><li>JavaOne </li></ul></ul><ul><ul><li>JAX, W-JAX </li></ul></ul>
  3. 3. Advanced JSF - ToC <ul><li>JSF – Background </li></ul><ul><li>JSF – Overview of JSF - Frameworks </li></ul><ul><li>Selecting Frameworks </li></ul><ul><ul><li>Framework Details </li></ul></ul><ul><ul><li>Integration </li></ul></ul><ul><li>Some code samples </li></ul>
  4. 4. JSF – Background <ul><li>It all started with Servlet API ... </li></ul><ul><li>... and JSPs ... </li></ul><ul><li>... and „Model 2“ Web frameworks </li></ul><ul><ul><li>Apache Struts </li></ul></ul><ul><ul><ul><li>Action-based </li></ul></ul></ul><ul><li>... and JSTL! </li></ul><ul><li>Tons of „Model 2“ Frameworks ... </li></ul><ul><ul><li>(almost) no component-based approach </li></ul></ul><ul><ul><ul><li>UI Tags done with JSTL </li></ul></ul></ul><ul><li>JavaServer Faces </li></ul><ul><ul><li>one standard for Java Web Apps </li></ul></ul>
  5. 5. JSF – Details <ul><li>Java Standard of JCP </li></ul><ul><ul><li>lightweight Web-Framework </li></ul></ul><ul><ul><li>API for UI Component Development </li></ul></ul><ul><li>Specs out there: </li></ul><ul><ul><li>JSR 127  JSF 1.1 (May 2004) </li></ul></ul><ul><ul><li>JSR 252  JSF 1.2 [Java EE 5] (May 2006) </li></ul></ul><ul><ul><li>JSR 314  JSF 2.0 [Java EE 6] (2008 ?) </li></ul></ul><ul><li>Goals </li></ul><ul><ul><li>Make Java-Web-Development simple </li></ul></ul><ul><ul><li>Tooling (Jdev, Sun / Netbeans, Eclipse, ...) </li></ul></ul><ul><li>Implementations </li></ul><ul><ul><li>Apache MyFaces | RI (Sun) | OperaMasks.org </li></ul></ul>
  6. 6. JSF –Frameworks <ul><li>Wow! Really one standard ? </li></ul><ul><li>Yes ! </li></ul><ul><li>But... </li></ul><ul><li>Lot‘s of optionen: </li></ul><ul><ul><li>View-Layer (JSP, Facelets, Shale-Clay, Tiles, ...) </li></ul></ul><ul><ul><li>Dialog (Spring, Shale, Oracle ADFc) </li></ul></ul><ul><ul><li>JSF-Frameworks (Seam / Web Beans) </li></ul></ul><ul><ul><li>Custom JSF Lifecycle... (Mabon, ADF Faces) </li></ul></ul><ul><ul><li>Components (many, many ...) </li></ul></ul>
  7. 7. JSF „Frameworks“... <ul><li>Apache MyFaces Tomahawk </li></ul>Apache MyFaces Sun RI IceFaces Oracle ADF Faces Apache MyFaces Tobago Apache MyFaces Trinidad Facelets Seam JSR 299 / Web Beans Rich Client Faces Jenia Yahoo UI 4 JSF  http://www.jsfmatrix.net  Add your lib here JBoss RichFaces
  8. 8. Houston, we have a problem !
  9. 9. JSF Frameworks <ul><li>What you really need: </li></ul><ul><li>JSF – Runtime: </li></ul><ul><ul><li>Apache MyFaces </li></ul></ul><ul><ul><li>Sun RI </li></ul></ul><ul><li>View-Layer: </li></ul><ul><ul><li>JSP / JSPX (default) </li></ul></ul><ul><ul><li>Facelets </li></ul></ul><ul><ul><li>Apache Shale Clay </li></ul></ul><ul><li>Components: </li></ul><ul><ul><li>standard components </li></ul></ul><ul><ul><ul><li>very simple </li></ul></ul></ul><ul><ul><li>Usually you need more! </li></ul></ul>
  10. 10. Other frameworks <ul><li>That‘s it ? </li></ul><ul><li>Yes, in case of the „VIEW“ </li></ul><ul><li>What do you need for your Business-Layer ? </li></ul><ul><ul><li>EJB 2.x </li></ul></ul><ul><ul><li>EJB 3.x </li></ul></ul><ul><ul><li>Spring </li></ul></ul><ul><ul><li>Spring + JPA </li></ul></ul><ul><ul><li>ORM (Toplink, Hibernate) </li></ul></ul><ul><ul><li>JDBC / Spring + JDBC </li></ul></ul><ul><ul><li>A database... </li></ul></ul>
  11. 11. Frameworks <ul><li>We take: </li></ul><ul><ul><li>Apache MyFaces (runtime) </li></ul></ul><ul><ul><li>Facelets (view-layer) </li></ul></ul><ul><ul><li>Trinidad (JSF-Component Suite) </li></ul></ul><ul><ul><ul><li>The mother of PPR  </li></ul></ul></ul><ul><ul><li>Spring + JPA + Apache Derby </li></ul></ul><ul><ul><ul><li>JPA = Java Persistence API: </li></ul></ul></ul><ul><ul><ul><ul><li>Apache OpenJPA </li></ul></ul></ul></ul><ul><ul><ul><ul><li>Oracle‘s Toplink (Eclipse Link) </li></ul></ul></ul></ul><ul><ul><ul><ul><li>Apache Cayenne </li></ul></ul></ul></ul><ul><ul><ul><ul><li>... </li></ul></ul></ul></ul><ul><ul><li>MyFaces Orchestra (ViewController + conversation scope) </li></ul></ul>
  12. 12. Application Architecture JSF View DAO / Repository JSF Bean Service Spring Beans Java Persistence API (Apache OpenJPA) Apache Derby View Controller XHTML Pages Faces Apache MyFaces Orchestra
  13. 13. The choosen Frameworks
  14. 14. Apache MyFaces <ul><li>First OpenSource JSF Implementation </li></ul><ul><ul><li>JSF 1.1 and JSF 1.2 (in 2007) </li></ul></ul><ul><ul><li>Notes on the TCK ... </li></ul></ul><ul><li>Since 2005 hosted at Apache </li></ul><ul><ul><li>Before: LGPL / Sourceforge </li></ul></ul><ul><li>largest JSF „user community“ </li></ul><ul><li>several subprojects </li></ul><ul><ul><li>Tobago </li></ul></ul><ul><ul><li>Tomahawk </li></ul></ul><ul><ul><li>Trinidad </li></ul></ul><ul><ul><li>Orchestra </li></ul></ul><ul><ul><li>tbc  </li></ul></ul>
  15. 15. Facelets <ul><li>Alternate JSF-View-Technology </li></ul><ul><ul><li>JSP(X) is „old school“ </li></ul></ul><ul><li>lightweight Templating Framwork </li></ul><ul><ul><li>XHTML-based Templates </li></ul></ul><ul><ul><li>friendly to Designer </li></ul></ul><ul><ul><li>DEMO... </li></ul></ul><ul><li>Performance </li></ul><ul><li>JSF 1.2 w/o JavaEE 5 Container </li></ul><ul><ul><li>JSR RI </li></ul></ul><ul><ul><li>MyFaces 1.2.1 (soon) </li></ul></ul><ul><li>Damn simple Component Development! </li></ul><ul><ul><li>JavaServer Faces - Version 2.x </li></ul></ul>
  16. 16. A simple Facelet <ul><li><!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot; &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot;> </li></ul><ul><li><html </li></ul><ul><li>xmlns=&quot;http://www.w3.org/1999/xhtml </li></ul><ul><li>xmlns:h=&quot;http://java.sun.com/jsf/html &quot;> </li></ul><ul><li><body> <input type=&quot;text&quot; jsfc=&quot;h:inputText„ value=&quot;#{bean.property}&quot; /> </li></ul><ul><li></body> </li></ul><ul><li></html> </li></ul>
  17. 17. Faces Servlet Mapping <ul><li>http://server:8080/app/page.faces </li></ul><ul><li>With Facelets </li></ul><ul><ul><li>„ Open Source“ </li></ul></ul><ul><ul><ul><li>http://server:8080/app/page.xhtml </li></ul></ul></ul><ul><li>Servlet-Mapping: </li></ul><ul><li>< servlet-mapping > </li></ul><ul><li>< servlet-name > faces </ servlet-name > </li></ul><ul><li>< url-pattern > *.xhtml </ url-pattern > </li></ul><ul><li></ servlet-mapping > </li></ul><ul><li>http://server:8080/app/page.xhtml </li></ul>
  18. 18. Apache MyFaces Trinidad <ul><li>Part of Apache MyFaces </li></ul><ul><li>Over 100 JSF components </li></ul><ul><li>Several framework „goodies“ </li></ul><ul><ul><li>Test-Framework </li></ul></ul><ul><ul><li>Maven Plugins </li></ul></ul><ul><ul><li>Skinning (CSS based) (DEMO) </li></ul></ul><ul><ul><li>Dialog-Support (DEMO) </li></ul></ul><ul><ul><li>Ajax-API (DEMO) </li></ul></ul><ul><ul><ul><li>client-side (JavaScript) </li></ul></ul></ul><ul><ul><ul><li>server-side (Java) </li></ul></ul></ul><ul><li>stable JSF component set </li></ul><ul><ul><li>JSF 1.1 and 1.2 </li></ul></ul><ul><li>Donated by Oracle (2006) (ADF Faces) </li></ul>
  19. 19. Apache MyFaces Trinidad <ul><li>The component show </li></ul><ul><li>Trinidad Demo online: </li></ul><ul><li>http://www.irian.at </li></ul>
  20. 20. Spring Framework <ul><li>Well-known OpenSource Framework </li></ul><ul><ul><li>Apache 2.0 License </li></ul></ul><ul><li>„ Help“ for Java EE (J2EE) </li></ul><ul><ul><li>Makes EJB / J2EE simple! </li></ul></ul><ul><ul><li>POJOs are first class citizens </li></ul></ul><ul><ul><li>Added values to Java EE 5 </li></ul></ul><ul><li>Several „goodies“ (AOP, Transaction, DI, JDBC, ...) </li></ul><ul><li>Integration points for different Frameworks </li></ul><ul><ul><li>JSF, Struts, EJB, Hibernate, AspectJ,... </li></ul></ul>
  21. 21. Java Persistence API <ul><li>Standard for Java Persistence </li></ul><ul><ul><li>Important Part of EJB3 (JSR 220) </li></ul></ul><ul><ul><ul><li>Not tied to a EJB-Container </li></ul></ul></ul><ul><ul><li>RI => Toplink Essentials (Glassfish) </li></ul></ul><ul><ul><li>Lessons learned (Toplink, Hibernate, JDO) </li></ul></ul><ul><li>Simplifies EJB (2.x and 1.x) </li></ul><ul><li>Java5 Annotations (or XML...) </li></ul><ul><li>ORM-Frameworks (w/ JPA Support): </li></ul><ul><ul><li>Eclipse Link (Oracle Toplink) </li></ul></ul><ul><ul><li>Hibernate (JBoss) </li></ul></ul><ul><ul><li>OpenJPA & Cayenne (Apache) </li></ul></ul>
  22. 22. Java Persistence API <ul><li>@Entity </li></ul><ul><li>public class Customer </li></ul><ul><li>{ </li></ul><ul><li>@Id </li></ul><ul><li>@GeneratedValue (strategy= GenerationType. AUTO ) </li></ul><ul><li>private Long id ; </li></ul>
  23. 23. Java Persistence API <ul><li>@Temporal (value = TemporalType. DATE ) private Date birthday ; </li></ul><ul><li>@OneToOne (cascade= CascadeType. ALL ) private Address address ; </li></ul>
  24. 24. Spring and JPA <ul><li>Uses JPA w/o EJB-Container </li></ul><ul><ul><li>JPA used as ORM-Framework </li></ul></ul><ul><li>Supported JPA Implementations: </li></ul><ul><ul><ul><li>Hibernate </li></ul></ul></ul><ul><ul><ul><li>OpenJPA (Apache) </li></ul></ul></ul><ul><ul><ul><li>Toplink </li></ul></ul></ul><ul><li>JPA Template </li></ul><ul><ul><li>Use it for migration only! </li></ul></ul><ul><li>Direct usage of PersistenceContext </li></ul><ul><ul><li>AbstractEntityManagerFactoryBean </li></ul></ul>
  25. 25. Spring and JPA (Config) <ul><li><bean id=&quot;entityManagerFactory&quot; class=&quot; org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean &quot; </li></ul><ul><li>p:dataSource-ref=&quot;dataSource&quot; </li></ul><ul><li>p:persistenceUnitName=&quot;kickstart&quot; > </li></ul><ul><li><property name=&quot;jpaVendorAdapter&quot;> </li></ul><ul><li><bean class=&quot;org.springframework.orm.jpa.vendor.OpenJpaVendorAdapter&quot;> </li></ul><ul><li><property name=&quot;showSql&quot; value=&quot;true&quot;/> </li></ul><ul><li><property name=&quot;generateDdl&quot; value=&quot;true&quot;/> </li></ul><ul><li></bean> </li></ul><ul><li></property> </li></ul><ul><li><!– See OPENJPA-40 --> </li></ul><ul><li><property name=&quot;loadTimeWeaver&quot;> </li></ul><ul><li><bean class=&quot;net.wessendorf.wjax.openjpa.OpenJpaLoadTimeWeaver&quot;/> </li></ul><ul><li></property> </li></ul><ul><li></bean> </li></ul>
  26. 26. Spring and JPA (Config) <ul><li><bean id=&quot;transactionManager&quot; class=&quot;org.springframework.orm.jpa.JpaTransactionManager&quot; </li></ul><ul><li>p:entityManagerFactory-ref=&quot;entityManagerFactory&quot; </li></ul><ul><li>/> </li></ul><ul><li><bean class=„ </li></ul><ul><li>org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor </li></ul><ul><li>&quot;/> </li></ul><ul><li><bean class=„ </li></ul><ul><li>org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor </li></ul><ul><li>&quot;/> </li></ul>
  27. 27. Spring and JPA (DAO) <ul><li>@Repository </li></ul><ul><li>@Transactional (propagation = Propagation. SUPPORTS ) </li></ul><ul><li>public class JpaCustomerDaoImpl implements CustomerDao </li></ul><ul><li>{ </li></ul><ul><li>private final String QUERY_ALL = &quot;select c from Customer c&quot; ; </li></ul><ul><li>private final String QUERY_BY_SECONDNAME = &quot;select c from Customer c where c.secondname LIKE :param&quot; ; </li></ul><ul><li>private EntityManager em ; </li></ul><ul><li>@PersistenceContext </li></ul><ul><li>public void setEntityManager(EntityManager entityManager) </li></ul><ul><li>{ </li></ul><ul><li>this . em = entityManager; </li></ul><ul><li>} </li></ul><ul><li>... </li></ul>
  28. 28. Spring and JPA (DAO) <ul><li>public void remove(Customer customer) </li></ul><ul><li>{ </li></ul><ul><li>Customer toDel = findById(customer.getId()); </li></ul><ul><li>em .remove(toDel); </li></ul><ul><li>} </li></ul><ul><li>public List queryBySecondname(String name) </li></ul><ul><li>{ </li></ul><ul><li>Query q = em .createQuery( QUERY_BY_SECONDNAME ); </li></ul><ul><li>q.setParameter( &quot;param&quot; , name+ &quot;%&quot; ); </li></ul><ul><li>return q.getResultList(); </li></ul><ul><li>} </li></ul>
  29. 29. Services with Spring <ul><li>private CustomerDao customerDao ; </li></ul><ul><li>public void setCustomerDao(CustomerDao customerDao) </li></ul><ul><li>{ </li></ul><ul><li>this . customerDao = customerDao; </li></ul><ul><li>} </li></ul><ul><li>@Transactional(propagation = Propagation.REQUIRED) </li></ul><ul><li>public void removeCustomer(Customer customer) </li></ul><ul><li>{ </li></ul><ul><li>customerDao .remove(customer); </li></ul><ul><li>} </li></ul>
  30. 30. Spring: Service and DAO <ul><li>Config: </li></ul><ul><li>< bean class = „ </li></ul><ul><li>com.sessions.myfaces.daos. JpaCustomerDaoImpl &quot; id = &quot; customerDao &quot; /> </li></ul><ul><li>< bean class = „ </li></ul><ul><li>com.sessions.myfaces.services. CustomerServiceImpl &quot; id = &quot;customerService„ </li></ul><ul><li>p:customerDao-ref = &quot;customerDao&quot; /> </li></ul>
  31. 31. MyFaces Orchestra <ul><li>Simpler Application State Management </li></ul><ul><ul><li>Conversation-Scope (dialog / wizard) </li></ul></ul><ul><li>Better integration of View- and Persistence Layer </li></ul><ul><ul><li>Conversation-Scope persistance contexts </li></ul></ul><ul><li>JSF-Extension </li></ul><ul><ul><li>Not tied to Apache MyFaces </li></ul></ul><ul><ul><li>Core not tied to JSF API... </li></ul></ul><ul><ul><ul><li>No other framework supported (yet!) </li></ul></ul></ul><ul><li>JSF‘s „Managed Bean Facility“ replaced by Spring‘s IoC Container </li></ul><ul><ul><li>Requires Spring 2.0 </li></ul></ul><ul><li>ViewController </li></ul>
  32. 32. Session Application Manual Conversation Flash Conversation Request Conversation Scopes
  33. 33. Conversation-Scope persistance contexts
  34. 34. <ul><li>Common Pattern </li></ul><ul><ul><li>„ bean name“ similar to JSF View-Id </li></ul></ul><ul><ul><li>form.xhtml  form </li></ul></ul><ul><ul><li>users/form.xhtml  usersForm </li></ul></ul><ul><li>Lifecycle Hooks </li></ul><ul><ul><li>initView (nach RESTORE_VIEW ) </li></ul></ul><ul><ul><li>preProcess (vor INVOKE_APPLICATION ) </li></ul></ul><ul><ul><li>preRender (vor PRE_RENDER ) </li></ul></ul><ul><li>Orchestra supports Java5 Annotations </li></ul><ul><li>Pattern known in: </li></ul><ul><ul><li>JDeveloper + ADFc </li></ul></ul><ul><ul><li>Apache Shale </li></ul></ul><ul><ul><li>Apache Struts 2 </li></ul></ul>ViewController
  35. 35. Let‘s integrate them!
  36. 36. Main configuration <ul><li>Lot‘s of XML Files... </li></ul><ul><ul><li>Servlet Container (web.xml) </li></ul></ul><ul><ul><ul><li>All frameworks... </li></ul></ul></ul><ul><ul><li>Faces (faces-config.xml) </li></ul></ul><ul><ul><li>Spring XML file(s) </li></ul></ul><ul><ul><li>Trinidad: </li></ul></ul><ul><ul><ul><li>trinidad-config.xml </li></ul></ul></ul><ul><ul><ul><li>trinidad-skin.xml </li></ul></ul></ul><ul><ul><li>Facelets: </li></ul></ul><ul><ul><ul><li>(custom) taglib... </li></ul></ul></ul>
  37. 37. Important configuration <ul><li>JSF </li></ul><ul><ul><li>FacesServlet (web.xml) </li></ul></ul><ul><li>Facelets </li></ul><ul><ul><li>ViewHandler (web.xml b/c Trinidad) </li></ul></ul><ul><ul><li>javax.faces.DEFAULT_SUFFIX (web.xml) </li></ul></ul><ul><li>Trinidad </li></ul><ul><ul><li>RenderKit (faces-config.xml) </li></ul></ul><ul><ul><li>TrinidadFilter (web.xml) </li></ul></ul><ul><ul><li>ResourceServlet (web.xml) </li></ul></ul><ul><li>Orchestra </li></ul><ul><ul><li>Several things... (spring-xml(s) & web.xml) </li></ul></ul><ul><li>Spring </li></ul><ul><ul><li>RequestContextListener (web.xml) </li></ul></ul><ul><ul><li>ContextLoaderListener (web.xml) </li></ul></ul><ul><ul><li>DelegatingVariableResolver (faces-config.xml) </li></ul></ul>
  38. 38. Notes on JSF Managed Beans
  39. 39. JSF Managed Bean‘s <ul><li>Use Spring 2 </li></ul><ul><ul><li>Offers Scopes (request / session) </li></ul></ul><ul><li>Required configuration: </li></ul><ul><li>< faces-config > </li></ul><ul><li>< application > </li></ul><ul><li>< variable-resolver > </li></ul><ul><li>org.springframework.web.jsf.DelegatingVariableResolver </li></ul><ul><li></ variable-resolver > </li></ul><ul><li></ application > </li></ul><ul><li>... </li></ul>
  40. 40. JSF Managed Bean‘s <ul><li>A Bean clazz file: </li></ul><ul><li>public class FooController </li></ul><ul><li>{ </li></ul><ul><li>private CustomerService customerService ; </li></ul><ul><li>public CustomerService getCustomerService() </li></ul><ul><li>{ </li></ul><ul><li>return customerService ; </li></ul><ul><li>} </li></ul><ul><li>public void setCustomerService(CustomerService customerService) </li></ul><ul><li>{ </li></ul><ul><li>this . customerService = customerService; </li></ul><ul><li>} </li></ul><ul><li>... </li></ul><ul><li>} </li></ul>
  41. 41. JSF Managed Bean‘s <ul><li>Bean configuration (in Spring !): </li></ul><ul><ul><li>Spring offers lot‘s of features </li></ul></ul><ul><ul><li>Orchestra requires this! </li></ul></ul><ul><li>No Beans in faces-config.xml </li></ul><ul><li>< bean </li></ul><ul><li>id = &quot;create„ class = „....FooController„ scope = &quot;request&quot; </li></ul><ul><li>p:customerService-ref = &quot; customerServiceImpl “ / > </li></ul>
  42. 42. Let‘s code!
  43. 43. Facelets <ul><li>Template Engine, XHTML based </li></ul><ul><ul><li>Layout with CSS </li></ul></ul><ul><ul><li>Define areas in your master-template </li></ul></ul><ul><ul><ul><li>(content, footer, ...) </li></ul></ul></ul><ul><li><tr:document </li></ul><ul><li>xmlns:ui=&quot;http://java.sun.com/jsf/facelets&quot; </li></ul><ul><li>xmlns:tr=&quot;http://myfaces.apache.org/trinidad&quot; </li></ul><ul><li>...> </li></ul><ul><li>... </li></ul><ul><li><div class=„content&quot;> </li></ul><ul><li><ui:insert name=&quot;content&quot;>My default Content</ui:insert> </li></ul><ul><li></div> </li></ul><ul><li>...</tr:document> </li></ul>
  44. 44. Facelets <ul><li>Template Client </li></ul><ul><ul><li>regular web-page </li></ul></ul><ul><li><ui:composition xmlns=&quot;http://www.w3.org/1999/xhtml&quot; </li></ul><ul><li>xmlns:tr=&quot;http://myfaces.apache.org/trinidad&quot; </li></ul><ul><li>xmlns:mw=&quot;http://wessendorf.net/kickstart&quot; </li></ul><ul><li>... </li></ul><ul><li>template=&quot;WEB-INF/facelets/layout/template.xhtml&quot; > </li></ul><ul><li><!-- content --> </li></ul><ul><li><ui:define name=&quot;content&quot;> </li></ul><ul><li>My concrete JSF-Content !!! </li></ul><ul><li></ui:define> </li></ul><ul><li></ui:composition> </li></ul>
  45. 45. Facelets <ul><li>JSF is not „DRY“ ? </li></ul><ul><li><h:dataTable ...> </li></ul><ul><li>... </li></ul><ul><li><h:colum> </li></ul><ul><li><f:facet name=„header“> </li></ul><ul><li><h:outputText value=„Name“ /> </li></ul><ul><li></f:facet> </li></ul><ul><li><h:outputText value=„#{bean.name}“ /> </li></ul><ul><li></column> </li></ul><ul><li>... </li></ul><ul><li><h:colum> </li></ul><ul><li><f:facet name=„header“> </li></ul><ul><li><h:outputText value=„some other value“ /> </li></ul><ul><li></f:facet> </li></ul><ul><li><h:outputText value=„#{bean.foo}“ /> </li></ul><ul><li></column> </li></ul><ul><li>... </li></ul><ul><li></h:dataTable> </li></ul>
  46. 46. Facelets <ul><li>This would be nice! </li></ul><ul><li><h:dataTable ...> </li></ul><ul><li>... </li></ul><ul><li><x:smartColumn header=„Name“ visibleValue=„#{bean.name}“/> </li></ul><ul><li><x:smartColumn header=„ some other value“ visibleValue=„#{bean.foo}“/> </li></ul><ul><li>... </li></ul><ul><li></h:dataTable </li></ul><ul><li>... but... </li></ul>
  47. 47. Facelets <ul><li>P(l)ain JSF: </li></ul><ul><ul><li>Too much to do for comp. Dev: </li></ul></ul><ul><ul><ul><li>Java: </li></ul></ul></ul><ul><ul><ul><ul><li>UIComponent (JavaBean) </li></ul></ul></ul></ul><ul><ul><ul><ul><li>Renderer (creates the markup (HTML)) </li></ul></ul></ul></ul><ul><ul><ul><ul><li>Tag-Class (connects Comp. and Renderer) </li></ul></ul></ul></ul><ul><ul><ul><li>XML </li></ul></ul></ul><ul><ul><ul><ul><li>Faces-config.xml </li></ul></ul></ul></ul><ul><ul><ul><ul><li>TLD file </li></ul></ul></ul></ul>
  48. 48. Facelets <ul><li>With Facelets... </li></ul><ul><ul><li>Simple component development </li></ul></ul><ul><li>„ Rendering“ via XHTML file </li></ul><ul><li>NO! Java-Code required </li></ul><ul><li>Just: </li></ul><ul><ul><li>XHTML file </li></ul></ul><ul><ul><li>Facelet‘s Taglib XML file </li></ul></ul><ul><ul><li>register Taglib in web.xml </li></ul></ul>
  49. 49. Facelets <ul><li>My JSF Component: </li></ul><ul><li><tr:column </li></ul><ul><li>xmlns:ui=&quot;http://java.sun.com/jsf/facelets&quot; </li></ul><ul><li>xmlns:f=&quot;http://java.sun.com/jsf/core&quot; </li></ul><ul><li>xmlns:tr=&quot;http://myfaces.apache.org/trinidad &quot;> </li></ul><ul><li><f:facet name=&quot;header&quot;> </li></ul><ul><li><tr:outputText value=&quot;#{ header }&quot; /> </li></ul><ul><li></f:facet> </li></ul><ul><li><tr:outputText value=&quot;#{ visibleValue }&quot; /> </li></ul><ul><li></tr:column> </li></ul>
  50. 50. Facelets <ul><li>Taglib.xml: </li></ul><ul><li><facelet-taglib> </li></ul><ul><li><namespace>http://corp.com/smart</namespace> </li></ul><ul><li><tag> </li></ul><ul><li><tag-name>smartColumn</tag-name> </li></ul><ul><li><source>.../column.xhtml</source> </li></ul><ul><li></tag> </li></ul><ul><li></facelet-taglib> </li></ul><ul><li>web.xml: </li></ul><ul><li><context-param> </li></ul><ul><li><param-name>facelets.LIBRARIES</param-name> </li></ul><ul><li><param-value>/WEB-INF/mw.taglib.xml</param-value> </li></ul><ul><li></context-param> </li></ul>
  51. 51. Facelets <ul><li>Using the custom component: </li></ul><ul><ul><li>Add Namespace to your page: </li></ul></ul><ul><ul><li><tr:document </li></ul></ul><ul><ul><li>xmlns:ui=&quot;http://java.sun.com/jsf/facelets&quot; </li></ul></ul><ul><ul><li>xmlns:x=&quot; http://corp.com/smart&quot; </li></ul></ul><ul><ul><li>xmlns:f=&quot;http://java.sun.com/jsf/core&quot;> </li></ul></ul><ul><ul><li>Inside the XHTML file: </li></ul></ul><ul><li><x:smartColumn header =„Name“ visibleValue =„#{bean.name}“/> </li></ul>
  52. 52. Trinidad <ul><li>Offers Ajax (aka PPR) for free </li></ul><ul><ul><li>XHR + IFrame (for Uploads) </li></ul></ul><ul><ul><li>Components include Ajax: </li></ul></ul><ul><ul><ul><li>autoSubmit </li></ul></ul></ul><ul><ul><ul><li>partialSubmit </li></ul></ul></ul><ul><ul><ul><li>partialTriggers </li></ul></ul></ul><ul><li>Ajax-API </li></ul><ul><ul><li>server </li></ul></ul><ul><ul><li>client </li></ul></ul><ul><li>Dialog-Framework </li></ul><ul><li>CSS Skinning </li></ul>
  53. 53. Trinidad <ul><li>PPR in Action </li></ul><ul><li><tr:selectOneRadio value=&quot;#{partialBean.selectOne}&quot; autoSubmit=&quot;true&quot; id=&quot;select1&quot; > </li></ul><ul><li><tr:selectItem label=&quot;First&quot; value=&quot;Beer&quot;/> </li></ul><ul><li><tr:selectItem label=&quot;Second&quot; value=&quot;more beer&quot;/> </li></ul><ul><li><tr:selectItem label=&quot;Third&quot; value=&quot;sold out!&quot;/> </li></ul><ul><li></tr:selectOneRadio> </li></ul><ul><li><tr:outputText value=&quot;#{partialBean.selectOne}&quot; </li></ul><ul><li>partialTriggers=&quot;select1&quot; /> </li></ul>
  54. 54. Trinidad <ul><li>Call JavaScript from the Server... </li></ul><ul><li>ExternalRenderKitService.addScript(): </li></ul><ul><li>public String doTheWork() </li></ul><ul><li>{ </li></ul><ul><li>... </li></ul><ul><li>FacesContext context = FacesContext.getCurrentInstance(); </li></ul><ul><li>ExtendedRenderKitService erks = </li></ul><ul><li>Service.getRenderKitService(context, </li></ul><ul><li>ExtendedRenderKitService.class); </li></ul><ul><li>erks.addScript(context, </li></ul><ul><li>&quot;hello();&quot;);  JS-function </li></ul><ul><li>return (&quot;success&quot;); </li></ul><ul><li>} </li></ul>
  55. 55. Trinidad: Monitoring PPR <ul><li>function addListener() </li></ul><ul><li>{ </li></ul><ul><li>var requestQueue = TrPage.getInstance().getRequestQueue(); </li></ul><ul><li>requestQueue.addStateChangeListener(myCallback); </li></ul><ul><li>} </li></ul><ul><li>function myCallback(state) </li></ul><ul><li>{ </li></ul><ul><li>var busy = state == TrRequestQueue.STATE_BUSY; </li></ul><ul><li>var div = document.getElementById(&quot;load&quot;); </li></ul><ul><li>div.style.display = busy ? &quot;inline&quot; : &quot;none&quot;; </li></ul><ul><li>} </li></ul><ul><li>In XHTML: </li></ul><ul><li><tr:commandLink onclick=&quot;addListener(); &quot; ...> </li></ul>
  56. 56. Trinidad <ul><li>Dialog Framework </li></ul><ul><ul><li>„ new Window“ or lightweight Dialogs... </li></ul></ul><ul><ul><li><tr:commandLink text=&quot;Google Maps&quot; useWindow=&quot;true&quot; action=&quot;dialog:map&quot; returnListener=&quot;#{bean.returnListener}&quot; /> </li></ul></ul><ul><li>CSS Skinning </li></ul><ul><ul><li>needs trinidad-skins.xml </li></ul></ul><ul><ul><li>register „skin-family“ in trinidad-config.xml </li></ul></ul><ul><ul><li>create a CSS Datei </li></ul></ul>
  57. 57. Trinidad <ul><li>CSS Skinning : </li></ul><ul><li>.AFRequiredIconStyle { </li></ul><ul><li>color: #CC0000; </li></ul><ul><li>-tr-rule-ref: selector(&quot;.AFDefaultFont:alias&quot;); </li></ul><ul><li>} </li></ul><ul><li>af|inputDate::launch-icon </li></ul><ul><li>{ </li></ul><ul><li>content: url(/images/calendar_icon.gif); </li></ul><ul><li>} </li></ul>
  58. 58. Orchestra - ViewController <ul><li>Three ways </li></ul><ul><ul><li>Reflection (initView(),...) </li></ul></ul><ul><ul><li>Interface (ViewController) </li></ul></ul><ul><ul><li>Annotations (@ViewController, @InitView,...) </li></ul></ul><ul><li>„ Multi-ViewController“ </li></ul><ul><ul><li>@ViewController(viewIds={&quot;/all.xhtml&quot;, ...) </li></ul></ul>
  59. 59. Orchestra - ViewController <ul><li>Orchestra ViewController </li></ul><ul><li>@ConversationRequire( </li></ul><ul><li>conversationNames = &quot;editor&quot;, </li></ul><ul><li>entryPointViewIds = {&quot;/all.xhtml&quot;}, </li></ul><ul><li>redirect=&quot;/all.xhtml&quot;) </li></ul><ul><li>@ViewController(viewIds={&quot;/edit1.xhtml&quot;, &quot;/edit2.xhtml&quot;}) </li></ul><ul><li>public class Editor ... </li></ul><ul><li>{ </li></ul><ul><li>... </li></ul><ul><li>@PreRenderView public void loader() </li></ul><ul><li>{ </li></ul><ul><li>... </li></ul><ul><li>} </li></ul><ul><li>... </li></ul><ul><li>} </li></ul>
  60. 60. Orchestra - Scope <ul><li>Manuel-Scope </li></ul><ul><li><bean id=&quot; googleMapBean &quot; class=&quot;net.wessendorf.faces.starter.view.controller.GoogleMapBean&quot; scope=&quot;conversation.manual&quot; </li></ul><ul><li>orchestra:conversationName=&quot; googleMap &quot; </li></ul><ul><li>p:userService-ref=&quot;userServiceImpl&quot;> </li></ul><ul><li><aop:scoped-proxy /> </li></ul><ul><li></bean> </li></ul><ul><li>Closing a Conversation </li></ul><ul><li>Conversation currentConv = ConversationManager.getInstance().getConversation(&quot; googleMap &quot;); </li></ul><ul><li>currentConv.invalidate(); </li></ul>
  61. 61. Orchestra - Scopes <ul><li>ConversationBindingListener interface </li></ul><ul><ul><li>valueBound() </li></ul></ul><ul><ul><li>valueUnbound() </li></ul></ul><ul><li>Usem it for both scope‘s </li></ul><ul><ul><li>Flash </li></ul></ul><ul><ul><li>manual </li></ul></ul><ul><li>Conversation has „timeout“ </li></ul><ul><ul><li>30 minutes (default) </li></ul></ul>
  62. 62. Discussion <ul><li>JBoss Seam, „a Java EE framework“ </li></ul><ul><ul><li>JSF </li></ul></ul><ul><ul><li>EJB 3 </li></ul></ul><ul><li>Base for „Web Beans“ (JSR 299) </li></ul><ul><ul><li>Dependency-Injection... </li></ul></ul><ul><ul><li>Google Guice </li></ul></ul><ul><li>A (web) framework for Java EE </li></ul><ul><li>JavaServer Faces 2.0 </li></ul><ul><ul><li>Better Integration for component sets </li></ul></ul><ul><ul><ul><li>Ajax-Layer ? </li></ul></ul></ul><ul><ul><li>Taking up good ideas </li></ul></ul><ul><ul><ul><li>Facelets </li></ul></ul></ul><ul><ul><ul><li>Trinidad </li></ul></ul></ul><ul><ul><ul><li>... </li></ul></ul></ul><ul><li>„ Modern Web Frameworks“ ... ? </li></ul>
  63. 63. Documentation <ul><li>http://myfaces.apache.org </li></ul><ul><li>http://myfaces.apache.org/trinidad </li></ul><ul><li>http://springframework.org </li></ul><ul><li>https://facelets.dev.jav.net </li></ul><ul><li>Slides  http://slideshare.net/mwessendorf/ </li></ul><ul><li>Demo: </li></ul><ul><ul><li>http://code.google.com/p/facesgoodies/ </li></ul></ul>
  64. 64. Q&A <ul><li>Questions ? </li></ul><ul><li>Thank you ! </li></ul>

×