This week's book giveaway is in the Design forum.
We're giving away four copies of Design for the Mind and have Victor S. Yocco on-line!
See this thread for details.
Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Atul Samnerkar
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2458
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is the scope of your managed bean?
 
alireza aghamohammadi
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic