Friday, January 13, 2006

Non-JSF components and JSF components are out of order!

(article could be found and edited at The UVLE 3.0 Wiki)

Sometimes, when you expect a JSF component beside some non-JSF component, (say a normal HTML tag, a JSTL tag, or something else), ordering gets mixed and really messed up, especially if you are using Struts Tiles for templating. For example:

Hello, <h:outputText value="#{user.displayName}">!

One will expect it to appear as:

Hello, Mang Jose!

However, there are times when things go badly and appear as:

Mang Jose

Hello,!

This is due to the difference in rendering approach between Tiles, ordinary JSP, and JSF (links to references will be provided after the developer has done the project and has more time in his hands). It has been highly recommended that a JSF enabled page must be fully rendered by JSF to solve this out of synching. One way to do this is by using <f:verbatim>, a tag that renders anything inside it as plain text, including JSF tags, and any other tags for that matter (hence the name). Thus, we do this as:

<f:verbatim>Hello, </f:verbatim><h:outputText value="#{user.displayName}"><f:verbatim>!</f:verbatim>