2. My experience with JBoss Seam and JSF:
• Used plain JSF 1.2 for prototype (~1 month)
• Used Seam 2.2 in actual implementation (~9
months)
What is this presentation about?
• Common tasks where Seam makes life easier
3. Separated business logic
in:
◦ JSF managed beans
◦ Business components (EJBs)
EJB lookup
Context context = new InitialContext();
context.lookup("java:comp/env/...");
4. One kind of “stuff ”
Seam Components
◦ POJOs
◦ EJB
◦ Entities
Seam unifies Java EE:
◦ Dependency Injection
◦ Transactions
◦ Security
No separation between front-
end components and business
components.
Define your own architecture
5. faces-config.xml
JSF
<managed-bean>
◦ Through faces-config.xml <managed-bean-name>myBean1</managed-bean-name>
<managed-bean-class>mypackage.MyBean1</managed-
bean-class>
Java EE: @EJB <managed-bean-scope>application</managed-bean-
scope>
</managed-bean>
◦ Servlets, Filters, Listeners
<managed-bean>
◦ Tag handlers, tag library <managed-bean-name>myBean2</managed-bean-name>
event listeners <managed-bean-class>mypackage.MyBean2</managed-
bean-class>
<managed-bean-scope>request</managed-bean-scope>
… but not in JSF Managed <managed-property>
beans (backing beans) <property-name>myBean1</property-name>
<value>#{myBean1}</value>
</managed-property>
</managed-bean>
8. JSF UI Component
tree and state
◦ Tomahawk <t:saveState>
◦ Richfaces <a4j:keepAlive>
If client-side state:
object != object
9. Session
◦ Problems:
Increased memory usage
Scalability problems
Need to consider
multiple tabs
10. Seam scopes:
◦ Event (Request)
◦ Session
◦ Application
◦ Page
◦ Stateless
◦ Business Process
◦ Conversation
What is a conversation?
◦ Lives for multiple requests
◦ Stateful, but not session
13. Application Security:
◦ Page-level security
◦ Component-level security
JSF does not specify security
Can a filter be used?
◦ Does View Handler use the
Servlet Request Dispatcher?
JSP:Yes
<filter-mapping>
<filter-name>My Security Filter</filter-name>
<url-pattern>/view2.jsp</url-pattern>
<dispatcher>REQUEST</dispatcher>
<dispatcher>FORWARD</dispatcher>
</filter-mapping>
Facelets: No
14. Both Page-level and Component-level security
Some examples:
◦ Page-level authentication / authorization
<pages login-view-id="/login.xhtml">
<page view-id=”admin*" login-required="true”>
<restrict>#{s:hasRole('admin')}</restrict>
</page>
</pages>
<security:identity authenticate-method="#{authManager.authenticate}"/>
◦ Page customization
<s:link view="/jhug/deleteMember.xhtml" value="Delete" rendered="#{s:hasRole('admin') ||
s:hasRole(’usermanager')}"/>
◦ Component-level authorization
@Name("myBean")
@Scope(ScopeType.SESSION)
@Restrict("#{s:hasRole('admin')}")
public class MyBean implements Serializable {
…
15. <h:commandLink value="Click here” action="#{myBean.method}">
<f:setPropertyActionListener target="#{myBean.methodParameter}”
value="#{value}" />
</h:commandLink>
public class MyBean {
private String param;
public String method() {
if("something".equals(param)) {
return "ok";
}
return "notOk";
}
public String getParam() {
return param;
}
public void setParam(String param) {
this.param = param;
}
}
16. <h:commandLink value="Click here” action="#{myBean.method(value)}” />
@Name("myBean")
public class MyBean {
public String method(String param) {
if("something".equals(param)) {
return "ok";
}
return "notOk";
}
}
17. Help:
◦ Good books
◦ Extensive, up-to-date documentation
◦ Old forum, somewhat inactive
◦ StackOverflow.com
Issues:
◦ Works best on JBoss AS
◦ Seam 2 issues are resolved slowly
(Focus on Seam 3)