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...
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?
What is wrong in my code? I hope you can help me.. Thanks!
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.
Blitzlügen - Lies or information broadcast, but when called out the broadcaster does little or nothing is done to correct them, thus allowing those who wish to believe to accept them as truth.
Lügensturm - A barrage of Blitzlügen fired in such quick succession that it is essentially impossible to correct them all.