wnas

h:outputText flaw / bug ?

jsp

I recently came across something that I can only describe as a flaw or a bug in the myFaces implementation of a tag. The tag in question is the h:outputText of the tomahawk myFaces tags. It seems like a straightforward tag as you look at it, or use it.

<h:outputText id="tagId"
	value="#{dna.project.projectPart.value}"
	converter="converters.valueConverter"/>

What it renders is almost as simple:

<span id="jsfGen:tagId">value</span>

Nothing to it, you might say. A simple way of putting data on a page, using a simple tag.

But, if you have some sloppy coding and someone forgets to put an id on the tag, something weird happens

Problem

The span surrounding the data, a simple html tag which you might use to style it according to some degree, simply disappears. So if you do this:

<h:outputText id="tagId"
	value="#{dna.project.projectPart.value}"
	converter="converters.valueConverter"/>

It leaves you with nothing more than this:

value

So what I hear you ask, the data is still there and that is true. But missing the span tag can cause serious trouble for the front ender how is styling you application. If you do not know that omitting the id causes the tag to render without a span, you have some serious searching ahead of you, as the missing id is the only thing that is different. In the example above it is easily spotted, but in real life, you often have to search through multiple lines of code in multiple xhtml documents, making it easy to overlook.

As I found it, it is kinda logical, as the output text tag only outputs text and nothing more. Only when it needs a tag to apply the id to, it renders one. But doing this results in unpredictable html rendering, where the styling or the javascript can be harmed as they both want a predictable result of html to address.

Solution

The quickest way to solve this problem in an existing project is to agree on Coding conventions in which you set that you always set an ID on h:outputText. By doing this, you will easily spot the mistakes and will be able to correct them.

What I propose is a very simple solution, rebuild the tag in a subtle manner so that it always renders the span. In that way we do not have unpredictable results in our html and everybody lives happily everafter...

How?

What I think is that rewriting the tag in order to always creates a span surrounding the data, leaves us with a more simple tag and should not need much work...

Now, I need to figure out how to rewrite a tag, anybody out there who can help me...

← Home