jump to navigation

Another JSF Gotcha July 9, 2008

Posted by Phill in General J2EE.
Tags: , , , ,
comments closed

JSF has a number of “gotchas”. Today I managed to stumble across another one. Again.

Suppose you’re designing a user administration panel, and you want to be able to edit a user and select a list of roles for them. You’d think a fairly logical control to use would be a selectManyListbox (assuming, for the moment, it’s a fairly small number of roles).

So, in your backing bean you add in a List containing all the user roles, and you configure your SelectItems and converters. Except you still keep getting that damn error message: “Validation Error: Value is not valid”.

It turns out the problem is that JSF is so advanced, it can’t yet handle the Java Collections Framework: you have to use arrays instead. That’s right, in your backing bean, if you use List<MyClass> as the value binding for the list box, it will not work. You need to use MyClass[] instead.

I am using an older version of JSF (1.1 as opposed to 1.2) so that might be fixed now – still rather annoying to come across it though.

Advertisements