Friday, January 29, 2010

A feature that JSF needs

I've noticed for some time now that there are just some things that are hokey in JSF.

If you're like me, you almost always have your forms setup like this:

<h:outputLabel for="pvalue" value="Value"/>
<h:inputText value="#{propertyAction.propValue}" id="pvalue"/>

Now if there's a validation on this input, you need to mark the label (otherwise users get a really bizarre error message that they won't understand)

<h:outputLabel for="pvalue" value="Value"/>
<h:inputText value="#{propertyAction.propValue}" id="pvalue" label="Value"/>

And if you're using a bundle, it'll look something like this:

<h:outputLabel for="pvalue" value="${msgs['value']}"/>
<h:inputText value="#{propertyAction.propValue}" id="pvalue" label="${msgs['value']}"/>

So why can't JSF be smart enough to realize "Ok, I have an outputLabel for this input type, it has a validation error, let me use that label instead." and make the label attribute optional and can override the outputLabel in this case.

1 comment:

  1. You forgot the
    <h:message for="pvalue" /> :P

    Makes it even better. Should be easy enough to do a composite component to do this though. I'll have to give it a try.

    It'll be the JSF equivalent of the tuple, implemented a thousand times over in many different projects, because it was left out of the base platform...!