Abstract
Learn to create a scripting like experience using Java, JBoss Seam, Facelets, JSF and Crafter rivet's XML engine.
Article
The XML engine inside Crafter rivet is very powerful and when combined with Facelets and JSF and Seam components this capability can be used to drive content rich web applications and Web sites. Facelets supports a rich capability for creating reusable UI components through its ui:composite tag. The composite tag allows you to define tiles and then later include them in to a larger framework.
Seam components are developed in Java which has a reputation for being a bit more difficult to develop in and deploy to. With Java you must first compile, package, deploy and often restart your application. This can make development a drag. It can also make Java less attractive as a platform for prototyping or where fast turn around is important.
While there is some truth in this thinking, it is not all true. The simple truth is that the right tool for the job get's the job done the fastest and with the greatest ease.Java and Seam are awesome as platforms and frameworks. Facelets is a powerful templating capability. JSF components bring powerful reuse but are slower to develop then say - a PHP or Javascript based component. This does not mean that JSF is bad. It means JSF has to be used the right way. It was designed for reuse and allows for graphs of reusable components to be combined to create unique UI experiences. If you keep this in mind as you develop it is possible with the help of Facelets and Seam to create a very rapid, nearly scriptable development experience.
Sample Crafter rivet Page Document
<?xml version="1.0" encoding="UTF-8"?> <page rootLevelAttribute='it is rough at the top'> <title xsi:nil="false" >Welcome to Crafter</title> <meta-keywords xsi:nil="true" /> <meta-description xsi:nil="true" /> <body xsi:nil="false">Welcome to Crafter, this value from Alfresco</body> <someContent myAttribute='time wll spent' xsi:nil="false">:)</someContent> <someContainer xsi:nil="false"> <someNestedContainer> <nestedItem>a</nestedItem> <nestedItem myAttribute='Radar spelled backwards is... radaR'>c</nestedItem> <nestedItem>d</nestedItem> </someNestedContainer> </someContainer> </page>
Sample Facelets Template
<ui:composition xmlns="http://www.w3.org/1999/xhtml" xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:h="http://java.sun.com/jsf/html" xmlns:c="http://java.sun.com/jstl/core"> <h:outputText value="#{pageRefResources['body']}" escape="false"/><br/> <h:outputText value="#{pageRefResources['someContent']}" escape="false"/><br/> <h:outputText value="#{pageRefResources['someContainer/someNestedContainer/nestedItem[2]']}" escape="false"/><br/> <h:outputText value="#{pageRefResources['someContent/@myAttribute']}" escape="false"/><br/> <h:outputText value="#{pageRefResources['someContainer/someNestedContainer/nestedItem[2]/@myAttribute']}" escape="false"/><br/> <h:outputText value="#{pageRefResources['@rootLevelAttribute']}" escape="false"/><br/> <ul> <ui:repeat value="#{pageRefResources['someContainer/someNestedContainer/nestedItem']}" var="item"> <li><h:outputText value="#{item}" escape="false"/></li> </ui:repeat> </ul> <ul> <ui:repeat value="#{pageRefResources['//nestedItem']}" var="item"> <li style='color:orange'><h:outputText value="#{item}" escape="false"/></li> </ui:repeat> </ul> <!-- lookup a single response from a list --> <h:outputText value="#{pageRefResources['//nestedItem[@foo=\'bar\']/myValue'].get(0)}" escape="false"/> </ui:composition>
Output
Welcome to Crafter, this value from Alfresco
![]()
c
time wll spent
Radar spelled backwards is... radaR
it is rough at the top
- a
- c
- d
- a
- c
- d
Under The Hood
Under the hood Crafter is mapping DOM XPATH responses to "atomic" properties (single values), java.util.Map and java.util.List. This is enables us to bind to, and place nicely in EL expressions within tag libraries like JSTL, Facelet tags, JSF tags and so on.
Pros and Cons
Pros
- writing additional or domain specific java code/components makes it possible to perfectly abstract view from model
- Complex content paths can be reduced to very simple function calls
Cons
- Requires custom java development, wiring, deployment, restart
- Not great for prototyping
- Not great for short projects or fast