Adverts

I searched a long time before I figured this one out. I was using a selectOneListBox with a customer converter and getting the error message "Validation Error: Value is not valid". If you are using a custom converter, as I describe on the converters page, you have to provide a working equals method for the object that you are trying to convert to and from. If you attempt to use the default equals method or fluff the implimentation the object won't convert correctly leading to the rather non-intuative error message: "Validation Error: Value is not valid".

I think the problem is that the object that is provided by the value binding is checked against the items in the select list and no match is found. I can't figure out why that would create a validation error when the item in the value binding is set but it does explain why the wrong (first) item is always selected in the menu.

Update

I have found out why if you have a broken equals method the selectOne doesn't work. I'm at a loss to think why it is implimented like this but hey, I just use the thing. Anyway this is an extract from this thread:

Nope, there is no any default validators. You may check it out by calling getValidators method on the component instance. The only instance I've seen was my own validator that does nothing. I had the same problem before with selectOne component. And it was very hard to find the reason :-(

The problem is that JSF wants to make sure that selected items (beans actually) are members of collection returned by f:selectItems tag. I'm not sure if this is really necessary but anyways, after conversion of the bean value JSF will call equals on every element of the collection and the converted value. Usually, converter returns a new object so default implementation of equals method will always return false. JSF supposes that the converted bean is not a member of the list and displays that "Value is not valid" message. The simplest way to fix this is to override equals method of bean class, which is used in listbox.

Adverts

Donate and Help

Please support this site and
Bandwidth doesn't grow on trees y' know :o)

Adverts

Get Adsense