2. Cagatay Civici
JSF EG (Expert Group) Member
PrimeFaces Lead
Apache MyFaces PMC
Speaker, Author, Reviewer
Consultant and Trainer for Prime Technology
14. No XML
faces-config.xml is not optional
Get rid of;
<managed-bean />
<navigaton-case />
<component />, <renderer />
<converter />, <validator />
...
15. Managed Beans with JSF 1.x
<managed-bean>
<managed-bean-name>itemView</managed-bean-name>
<managed-bean-class>com.prime.view.itemView</managed-bean-class>
<managed-bean-scope>request</managed-bean-scope>
</managed-bean>
package com.prime.view;
public class ItemView {
}
16. Managed Beans with JSF 2.0
NO XML
@ManagedBean
public class ItemView {
}
17. Dependencies with JSF 1.x
<managed-bean>
<managed-bean-name>itemView</managed-bean-name>
<managed-bean-class>com.prime.view.itemView</managed-bean-class>
<managed-bean-scope>request</managed-bean-scope>
<managed-property>
<property-name>itemService</property-name>
<value>#{itemService}</value>
</managed-property>
</managed-bean>
<managed-bean>
<managed-bean-name>itemService</managed-bean-name>
<managed-bean-class>com.prime.service.ItemServiceImpl</managed-bean-class>
<managed-bean-scope>application</managed-bean-scope>
</managed-bean>
package com.prime.view;
public class ItemView {
private ItemService itemService;
//getter&setter
}
18. Dependencies with JSF 2.0
NO XML
@ManagedBean(name=”itemService”)
@ApplicationScoped
public class ItemServiceImpl implements ItemService {
}
@ManagedBean
public class ItemView {
@ManagedProperty(value=”itemService”)
private ItemService itemService;
//getter&setter
}
25. Event Listeners
New API SystemEventListener
isListenerForSource(Object source)
processEvent(SystemEvent event)
Configure via xml or @ListenerFor
Application.subscribeToEvent(event, listener);
UIComponent.subscribeToEvent(event, listener);
28. Navigations with JSF 2.0
NO XML
public String buttonClick() {
return “target”;
}
source.xhtml target.xhtml
29. GET Support
Navigate by GET
View Metadata and View Parameters
Bookmarkable URLs
Post-Redirect-Get
30. GET Support with JSF 1.x
Assigned when bean is used for first time
No validation/conversion support
No post assignment listener (init view)
http://www.site.com/itemView.jsf?itemId=10
<managed-bean>
<managed-bean-name>itemView</managed-bean-name>
<managed-bean-class>com.prime.view.itemView</managed-bean-class>
<managed-bean-scope>request</managed-bean-scope>
<managed-property>
<property-name>itemId</property-name>
<value>#{param[‘itemId’]}</value>
</managed-property>
</managed-bean>
31. GET Support with JSF 2.0
Introducing ViewParameters
Validation/conversion support
Post assignment listener (init view)
http://www.site.com/itemView.jsf?itemId=10
<f:view>
<f:metadata>
<f:viewParam name=”itemId” value=”#{itemView.itemId}” />
</f:metadata>
</f:view>
32. GET Support with JSF 2.0
Validation/conversion support
<f:view>
<f:metadata>
<f:viewParam name=”itemId” value=”#{itemView.itemId}”>
<f:validator validatorId=”itemValidator” />
</f:viewParam>
</f:metadata>
</f:view>
33. GET Support with JSF 2.0
Post mapping listener
<f:view>
<f:metadata>
<f:viewParam name=”itemId” value=”#{itemView.itemId}”>
<f:validator validatorId=”itemValidator” />
</f:viewParam>
<f:event type=”preRenderView” listener=”#{itemView.loadItem}”/>
</f:metadata>
</f:view>
public void loadItem() {
//load item with itemId from datatabase
}
34. GET Support with JSF 1.2
GET component h:outputLink
<h:outputLink value=”#{request.contextPath}”/itemView.jsf?itemId=10>
View Item
</h:outputLink>
Manual URL generation
No support for;
context-path
navigation-rules
35. GET Support with JSF 2.0
<h:button /> and <h:link />
<h:link outcome=”main” />
<h:button outcome=”main” includeViewParams=”true”/>
<h:button outcome=”main” includeViewParams=”true”>
<f:param name=”itemId” value=”#{itemView.itemId}” />
</h:button>
Auto generated Bookmarkable URLs
Integrated with Navigation Rules
36. Project Stage
Runtime hint
Mostly for use of implementation and extensions
Development, Production, SystemTest, UnitTest
<context-param>
<param-name>javax.faces.PROJECT_STAGE</param-name>
<param-value>Development</param-value>
</context-param>
Application.getProjectStage()
38. State Saving in JSF 1.x
Full Component Tree saved/restored
Attributes saved/restored
Performance/Memory issues
Burden for component developer
39. State Saving in JSF 2.0
Partial State Saving
Initial state is marked
Deltas are saved and helper
StateHelper API for developers
Much less in size
40. Resource Loading with JSF 1.x
Loading bundles resources from jar
Custom Servlet or Filter required
41. Resource Loading with JSF 2.0
New Resource APIs for;
Registering
Relocating
Loading
locale, version support
New components
<h:outputStylesheet /> and <h:outputScript />
42. Registering
Resources located at;
/webroot/resources/mylib
/jar/META-INF/resources/mylib
@ResourceDependency(name=”cool.js”, library=”mycoollib”)
public class MyCoolComponent extends UIComponent {
}
@ResourceDependencies {
@ResourceDependency(name=”cool.js”, library=”mycoollib”)
@ResourceDependency(name=”cool.css”, library=”mycoollib”)
}
public class MyCoolComponent extends UIComponent {
}
43. Relocating
Resources placed at head or body
<h:head />, <h:body />
@ResourceDependency(name=”cool.js”, library=”mycoollib”, target=”head”)
public class MyCoolComponent extends UIComponent {
}
UIViewRoot.addComponentResource API
44. Resource Components
Load from webroot or jar
<h:outputStylesheet name=”cool.css” library=”mycoollib” />
<h:outputScript name=”cool.js” library=”mycoollib” target=”head”/>
<h:graphicImage name=”cool.png” library=”mycoollib”/>
<h:graphicImage value=”#{resource[‘mycoollib:cool.png’}”/>
51. PRIMEFACES
Next Generation Component Suite
Most Popular JSF 2.0 Library
100+ components (Everything you need)
Lightweight: one jar, no dependencies, zero-config
Skinning support with 25+ themes and theme creator
Extensive documentation
Huge and active community
jQuery based
Mobile UI Kit: TouchFaces
Ajax Push support
Open Source (Apache License)
52. Setup
No setup required, drop the jar and add the namespace;
xmlns:p=”http://primefaces.prime.com.tr/ui”
<p:editor />
61. How to Create Your Own
No need to know CSS
Disable default skin
<context-param>
<param-name>primefaces.skin</param-name>
<param-value>none</param-value>
</context-param>
See: http://vimeo.com/14235640
72. Trainings
Prime Technology Courses (onsite and online);
JSF2 and PrimeFaces
JSF2 - Spring - JPA (popular)
JSF - Seam - JPA
JSF2 - CDI- JPA (Java EE 6)
and more
www.prime.com.tr/training.html