Flying Saucer for PDF rendering

July 3, 2007

An interesting article about using a Java XHTML renderer (Flying Saucer) to render the output from facelets into PDF, JPG, or SVG:

Combine JSF Facelets and the Flying Saucer XHTML Renderer


Facelets: Tip for ui:include

July 3, 2007

Lately I wanted to use ui:include to read some common form fields from a seperate. I had a stumbling block, though, because I was using Apache Trinidad’s tr:panelFormLayout, which only lays out its direct children (or children in a group, but that results in a different look).

Although I’ve since given up on using trinidad, I had an idea on how to get around this – use c:if. As far as I know, c:if doesn’t create an additional component, so its inner components are added to the parent. I think ui:include might not require the incuded file to be valid XML – I could leave out the c:if and have multiple roots – but I prefer to have the file look like valid xml for the benefit of other tools.

So, the target file of the include would look like this:

<c:if test="true" xmlns:...> ... </c:if>

JSF Link to an entity

July 3, 2007

It’s very common to want to have a link which submits some form fields. Unfortunately, JSF/Facelets don’t, as far as I can tell, provide a tag which allows you to directly setup some beans and call an action when you click a link. The closest you can get is passing some string POST parameters, like this:

<h:commandLink id="editLink" action="#{employeeAction.prepareEdit}">
<h:outputText value="#{msg.edit}"/>
<f:param name="id" value="#{}"/>

And then you access that parameter like this:

FacesContext context = FacesContext.getCurrentInstance();
Map map = context.getExternalContext().getRequestParameterMap();
String employeeID = (String) map.get("id");

This is fairly normal compared to other frameworks, perhaps, but it’s not as nice as I’d expect from JSF for something so simple.

There’s a page describing some alternative methods for use in Apache MyFaces here.

Facelets tag reference sites

July 2, 2007

Does DRY (don’t repeat yourself) apply to documentation?

I’ve just started a project using facelets, glassfish, and the associated technologies (JTA, JSF, JTA, Java, Java EE, …). One major problem I have is that they’ve built these technologies as a big family on top of one another, but they don’t merge the documentation from the libraries they’re built on into the documentation for the tool itself.  For example, in order to know the available tags in facelets, I refer to at least these pages:

Facelets Tag Reference 

JSF Tag Reference

JSTL Tag Reference

Java EE Tutorial

Apache Trinidad Tag Reference

Gravel Tag Reference

Editing facelets in eclipse 3.3 WTP 2.0

July 2, 2007

If you’re all set up to do Java Server Faces, but you want to be able to edit the jsf-config.xml using the WTP 2.0 (web tools platform) and have some kind of editing support in eclipse, try this:

Go to Window > Preferences … > General > Content Types > Text > JSP and add “*.xhtml”, or whatever extension you’re using for your facelets.

Now you’ll gain a bit of validation and editing support that wasn’t there before. Hope that helps!