1 2 Previous Next 27 Replies Latest reply on Jun 4, 2008 9:56 PM by nickarls Go to original post
      • 15. Re: s:selectItems and s:convertEntity
        stereoscope

        <?xml version="1.0" encoding="UTF-8"?>
        <components xmlns="http://jboss.com/products/seam/components"
                    xmlns:core="http://jboss.com/products/seam/core"
                    xmlns:persistence="http://jboss.com/products/seam/persistence"
                    xmlns:drools="http://jboss.com/products/seam/drools"
                    xmlns:bpm="http://jboss.com/products/seam/bpm"
                    xmlns:security="http://jboss.com/products/seam/security"
                    xmlns:mail="http://jboss.com/products/seam/mail"
                    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                    xsi:schemaLocation=
                        "http://jboss.com/products/seam/core http://jboss.com/products/seam/core-2.0.xsd 
                         http://jboss.com/products/seam/persistence http://jboss.com/products/seam/persistence-2.0.xsd 
                         http://jboss.com/products/seam/drools http://jboss.com/products/seam/drools-2.0.xsd
                         http://jboss.com/products/seam/bpm http://jboss.com/products/seam/bpm-2.0.xsd
                         http://jboss.com/products/seam/security http://jboss.com/products/seam/security-2.0.xsd
                         http://jboss.com/products/seam/mail http://jboss.com/products/seam/mail-2.0.xsd
                         http://jboss.com/products/seam/components http://jboss.com/products/seam/components-2.0.xsd">
        
           <!-- The components.xml file helps seam to find EJB componenet in JNDI  -->
        
           <core:init debug="@debug@" jndi-pattern="@jndiPattern@"/>
             
           <core:manager concurrent-request-timeout="500" 
                         conversation-timeout="120000" 
                         conversation-id-parameter="cid"/>
            
           <persistence:managed-persistence-context name="entityManager"
                                             auto-create="true"
                                                   persistence-unit-jndi-name="java:/MashupEntityManagerFactory"/>                          
        
           <drools:rule-base name="securityRules">
               <drools:rule-files>
                   <value>/security.drl</value>
               </drools:rule-files>
           </drools:rule-base>
        
           <security:identity security-rules="#{securityRules}" authenticate-method="#{authenticator.authenticate}" remember-me="true"/>
           
           <event type="org.jboss.seam.security.notLoggedIn">
               <action execute="#{redirect.captureCurrentView}"/>
           </event>
           <event type="org.jboss.seam.security.loginSuccessful">
               <action execute="#{redirect.returnToCapturedView}"/>
           </event>
           
           <mail:mail-session host="localhost" port="2525" username="test" password="test" />
           
           <component name="org.jboss.seam.ui.EntityConverter">
                     <property name="entityManager">#{em}</property>
           </component>
           
           <!-- For use with jBPM pageflow or process management -->
           <!--  
           <bpm:jbpm>
              <bpm:process-definitions></bpm:process-definitions>
              <bpm:pageflow-definitions></bpm:pageflow-definitions>
           </bpm:jbpm>
           -->
              
        </components>
        


        • 16. Re: s:selectItems and s:convertEntity
          nickarls

          try


          @In private EntityManager entityManager;

          • 17. Re: s:selectItems and s:convertEntity
            stereoscope

            man nicklas thanks ... i got it ! i reread your post about the @IN thing and then thought about the compnents.xml and well it's working !


            i messing around with this quite a while and now it's working thats awesome.


            but tell why does it work with @in and not with @persistence context!?


            cheers

            • 18. Re: s:selectItems and s:convertEntity

              The name of your Entitymanager is 'entityManager'.
              The stuff I posted should then be


              <component name="org.jboss.seam.ui.EntityConverter">
                 <property name="entityManager">#{entityManager}</property>
              </component> 
              



              if needed at all.

              • 19. Re: s:selectItems and s:convertEntity

                Fritz: I think Nicklas deserves some stars for his efforts :-)

                • 20. Re: s:selectItems and s:convertEntity
                  nickarls

                  Umm, can't remember. Probably something with lazy loading and object identity in multiple entity manager instances...

                  • 21. Re: s:selectItems and s:convertEntity
                    nickarls

                    Only 150 or so and I get past Pete!!1! ;-)


                    Friday and the sun is shining, off I go...

                    • 22. Re: s:selectItems and s:convertEntity
                      stereoscope

                      Actually all of deserve some stars !
                      Thanks guys ... but as ussual it't wont be the last time we heard something from each other!



                      cheers

                      • 23. Re: s:selectItems and s:convertEntity
                        vikram.vikram.chhetry.gmail.com

                        Hi,
                        I am also facing some what same problem. I went thru all the posts here and made changes accordingly but cudnt succeed.


                        Posting My COde:


                        public void loadUserMasterList() {
                                        // fetch collection of CompanyType
                                        Collection<UserMaster> list = tenantEntityManager.createQuery(
                                                        "select object(sm) from UserMaster sm order by sm.iuserId")
                                                        .getResultList();
                                        // Iterate collection
                                        for (UserMaster ShipMaster : list) {
                                                // add SelectItem object to list
                                                userMasterList.add(new SelectItem(UserMaster.getIuserId(),
                                                                UserMaster.getStrShipName()));
                                        }
                                }
                        





                        <h:selectOneMenu value="#{dd.userMaster}">
                                <s:selectItems value="#{manageDD.userMasterList}" var="user"
                                        label="#{user.strName}"
                                        noSelectionLabel="#{messages.defaultListItem}" />
                                <s:convertEntity />
                        </h:selectOneMenu>
                        




                        components.xml



                        <persistence:filter name="tenantFilter">
                                        <persistence:name>tenantFilter</persistence:name>
                                        <persistence:parameters>
                                                <key>tenantId</key>
                                                <value>#{tenantId}</value>
                                        </persistence:parameters>
                                </persistence:filter>
                        
                                <persistence:managed-persistence-context name="tenantEntityManager"
                                        auto-create="true"
                                        persistence-unit-jndi-name="java:/DDEntityManagerFactory">
                                        <persistence:filters>
                                                <value>#{tenantFilter}</value>
                                        </persistence:filters>
                                </persistence:managed-persistence-context>
                        
                        
                        
                                <component name="org.jboss.seam.ui.entityConverter">
                                        <property name="entityManager">#{em}</property>
                                </component>
                        
                        



                        when I try to load the page it says



                        Property 'strName' not found on type javax.faces.model.SelectItem


                        I dont have any idea how to solve this.


                        Any help would be appreciated.


                        Thanks,


                        Vikram

                        • 24. Re: s:selectItems and s:convertEntity
                          vikram.vikram.chhetry.gmail.com

                          Hi,
                          Sorry for the re post.
                          I am also facing some what same problem. I went thru all the posts here and made changes accordingly but cudnt succeed.


                          Posting My COde:


                          public void loadUserMasterList() {
                                          // fetch collection of CompanyType
                                          Collection<UserMaster> list = tenantEntityManager.createQuery(
                                                          "select object(sm) from UserMaster sm order by sm.iuserId")
                                                          .getResultList();
                                          // Iterate collection
                                          for (UserMaster ShipMaster : list) {
                                                  // add SelectItem object to list
                                                  userMasterList.add(new SelectItem(UserMaster.getIuserId(),
                                                                  UserMaster.getStrShipName()));
                                          }
                                  }
                          





                          <h:selectOneMenu value="#{dd.userMaster}">
                                  <s:selectItems value="#{manageDD.userMasterList}" var="user"
                                          label="#{user.strName}"
                                          noSelectionLabel="#{messages.defaultListItem}" />
                                  <s:convertEntity />
                          </h:selectOneMenu>
                          




                          components.xml



                          <persistence:filter name="tenantFilter">
                                          <persistence:name>tenantFilter</persistence:name>
                                          <persistence:parameters>
                                                  <key>tenantId</key>
                                                  <value>#{tenantId}</value>
                                          </persistence:parameters>
                                  </persistence:filter>
                          
                                  <persistence:managed-persistence-context name="tenantEntityManager"
                                          auto-create="true"
                                          persistence-unit-jndi-name="java:/DDEntityManagerFactory">
                                          <persistence:filters>
                                                  <value>#{tenantFilter}</value>
                                          </persistence:filters>
                                  </persistence:managed-persistence-context>
                          
                          
                          
                                  <component name="org.jboss.seam.ui.entityConverter">
                                          <property name="entityManager">#{em}</property>
                                  </component>
                          
                          



                          when I try to load the page it says



                          Property 'strName' not found on type javax.faces.model.SelectItem


                          I dont have any idea how to solve this.


                          Any help would be appreciated.


                          Thanks,


                          Vikram

                          • 25. Re: s:selectItems and s:convertEntity

                            You have completely misunderstood s:selectItems. It should not contain SelectItem objects.


                            Your userMasterList should contain UserMaster objects and not SelectItem object. Now you put selectitems in the list and s:selectItems tries to get strName from the SelectItem, which doesn't exist.


                            Fill your userMasterList with UserMaster and override equals/hashcode in the UserMaster class.

                            • 26. Re: s:selectItems and s:convertEntity
                              vikram.vikram.chhetry.gmail.com

                              Hi Daniel,


                              Thanks for the quick reply.


                              After reading all the posts I understood what it is and made changes as suggested but cudnt suceed so i rolled my code back and posted it here.


                              I just want to know id this is a right way of overridding.



                                   @Override
                                   public boolean equals(Object obj) {
                                        if (obj == null)
                                             return false;
                                        else if (!(obj instanceof UserMaster))
                                             return false;
                                        else if (((UserMaster) obj).getIuserId().equals(this.iuserId))
                                             return true;
                                        else
                                             return false;
                                   }
                              
                                   @Override
                                   public int hashCode() {
                                        int result = 17;
                              
                                        result = 37 * result + (int) this.getIuserId().intValue();
                                        return result;
                                   }
                              




                              I will try doing it again but before that I have a question.


                              My userMaster list comes from filtered entity manager that is tenantEntityManager. Do I need to make my own conveter? If yes the how do I create coverter for this?

                              • 27. Re: s:selectItems and s:convertEntity
                                nickarls

                                Check out usage of s:convertEntity in section Table 28.1. Seam JSF Control Reference for non-standard-entityManagers

                                1 2 Previous Next