aspose file tools*
The moose likes JSF and the fly likes Dynamic Select List - Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSF
Bookmark "Dynamic Select List - "Validation Error: Value is not valid"" Watch "Dynamic Select List - "Validation Error: Value is not valid"" New topic
Author

Dynamic Select List - "Validation Error: Value is not valid"

Atul Samnerkar
Ranch Hand

Joined: Sep 20, 2003
Posts: 44
Hi,

JSF does a partial validation of request parameters for <h:selectItems>. If you dynamically change the list of items in a <h:selectItems>, and you have a <h:selectManyListbox> with an existing value in the request that is invalid for the new
<h:selectItems>, then you will get a JSF error message: "Validation Error: Value is not valid"

Is there any solution for this? If yes, can anyone please send me the code snippet for the same?

Thanks,
Atul Samnerkar
Bauke Scholtz
Ranch Hand

Joined: Oct 08, 2006
Posts: 2458
You need to make sure that the list of selectitems is exactly the same during the apply request values phase (to process form submit) as it was during the render response of the previous request (to display form).

If the items are always the same (static), then it is fairly simple: just create the list in the constructor or static initialization block of the backing bean.

If the items dynamically depend on some key, then make sure that you pass that key so that it is known during the next request so that the getter of the list can return the same items based on that key.
Atul Samnerkar
Ranch Hand

Joined: Sep 20, 2003
Posts: 44
Hi Bauke,

Thanks for reply.

In this case, items dynamically get generated. Can you please elaborate on the solution? May be with the help of code snippet or pseudo code.

Thanks,
Atul Samnerkar
[ September 03, 2008: Message edited by: Atul Samnerkar ]
devi menon
Greenhorn

Joined: Sep 10, 2009
Posts: 1
Hi Atul,
I am also facing the same issue... did you get a solution to this problem yet? if so, could you please post it here? i would really appreciate it...
Thanks in advance!!!
alireza aghamohammadi
Greenhorn

Joined: May 12, 2010
Posts: 3
The error message 'value is not valid' is because of list box item sent to server does not exist or match in the items list box. Please see below example:


<!-- the jsf page -->

<h: outputText value="Select one of item only: "/>
<h:selectOneMenu value="#{testPageBean.yourdefaultNewValue}" id="test" required="true" onchange="submit()"
valueChangeListener="#{testPageBean.listListner}">

<f:selectItems value="#{testPageBean.allOfYourListItems}" />
</h:selectOneMenu>


/* the bean values and methods */

public void listListner(ValueChangeEvent event)
{
System.out.println("listListner");
/*make sure you use string for your list and the keys in your list box
if the new value that is selected does not have the same type or if the value does not exist in
your allOfYourListItems then you will get the "Validation Error: Value is not valid" error on your page
*/
yourdefaultNewValue = event.getNewValue().toString();

}
// * I'm assuming you have created your getter and setter properly too.

Good luck ,
Alireza Aghamohammadi

N Ha
Greenhorn

Joined: Jun 02, 2010
Posts: 9
alireza, I tried your solution but the error is thrown before getting to the listListner!
I have been into that for days now

Here is parts of my code
<h:selectManyListbox id="groups" value="#{customerController.selected.groups}">
<f:selectItems value="#{groupController.itemsAvailableSelectMany}"/>
</h:selectManyListbox>

In the GroupController
public List<SelectItem> getItemsAvailableSelectMany() {
List<SelectItem> groupList = new ArrayList<SelectItem>();
SelectItem[] selectItemsArray = JsfUtil.getSelectItems(ejbFacade.findAll(), false);
for (int i = 0; i < selectItemsArray.length; i++) {
Group group = (Group)selectItemsArray[i].getValue();
groupList.add(new SelectItem(group,group.getName()));
}
return groupList;
}

any help?
alireza aghamohammadi
Greenhorn

Joined: May 12, 2010
Posts: 3
selectManyListbox is very different from selectOneMenu ! Please let me know the followings and I may be able to provide some help

a. version and type of browser
b. version of java faces

Alireza Aghamohammadi
N Ha
Greenhorn

Joined: Jun 02, 2010
Posts: 9
a. IE 8.0 (though I don't understand what does it have to do with the browser?)
b. JSF 2.0

and I'm using GlassFish 3.0 server

If you have a working example for a dynamic populated ManySelectBox, it would be great

I have two entities @Customer and @Group
They have a Many to Many relationship between them
so the Customer Entity has a List of Groups ----> Set<Group> groups;
and the Group Entoty has a List of Customer ----> Set<Customer> customers;

When I try to assign Groups to Customers, it gives me this exception
Thang Pham
Ranch Hand

Joined: Jan 21, 2009
Posts: 35
What is the scope of your managed bean?
alireza aghamohammadi
Greenhorn

Joined: May 12, 2010
Posts: 3
ok here is an example, I hope this helps: (Sorry for not getting back to you any sooner, I have been very busy)






good luck,
Alireza Aghamohammadi
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Dynamic Select List - "Validation Error: Value is not valid"
 
Similar Threads
Can I supply a Bean in selectItem.setValue()?
ajax server-side validation
Doubt in h:selectItems
JSF prevents custom validator from getting control
On Drop Down Error summary=(j_id52:txtascedNarow: Validation Error: Value is not valid)