1 2 3 Previous Next 31 Replies Latest reply on Nov 27, 2006 7:20 AM by newlukai Go to original post
      • 15. Re: Challenge: Simple Example Adding Records With Lookup Dro

        Hmm. OK. Yesterday I searched around the web for possibilities to handle a ManyToOne-releationship in a dropdown-box. And I think that your http://wiki.jboss.org/wiki/Wiki.jsp?page=SeamSelectItemsNewDesign offers all the things I need with a great usability.

        But I think there should be a guideline or an explanation on how to use it, step-by-step.

        • 16. Re: Challenge: Simple Example Adding Records With Lookup Dro

          I'm trying to use <si:selectItems> and I followed all the hints in the example, but I still get an exception:

          java.lang.NullPointerException
           at org.jboss.seam.core.Messages$1.get(Messages.java:51)
           at org.jboss.seam.core.Messages$1.get(Messages.java:79)
           at org.jboss.seam.selectitems.jsf.SelectItemsConverter.getMessage(SelectItemsConverter.java:74)
           at org.jboss.seam.selectitems.jsf.EntityConverter.loadEntityFromPersistenceContext(EntityConverter.java:122)
           at org.jboss.seam.selectitems.jsf.EntityConverter.convertToObject(EntityConverter.java:48)
           at org.jboss.seam.selectitems.jsf.SelectItemsConverter.getAsObject(SelectItemsConverter.java:52)
           at org.apache.myfaces.shared_impl.renderkit.RendererUtils.getConvertedUIOutputValue(RendererUtils.java:651)
           at org.apache.myfaces.shared_impl.renderkit.html.HtmlMenuRendererBase.getConvertedValue(HtmlMenuRendererBase.java:111)
           at javax.faces.component.UIInput.getConvertedValue(UIInput.java:395)
           at javax.faces.component.UIInput.validate(UIInput.java:349)
           at javax.faces.component.UIInput.processValidators(UIInput.java:183)
           at javax.faces.component.UIForm.processValidators(UIForm.java:70)
           at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:624)
           at javax.faces.component.UIViewRoot.processValidators(UIViewRoot.java:146)
           at org.apache.myfaces.lifecycle.LifecycleImpl.processValidations(LifecycleImpl.java:262)
           at org.apache.myfaces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:76)
           at javax.faces.webapp.FacesServlet.service(FacesServlet.java:137)
           at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
           at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
           at org.apache.myfaces.webapp.filter.ExtensionsFilter.doFilter(ExtensionsFilter.java:97)
           at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
           at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
           at org.apache.myfaces.webapp.filter.ExtensionsFilter.doFilter(ExtensionsFilter.java:144)
           at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
           at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
           at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
           at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
           at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
           at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
           at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
           at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:175)
           at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:74)
           at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
           at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
           at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
           at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
           at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:869)
           at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:664)
           at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
           at org.apache.tomcat.util.net.MasterSlaveWorkerThread.run(MasterSlaveWorkerThread.java:112)
           at java.lang.Thread.run(Thread.java:595)


          It seems that during validation the converter can't get a message. So I think I didn't setup your jars (1.1.1beta2) properly.

          I placed the two jars to the \WEB-INF\lib directory of my war and included them in the Class-Path entry of the manifest for the war. Do I have to do something else?

          • 17. Re: Challenge: Simple Example Adding Records With Lookup Dro
            pmuir

            What version of Seam?

            • 18. Re: Challenge: Simple Example Adding Records With Lookup Dro

              It's 1.0.1 GA on a AS 4.0.4 Patch1.

              • 19. Re: Challenge: Simple Example Adding Records With Lookup Dro
                pmuir

                Ok, I've put up a new zip, same version no, with (I hope) a fix. I wasn't able to replicate your problem (I'm using 1.1.0.CR1) so let me know.

                • 20. Re: Challenge: Simple Example Adding Records With Lookup Dro

                  Yeah, it works. Thanks!

                  Now I've got the real error message: Cannot access entityManager; ensure persistenceUnitJndiName is set on SelectItemsConfig class in components.xml

                  So I've to set the JNDIName. But to which value? I didn't have a components.xml before I used si:selectItems. I set it to the jta-data-source I defined in persistence.xml:

                  <persistence>
                   <persistence-unit name="aresDatabase">
                   <provider>org.hibernate.ejb.HibernatePersistence</provider>
                   <jta-data-source>java:/aresDatasource</jta-data-source>
                  ... rest omitted ...


                  But it didn't work.

                  • 21. Re: Challenge: Simple Example Adding Records With Lookup Dro
                    pmuir

                    Ok, so the EntityConverter requires access to an EntityManager to load objects. Just set this as you would set up an EntityManager for Seam -

                    <component name="em" class="org.jboss.seam.core.ManagedPersistenceContext">
                     <property name="persistenceUnitJndiName">java:/selectItemsEntityManagerFactory</property>
                     </component>
                    
                     <component class="org.jboss.seam.selectitems.SelectItemsConfig">
                     <property name="persistenceUnitJndiName">java:/selectItemsEntityManagerFactory</property>
                     </component>




                    • 22. Re: Challenge: Simple Example Adding Records With Lookup Dro
                      pmuir

                      So in persistence.xml you need to define

                      <property name="jboss.entity.manager.factory.jndi.name" value="java:/selectItemsEntityManagerFactory"/>


                      And use the value of this as the value of the persistenceUnitJndiName

                      • 23. Re: Challenge: Simple Example Adding Records With Lookup Dro
                        pmuir

                        Btw. regarding your comment on a step-by-step guide, if you feel like writing up how you got SeamSelectItems up and running, I'll quite happily edit it and include it in the wiki page.

                        • 24. Re: Challenge: Simple Example Adding Records With Lookup Dro

                          Ah. OK. I didn't set this value in persistence.xml.
                          What does this property do? I try to explain it for my own: In persistence.xml I'm setting up how to connect the database. Whit the property you mentioned I give it a JNDI name?!? And this JNDI name is the value that is needed by the SelectItemsConfig. Right?

                          BTW: I just use the annotation @PersistenceContext(name="aresDatabase") to inject the EntityManager in each component that needs the EntityManager. I saw some guys using only the @In annotation. Why does it work for them? Does it have to do with the org.jboss.seam.core.ManagedPersistenceContext property in components.xml?

                          Where do I find more to read on this topic?

                          • 25. Re: Challenge: Simple Example Adding Records With Lookup Dro

                            *dancing on my desk*

                            It works ...
                            I'v full access on all the columns entity B and entity A have. And I can choose an entity B from a dropdown to save in entity A.

                            It's just great.

                            Thank you Mr Muir.

                            • 26. Re: Challenge: Simple Example Adding Records With Lookup Dro
                              pmuir

                               

                              <property name="jboss.entity.manager.factory.jndi.name" value="..."/>

                              causes jboss to publish an EntityManagerFactory in JNDI for this PersistenceContext. As I mentioned above EntityConverter requires access to your EntityManager. You tell SelectItemsConfig the name under which the EntityManagerFactory is published in JNDI, the EntityConverter can then do a JNDI lookup for this factory, and thus create an EntityManager. SelectItemsConfig is just a simple bean which can be configured by components.xml and then read by the various other classes (which aren't Seam components so can't be configured by components.xml directly)

                              If you want to @In your EntityManager you need to configure a Seam Managed Persistence Context, this is covered in the reference manual. http://docs.jboss.com/seam/1.1CR1/reference/en/html/configuration.html#d0e6249

                              • 27. Re: Challenge: Simple Example Adding Records With Lookup Dro

                                I've got an appointment so I quickly wrote down what I've done:

                                1. Download selectitems.jar and selectitems-ui.jar.

                                2. Place them in WEB-INF/lib of your war file.

                                3. Add following property to your persistence.xml:

                                <property name="jboss.entity.manager.factory.jndi.name" value="java:/selectItemsEntityManagerFactory"/>


                                4. Add following entry to your components.xml:
                                <component class="org.jboss.seam.selectitems.SelectItemsConfig">
                                 <property name="persistenceUnitJndiName">java:/selectItemsEntityManagerFactory</property>
                                 </component>

                                As you might guess the property has to be the same value you set in persistence.xml.

                                5. Now you can establish the relationships between your entities using @OneToOne and so on. (Don't forget to adjust getters and setters)
                                6. The method which outjected the SelectItems can now be rewritten to outject an list containing the entities.

                                7. Use <si:selectItems> to retrive the entities. With attribute "label" you can define the label shown on each row.

                                To use si you have to include
                                xmlns:si="http://jboss.com/products/seam/selectitems/taglib" and xmlns:s="http://jboss.com/products/seam/taglib"

                                You have to use attributes Value, var and label.

                                • 28. Re: Challenge: Simple Example Adding Records With Lookup Dro
                                  pmuir

                                  Thanks, I've added that to wiki page

                                  • 29. Re: Challenge: Simple Example Adding Records With Lookup Dro

                                    No problem.

                                    But ... erm ... I've another question: In my application there is a table which contains priorities. The table contains two columns: the ID and the description of the priority. On some pages the user can filter all shown entries by priority. Adding a noSelectionLabel the user has also the option to disable the filtering.

                                    But now the user should be able to filter for priorities greater or less than a distinct value, say 3. So I want to add two further rows in the si:selectItems which have this special meaning. I know that the EntityConverter can't handle rows, which are created in my bean and not persisted in the database.
                                    So I think the best solution would be a custom converter which handles the special meanings and invokes the EntityConverter for all the other cases.
                                    Is that possible?

                                    Has to be something like this (got it from the wiki):

                                    public Converter getPriorityConverter() {
                                     return new PriorityConverter<Priority>() {
                                    
                                     protected Object getIdAsObject(String id, Class clazz) {
                                     int priority = Integer.parseInt(id);
                                     if(priority == -2) return SpecialPriorities.GREATER_3;
                                     if(priority == -3) return SpecialPriorities.LESS_3;
                                     Converter entityConverter = new EntityConverter();
                                     return entityConverter.getIdAsObject(id, clazz);
                                     }
                                    
                                     protected String getIdAsString(Priority entity) {
                                     return entity.getId() + " (" + entity.getDescription() + ")";
                                     }
                                     };
                                    }