Saturday, August 29, 2009

richfaces pickList - validation error

A common error when using pickList is a "Value is not valid" error.

One reason for this is that the selectItem list does not contain one of the selected values. This happens often when you try to created a pre-selected list.

For example, suppose your selectItems are: A, B, C, D, E
And A & B are already selected.

This means that when the pickList is shows, you want A & B to appear in the right side, and you want C, D, E to appear on the left side.

What you need to do is put all five - A, B, C, D & E in the selectItems list (left side list).
Then in the list which will hold the selected items (right side list - the one that you will bind to the value attribute of the picklist), you need to put the select Item value of A & B.

richfaces will automatically show A & B on the right and C, D, E on the left.

However, if you put A & B in the right side list, and pnly C, D, E in the left side list - you will get a value is not valid error!


Secondly, remember that if your value is a non-String object, then you need to override the "equals" method in your Object class.

1 comment:

  1. Hi.... i'm having the value is not valid error as well... may i know what do u mean by "bind to the value attribute of the picklist" ??? because i have values which are supposed to be display on the right-hand-side but failed to do so....kept getting this - "Value is not String (class=javax.faces.model.SelectItem, value=javax.faces.model.SelectItem@1b30ebb)" ... Hope u can guide me along... ;)

    ReplyDelete