• Post Reply Bookmark Topic Watch Topic
  • New Topic

Validation Error: Value is not valid

 
Federico Minarelli
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello everybody! I am new both to JSF and JPA and hope you can help me with a problem I couldn't solve even after several hours of debugging and google searches..

I have 2 entities which are in a ManyToMany relationship:


They model the fact that a TestRun can be associated with several trackers (and viceversa).

I then have 2 Managed Beans (generated by NetBeans 7.0) called respectively TestRunController and TrackerController: each such bean has an aggregation to an Entity. I show here the relevant code for just one of them, as they are almost identical:



I added into the DB a couple of Trackers and finally created a Facelet for the insertion of a TestRun. This facelet uses a selectManyCheckbox which should allow to choose which trackers are associated with a testrun:


The form gets properly created and displayed and I am even able to create a TestRun record when I don't select any Tracker. But as soon as I select a Tracker, I get the error "Validation Error: Value is not valid" (I think this should correspond to javax.faces.component.UISelectMany.INVALID).

I read in internet (and in this forum as well) that this problem is sometimes connected with a missing overriding of equals(), but this should not be my case... Furthermore, I noticed (while debugging) that such method gets never invoked after the form is sent. The same happens with TrackerControllerConverter#getAsObject(), which according to several posts should be another cause for the problem...

I am relly confused and hope you can help me..

Bye and... THANKS!
 
Federico Minarelli
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
any idea? I am getting really crazy with this problem...
I have tried to re-create a simplified version of the project from scratch in Netbeans:

1) New Web application project.
2) I have created 2 entities "TestRun" and "Tracker". For TestRun.java I typed the following code:

And in Tracker.java:


I then generated automatically getters and setters for both. Then I right clicked my project: "new-> JSF Pages from entity classes..", I choosed my 2 entities and I got some a lot of staff free.
In testRun/create.xhtml the form looks now (after adding a couple of lines of code) like this:


getItemsAvailableSelectMany returns a list of SelectItems which is built from the DB:


I started the app, added 2 Trackers (no problems) and then tried to add a TestRun with an associated tracker. The result?


of course..

What is wrong in my code? I hope you can help me.. Thanks!
Bye
 
Tim Holloway
Bartender
Posts: 18408
58
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's hard to say for sure here. But I recommend that rather than fetching the selectitem list from persistent storage each time the View needs it, cache a copy and use that copy instead:




The selectItem list must be in View scope or higher for best results. Also, you'll find debugging this kind of stuff easier if you put an explicit id property on your input control, since the system-generated ids are often difficult to match up to the offending control.

If the caching strategy I listed fixed things it's because you had a mismatch on SelectItem identities even though the underlying values might be OK. At any rate, it's less overhead and eliminates possible issues having to do with non-repeatable reads.
 
Federico Minarelli
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi!

Thanks for your suggestion Tim.. Unfortunately the solution to the problem was another.. I solved it after reading here: http://download.oracle.com/javaee/6/api/javax/faces/component/UISelectMany.html and here: http://stackoverflow.com/questions/3822058/jsf-2-0-use-enum-in-selectmany-menu/3823776#3823776. In short, i needed to explicitly define a converter for my selectManyCheckbox:




 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!