• Save
Go Fullstack: JSF for Public Sites (CONFESS 2013)
Upcoming SlideShare
Loading in...5
×
 

Go Fullstack: JSF for Public Sites (CONFESS 2013)

on

  • 881 views

Slides for session Go Fullstack: JSF for public sites by Michael Kurz held at the CONFESS 2013 in Vienna/Austria. This is an updated version of the same session held at CONFESS 2012 including JSF 2.2 ...

Slides for session Go Fullstack: JSF for public sites by Michael Kurz held at the CONFESS 2013 in Vienna/Austria. This is an updated version of the same session held at CONFESS 2012 including JSF 2.2 view actions.

The examples for this session can be found at https://github.com/jsflive (see slides for details).

Statistics

Views

Total Views
881
Views on SlideShare
802
Embed Views
79

Actions

Likes
1
Downloads
0
Comments
2

1 Embed 79

http://armdev.wordpress.com 79

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

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…
  • No one platform can be compared with java ee 7, and as web framework JSF2.2 is the best, I have seen a lot of java and not java framework, but they all like just some experiment and they still depend from a lot of configs and have bad software design,
    Are you sure you want to
    Your message goes here
    Processing…
  • JSF2.2 is great, java ee 7 platform is the best, JSF2.2 have not alternatives. Thanks.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

Go Fullstack: JSF for Public Sites (CONFESS 2013) Go Fullstack: JSF for Public Sites (CONFESS 2013) Presentation Transcript

  • No mountains this year, but still snow...Go Fullstack: JSF for public sitesMichael Kurz | IRIAN
  • Agenda• Motivation• Architecture with/without EE 6 container• Putting the pieces together (CDI and CODI)• JSF and GET-Requests• RESTful URLs with JSF and PrettyFaces• Demonstrations and examples
  • Motivation• http://scientific-consensus.com• From GWT to JavaServer Faces• Lightweight Java EE 6 architecture• Does JSF really support HTTP GET?
  • Architecture and Technology Stack Architecture With EE 6 container No EE 6 container Presentation JSF, CDI, CODI JSF, CDI, CODI Service EJB, CDI CDI, CODI Data access EJB, JPA CDI, CODI, JPA
  • MyFaces Extensions CDI• Portable extension of CDI• Simplifies development with CDI and JSF• Several modules: • JSF 1.2 and 2.x • JPA, Bean Validation...• Works with: • CDI: OpenWebBeans, Weld • JSF: MyFaces, Mojarra (1.2, 2.0 and 2.1)• Watch out for Apache DeltaSpike
  • Management of Persistence Context• With Java EE container (EJB) @javax.ejb.Stateless public class CustomerRepository { @PersistenceContext private EntityManager em; }• Without Java EE container (CDI + CODI) @ApplicationScoped public class CustomerRepository { @Inject private EntityManager em; }
  • Transaction Management• With Java EE container • Transactions managed by container (@TransactionAttribute)• Without Java EE container (CDI only) • Transactions managed by CODI @ApplicationScoped public class CustomerService { @Inject private CustomerRepository customerRepository; @Transactional public void saveUser(User user) {...} }
  • Demonstration• Architecture with CDI and CODIExample: https://github.com/jsflive/mymail-get
  • The Web versus JSF vs. HTTP GET HTTP POST
  • JSF requests• HTTP requests in classic JSF page1.xhtml page2.xhtml page3.xhtml GET POST POST /faces/page1.jsf /faces/page1.jsf /faces/page2.jsf• Problems with HTTP POST: • Page reload problematic • URL in browser one step behind • Lack of bookmarkability/direct linking• JSF 2: h:link, h:button and view parameters
  • JSF 2: Navigation with h:link and h:button• Navigation target in attribute outcome <h:link outcome="/page1.xhtml" value="Page 1"/> <h:link outcome="/page2.xhtml" value="Page 2"> <f:param name="para" value="1"/> </h:link> <h:button outcome="/page3.xhtml" value="Page 3"/>• Renders link or button (h:form not necessary) <a href="/page1.jsf">Page 1</a> <a href="/page2.jsf?para=1">Page 2</a> <input type="button" value="Page 3" onclick="window.location.href = /pag3.jsf"/>
  • JSF 2: View Parameters• Bind request parameters to bean properties• Tag f:viewParam in f:metadata <f:metadata> <f:viewParam name="id" value="#{myBean.id}"/> </f:metadata> Converted and @Named @RequestScoped validated public class MyBean { private long id; public long getId() {return id;} public void setId(long id) {this.id = id;} }
  • "View actions" in JSF < 2.2• JSF 2.0 "forgot" about view actions• (JSF) Alternative: PreRenderViewEvent <f:event type="preRenderView" listener="#{bean.preRender}"/>• Listener method for system event public void preRender(ComponentSystemEvent event) { mail = mailService.findById(id); }• Alternative: CODI @PreRenderView
  • View actions in JSF 2.2• Real view actions part of JSF 2.2 <f:metadata> <f:viewParam name="id" value="#{bean.id}"/> <f:viewAction action="#{bean.load}" onPostback="false" phase="INVOKE_APPLICATION"/> </f:metadata>• Normal action method public String load() { mail = mailService.findById(id); return null; }
  • Post-Redirect-Get with JSF 2• Request /faces/myPage.xhtml?id=1 <h:form> <h:commandButton action="#{myBean.save}" value="Save"/> <h:commandButton value="Cancel" immediate="true" action="myPage?faces-redirect=true&amp; faces-include-view-params=true"/> </h:form> @Named @RequestScoped public class MyBean { public String save() { return "myPage?faces-redirect=true" + "&faces-include-view-params=true"; } }
  • Demonstration• GET requests with h:link and h:button• View Parameters and JSF 2.2 view actions• Post-Redirect-Get with JSFExample: https://github.com/jsflive/jsf-get-examples (jsf-get02-jsf22)
  • RESTful URLs http://myshop.at/node.html?mode=list&cat=1234 http://myshop.at/products/books
  • Why RESTful URLs?• Readability• Search Engine Optimization (SEO)• Confidence• Looks prettier
  • RESTful URLs for JSF• PrettyFaces: RESTful URLS for JSF • By OCPsoft, Open Source• Features: • URL Rewriting • Enhanced navigation • Page actions • Seamless integration into JSF • Easy configuration
  • PrettyFaces: Example 1 (1)• Remove "JSF parts" of URL http://myshop.at/faces/account.xhtml http://myshop.at/account
  • PrettyFaces: Example 1 (2)• Configuration in pretty-config.xml <url-mapping id="account"> <pattern value="/account"/> <view-id value="/faces/account.xhtml"/> </url-mapping>• Annotation based configuration @Named @RequestScoped @URLMapping(id="account", pattern="/account", viewId="/faces/account.xhtml") public class AccountPage {}
  • PrettyFaces: Example 2 (1)• Map part of URL to parameter http://myshop.at/faces/products/details.xhtml?id=123 http://myshop.at/product/123
  • PrettyFaces: Example 2 (2)• Configuration in pretty-config.xml <url-mapping id="productDetails"> <pattern value="/product/#{id}"/> <view-id value="/faces/products/details.xhtml"/> </url-mapping>• Path parameter used in view parameter <f:metadata> <f:viewParam name="id" value="#{bean.id}"/> </f:metadata> <f:event type="preRenderView" listener="#{bean.preRender}"/>
  • Demonstration• PrettyFacesExample: https://github.com/jsflive/jsf-get-examples (jsf-get03)
  • Conclusion• Lightweight Architecture with Java EE 6• JSF 2 simplifies GET support• JSF 2.2 adds view actions• PrettyFaces• Necessary for the intranet?
  • Curious?• Kurz, Marinschek, Müllan: JavaServer Faces 2.0, dpunkt.Verlag• IRIAN JSF@Work Online-Tutorial http://jsfatwork.irian.at• JSFlive Weblog http://jsflive.wordpress.com