Apr 192011

The following are things that I think could be improved upon in JSF2.

1) There is no colspan (or rowspan) attribute for panelGrid.

Something like this would be useful, for example if you want full control of the tables JSF creates for you for specific formatting. There are a couple of ways to get around this. One method is to not use a panelGrid and just use a plain old html table. Of course, if you use a plain html then you’ll have to wrap it something (like a panelGrid for instance) if you’d like the table to be rerendered with some AJAX.

The other way around this is knowing that the panelGrid does offer headers and footers for the table it creates for you. This may be acceptable for your design.

<f:facet name="header">
    <h:outputText value="I am header text and I take up many columns."/>


<f:facet name="footer">
    <h:outputText value="I am footer text and I take up many columns."/>

2) A Boolean value on a bean is set to false instead of being left as null when the form is submitted.

There isn’t much to say about this. It’s “Boolean” not “boolean,” so don’t touch it if it’s null! This may have to do with the javax.faces.VALIDATE_EMPTY_FIELDS setting, but in my mind the two should be unrelated. Storing null instead of “false” is useful when saving form data to a database and capturing whether the user actually chose false or was defaulted into false. The default should be null if there is a “no option” default. The only way around this I’m aware of at the time of this writing is making the backing bean use a String, giving the “no option” option a value of “null,” and then turning that “null” String into an actual null value before inserting into the database (what a pain).

3) selectMany check boxes can only be displayed vertically or horizontally.

What about 2 by 2? 3 by 2? etc. This is another control issue.. The way around this that I found is to create extra methods on the backing bean – one that returns the first half of the check boxes and one that returns the second half of the check boxes. That way the two methods can be used for two separate columns, thus creating a list of checkboxes that are two-by-two. The annoying thing about doing it this way is that returning a simple

list.sublist(0, list.size() / 2);

doesn’t really work. Since JSF wants to set data on the list instead of just looking at it, you may need to actually truly have two lists on the backing bean. Then dealing with it as one list requires some additional workarounds. That’s what I had to do…

 Posted by at 9:56 pm