1 2 3 Previous Next 36 Replies Latest reply on Sep 18, 2006 3:56 AM by trouby Go to original post
      • 15. Re: Entities with one/many_to_many relationships and SEAM

        In my example, adding a flush between the merge and refresh seems to help a lot.

         group = new Group();
         group.setGroupname( newGroupname() );
         orgmobDatabase.persist( group );
         // User owns the bidirectional many-to-many relationship with Group
         user.getGroups().add( group );
         orgmobDatabase.merge( user );
         orgmobDatabase.flush();
         orgmobDatabase.refresh( group );


        Also, after some more reading persistence type PERSIST also seems more appropriate to my needs.

        • 16. Re: Entities with one/many_to_many relationships and SEAM
          pmuir

          Looks like you are on the right track with the persist-flush-refresh sequence. Yep, I think em.persist() would be more suitable.

          If User is the owner I doubt you want CascadeType.ALL on the Group's Set (which you have as Set which I suspect is a typo?). Perhaps a subset of ALL?

          Regarding updates, you can just update an entity, and, assuming cascade is on, it will be merged to the database at the next flush (explicit or implicit at transaction boundary).

          • 17. Re: Entities with one/many_to_many relationships and SEAM
            trouby

            Hey,

            Peter, back to this,

            I tried to use the additional code for multiple object selection, but for some reason I get the following error while trying to submit the form generated by JSF.

            'Conversion Error setting value '1,2' for '#{customer.addresses}'.


            while '1,2' are the IDs of the selected 'addresses' entity objects.


            Am I missing anything? seems like this error is generated by JSF itself, and not by the converters or the annotations you have written,



            thanks

            • 18. Re: Entities with one/many_to_many relationships and SEAM
              pmuir

              It looks to me like the EntityConverter isn't being used.

              Can you get the example multiple-select to work? Can you try and strip down your facelet to a minimum, check it still won't work, and post it? Are you using myfaces? If so what version, as I can't spot where that error mesage comes from (I'm assuming that the error comes from h:messages, do you have showDetail turned on?)?

              My converter throws a javax.faces.convert.ConverterException if something goes wrong, JSF then catches that and adds a FacesMessage. In eclipse you can add a breakpoint if a ConverterException is thrown and find out where this problem is originating.

              • 19. Re: Entities with one/many_to_many relationships and SEAM
                trouby

                Yeah,

                There was a little mistake, I used the 'EntityConverter' as for 'selectOneListbox' instead for the 'selectitems:convertEntity' tag,


                anyway, this is the error I get now:

                Conversion Error setting value 'root.entity.Note@105fece root.entity.Note@4f0638' for '#{issue.notes}'.
                



                Two options were selected, so it looks like each of the selected options converted to an entity via the converter but still there's a convertion error occures,


                As the setNotes method is straight forward, here it is:

                private Collection<Note> notes;
                public void setNotes(Collection<Note> notes) {
                 this.notes = notes;
                 }
                





                As always, thanks :)

                Asaf.

                • 20. Re: Entities with one/many_to_many relationships and SEAM
                  pmuir

                  Are you using myfaces? If so what version, as I can't spot where that error mesage comes from (I'm assuming that the error comes from h:messages, do you have showDetail turned on?)?

                  My converter throws a javax.faces.convert.ConverterException if something goes wrong, JSF then catches that and adds a FacesMessage. In eclipse you can add a breakpoint if a ConverterException is thrown and find out where this problem is originating.

                  • 21. Re: Entities with one/many_to_many relationships and SEAM
                    trouby

                    Hey,
                    really weird, I use Seam with GlassFish, and GF comes with JSF1.2RI,

                    It seems to be a native JSF error message..
                    Here's my JSF code:

                    
                    <h:selectManyListbox id="setnotes" size="10" value="#{issue.notes}" required="true">
                    <f:selectItems value="#{noteListForSelectbox}"/>
                    <selectitems:convertEntity entityClass="edentity.entity.Note"/>
                    </h:selectManyListbox>
                    
                    <span class="errors"><h:message for="setnotes" showDetail="true"/></span>
                    
                    



                    Anyway, I'm pretty sure that the SelectItem's code is not executed at all... :-/


                    Any ideas how to debug where it fails?

                    thanks a lot.

                    • 22. Re: Entities with one/many_to_many relationships and SEAM
                      trouby

                      Hey,
                      really weird, I use Seam with GlassFish, and GF comes with JSF1.2RI,

                      It seems to be a native JSF error message..
                      Here's my JSF code:

                      
                      <h:selectManyListbox id="setnotes" size="10" value="#{issue.notes}" required="true">
                      <f:selectItems value="#{noteListForSelectbox}"/>
                      <selectitems:convertEntity entityClass="edentity.entity.Note"/>
                      </h:selectManyListbox>
                      
                      <span class="errors"><h:message for="setnotes" showDetail="true"/></span>
                      
                      


                      One thing that i'm not sure about, In the html code, I see that the generated selectbox options look like this:
                      <selectitems:convertEntity entityClass="edentity.entity.Note"></selectitems:convertEntity><select id="j_id37:setnotes" name="j_id37:setnotes" multiple="multiple" size="10"> <option value="edentity.entity.Note@17585e9">Note1</option>
                      


                      Is this is how it should be? in none-multiple selectbox I see the ID as the value option.

                      thanks a lot.

                      • 23. Re: Entities with one/many_to_many relationships and SEAM
                        adam.stortz

                        I am having the same problem. Every time I submit, I get a validation error: j_id4:userGroups: Validation Error: Value is not valid

                        I am not using MyFaces, I am using JSF 1.2 reference impl.

                        I override the equals method on the Entity, which is never getting called. I don't think the conversion logic is getting called, because the objects are not getting instantiated after submitting the form. The page is getting redisplayed with the error above, with no other valuable output.

                        Any ideas?

                        Thanks!

                        • 24. Re: Entities with one/many_to_many relationships and SEAM
                          trouby

                          Hey back,

                          I just noticed that in web.xml there's no 'facelets.LIBRARIES' parameter for the selectItems tag lib, it also does not exist within the example,


                          After adding the library, it seems that 'getAsString' is executed in the EntityConverter and returns the ID of the entity, but nothing more,
                          in none-multiple selection, EntityConverter->'getEntity' is called to retrieve the entity itself, in multiple only getAsString is called and returns the ID of the entity,


                          then I of course get the converter error as:

                          Conversion Error setting value '1' for '#{issue.notes}'.
                          



                          Any clue? :)

                          Thanks


                          • 25. Re: Entities with one/many_to_many relationships and SEAM
                            pmuir

                            It seems that facelets behaves differently under myfaces/Glassfish, normally requisite libraries are implicitly loaded.

                            So, what you are saying is that for selectOne's it work's fine with the facelets tag (rather than converter=) but not for multiple select? The myfaces code for multiple select is a bit strange, so I suspect that in getting it to work for that I got it wrong for JSF 1.2.

                            When I have time I'll try to look at multiple-select-with-Glassfish.

                            Keep me informed of your progess :)

                            • 26. Re: Entities with one/many_to_many relationships and SEAM
                              pmuir

                              Adam, have you tried adding the facelets.LIBRARIES parameter to web.xml? Does the tag get printed out verbatim on your page as trouby wrote above? Or do you have that bit working now?

                              • 27. Re: Entities with one/many_to_many relationships and SEAM
                                adam.stortz

                                Pete,

                                I added facelets.LIBRARIES to my web.xml. This did not correct the problem.

                                No, the tag is not being printed out verbatim on the page. The interesting part of the resulting html looks like this: (This is after making multiple selections and submitting the page)

                                <form id="j_id4" name="j_id4" method="post" action="/unleashed/editBlogEntry.faces" enctype="application/x-www-form-urlencoded">
                                 <input type="hidden" name="j_id4:j_id5" value="0" /><table>
                                 <tbody>
                                 <tr>
                                 <td>Title</td>
                                 <td>
                                 <input id="j_id4:title" type="text" name="j_id4:title" value="Title" />
                                 </td>
                                 <td></td>
                                 </tr>
                                 <tr>
                                 <td>Body</td>
                                 <td>
                                 <textarea id="j_id4:body" name="j_id4:body" cols="30">
                                 Body
                                 </textarea>
                                 </td>
                                 <td></td>
                                 </tr>
                                 <tr>
                                 <td>User Groups</td>
                                 <td>
                                 <select id="j_id4:userGroups" name="j_id4:userGroups" multiple="multiple" size="5" size="5">
                                 <option value="1" selected="selected">User Group 1</option>
                                 <option value="2" selected="selected">User Group 2</option>
                                 </select>
                                 </td>
                                 <td>
                                 <span class="error">j_id4:userGroups: Validation Error: Value is not valid</span>
                                 </td>
                                 </tr>
                                 </tbody>
                                 </table>
                                 <input type="submit" name="j_id4:j_id14" value="Save" />
                                 <input type="hidden" name="javax.faces.ViewState" id="javax.faces.ViewState" value="really long messy string" />
                                 <input type="hidden" name="j_id4" value="j_id4" />
                                </form>
                                


                                When the page is submitted, none of my server side code is called.

                                Any thoughts?

                                • 28. Re: Entities with one/many_to_many relationships and SEAM
                                  trouby

                                  Petemuir, how things going?

                                  Well, yeah, seems like it doesnt work with JSF1.2,
                                  Damn, is there any work arounds for this?

                                  I dont think I have the skills to check why it fails with JSF1.2, especially when everthing I use is kinda compiled :)

                                  Well, is there any work arounds to use meanwhile? or some other ways to handle multiple assignments via seam which is easy enough to manage?


                                  Desparating, but that's life :q

                                  Thanks pal :)

                                  • 29. Re: Entities with one/many_to_many relationships and SEAM
                                    pmuir

                                    If you can convert the example included to use Glassfish/1.2 such that it deploys on JBoss (as installed by the JEMS installer) with 'ant deploy', and detail whether I need to alter anything in the JBoss setup I'll try to take a look. No promises on when though :(