9 Replies Latest reply on Oct 11, 2009 9:38 PM by Pietro M.

    How to read and show a table

    Pietro M. Newbie

      Hi,
      unfortunately for work I have to use SEAM to make a web application.
      What I need is to have a controller that reads a list of elements from a table and displays them on an ICEFaces Datatable in the view.


      The table I need to read is called Sperimentazione and contains two elements.


      Here is my attempt:
      -CONTROLLER :

      @Name("SperimentazioneList")
      @Scope(ScopeType.EVENT)
      public class SperimentazioneList extends EntityQuery<Sperimentazione>
      {
              private static final String SQLQuery = "SELECT sperimentazione FROM Sperimentazione sperimentazione";
              private static final long serialVersionUID = 7598286873082408222L;
             
              @DataModel
              List<Sperimentazione> sperimentazioni;
             
              public SperimentazioneList() {
              }
             
              @Factory("sperimentazioni")
          public void getSperimentazioni() {
              setEjbql(SQLQuery);
              sperimentazioni = getResultList();
          }
      }


      -VIEW :
      <ui:define name="body">
              <ice:dataTable var="_sperimentazione" value="#{SperimentazioneList.sperimentazioni}">
                      <ice:columns binding="#{_sperimentazione.id}"/>
              </ice:dataTable>
      </ui:define>


      And here is what I get (SEAM Debug page error):
      Caused by javax.el.PropertyNotFoundException with message: "/home.xhtml @19,50 binding="#{_sperimentazione.id}": Target Unreachable, identifier '_sperimentazione' resolved to null"


      Please, I'm desperate... SEAM is so hard to use and so developer-unfriendly that I've already wasted one week getting nowhere.
      Thank you.

        • 1. Re: How to read and show a table
          xsa lefter Newbie

          Hi Pietro.. Seam is great if you know exactly how its work. I used it in my project all of my developer getting production in fast with zero knowledge about JSF, JPA, EJB3, and even Dependency Injection (after all they only know about Java SE and JSP). May their code worst but it happen because some of crazy-unpredictable requirement (non technical issues) everyday and all the day.


          Refer to your problem, may your error happen because you use #{SperimentazioneList.sperimentazioni} instead of #{sperimentazioni}. You need to use #{sperimentazioni} in your datatable value because you marked it with @Factory.


          But it's better to just use a #{SperimentazioneList.resultList}, move your setEjbql(SQLQuery) to the constructor and remove all unnecessary method since your controller is extended from EntityQuery, the EntityQuery provide out of the box for the common thing.


          By the way if you a new to seam, please learn and use a seam-gen and learn seam from generated code.


          Perhaps my solution help. Sorry for my bad english.

          • 2. Re: How to read and show a table
            xsa lefter Newbie

            .... I used it in my project all of my developer getting production in fast ....


            Sorry, typo, and because this forum not allowed me to edit my post, this is my correction: I used it in my project and all of my developer getting production in a week.

            • 3. Re: How to read and show a table
              Pietro M. Newbie

              Thank you very much for your quick reply.
              I tried to do as you suggested (deleted @Factory, moved setEjbql to constructor and changed the view to reference SperimentazioneList.resultList), but I still got the same error.



              "I used it in my project and all of my developer getting production in a week".


              I used it in my project all of my developer getting production in fast with zero knowledge about JSF, JPA, EJB3, and even Dependency Injection (after all they only know about Java SE and JSP).

              One week in production with zero knowledge?! How did you do?
              I started ten days ago with the same level of knowledge (no JSF, JPA, EJB3, Facelets and so on -- only Java) and after reading 280 pages of Seam In Action and some examples and seam-gen automatically generated code, I feel I don't know what I'm doing.


              Do you have some resources/references/tutorials (for dummies) to get a quick and complete (preferably quick) understanding of Seam to get into production?
              If so - please! - let me know. It seems to me that SEAM is everything but developer-friendly... (maybe I'm dumb, it's possible)

              • 4. Re: How to read and show a table
                xsa lefter Newbie

                Pietro M. wrote on Oct 10, 2009 20:32:


                Thank you very much for your quick reply.
                I tried to do as you suggested (deleted @Factory, moved setEjbql to constructor and changed the view to reference SperimentazioneList.resultList), but I still got the same error.


                Please write your view, entity, and controller here. Hope with nice formatting.





                One week in production with zero knowledge?! How did you do?

                Well, I create the project using seam-gen and generate all the views and the controllers depend on the entities, and If they getting some errors I tell them how to fix it.




                Do you have some resources/references/tutorials (for dummies) to get a quick and complete (preferably quick) understanding of Seam to get into production?

                Seam Reference and Seam In Action is enough. But if you really place your self with zero condition and no one to help you a place, may you need more research and try and error. If so, you can start from creating the database table first, use a seam-gen to generate seam project, and use command seam generate to generate all the entities based on the table, controllers, and the views. Then learn how it works.


                Hope this help, and happy coding.. :).

                • 5. Re: How to read and show a table
                  Damian Harvey Apprentice

                  A little formatting goes a long way (although forum edit would help too) :




                  @Name("SperimentazioneList") 
                  @Scope(ScopeType.EVENT) 
                  public class SperimentazioneList extends EntityQuery<Sperimentazione> { 
                    
                    private static final String SQLQuery = "SELECT sperimentazione FROM Sperimentazione sperimentazione"; 
                  
                    private static final long serialVersionUID = 7598286873082408222L; 
                  
                    @DataModel List<Sperimentazione> sperimentazioni; 
                    public SperimentazioneList() { } 
                  
                    @Factory("sperimentazioni") 
                    public void getSperimentazioni() { 
                      setEjbql(SQLQuery); 
                      sperimentazioni = getResultList(); 
                    } 
                  }



                  <ui:define name="body">
                    <ice:dataTable var="_sperimentazione" value="#{SperimentazioneList.sperimentazioni}">
                      <ice:columns binding="#{_sperimentazione.id}"/>  
                    </ice:dataTable> 
                  </ui:define>



                  IMO Seam is very easy to use. You just need to understand some very logical things. Expression Language (EL) allows you to specify something like

                  #{SperimentazioneList.sperimentazioni}

                  and in Seam terms this means find me something in a context (session/conversation/page/request) with the name SperimentazioneList and call the getSperimentazioni() method on it.


                  Your getSperimentazioni() method returns void. So when your table calls this method it is returned nothing rather than the list of objects that you expected. Read the Seam Reference for details on how to use the @Factory in the way that you were trying to. As Xsa has said, you want to use #{sperimentazioni} as your table value.


                  That is one problem. Your other problem seems to be that you don't understand how the Icefaces columns component works. Have you read the Iceface Columns Component Tutorial? It would appear that all you are missing is changing your binding attribute to a value. Binding is used when you will be providing the component itself from the backing bean (ie. rather than configuring via attributes etc you just build the component in Java), rather than providing the list that supplies the component.


                  Also, think about what you are trying to return with #{_sperimentazione.id}. So thinking about EL as above, this will call Sperimentazione.getId(). Given that the columns component expects a DataModel, is this what you intend?


                  Hope this helps.


                  Cheers,


                  Damian.



                  • 6. Re: How to read and show a table
                    Pietro M. Newbie

                    Thank you again Xsa and thank you Damian, too.
                    I made the get metod return the list, as you told me, and that luckily made the error go away:


                    @Name("SperimentazioneList")
                    @Scope(ScopeType.EVENT)
                    public class SperimentazioneList extends EntityQuery<Sperimentazione>
                    {
                         private static final String EJBQuery = "SELECT sperimentazione FROM Sperimentazione sperimentazione";
                         private static final long serialVersionUID = 7598286873082408222L;
                         
                         @DataModel
                         List<Sperimentazione> sperimentazioni;
                         
                         public SperimentazioneList() {
                             setEjbql(EJBQuery);
                             sperimentazioni = getResultList();
                         }
                         
                         public List<Sperimentazione> getSperimentazioni() {
                              return getResultList();
                         }
                    }



                    As you may notice I've removed the @Factory to simplify things.
                    But the page still doesn't display anything.
                    This is the view:


                         <ice:dataTable var="_sperimentazione" value="#{SperimentazioneList.resultList}">
                              <ice:columns value="#{sperimentazioni}"/>
                         </ice:dataTable>
                    



                    I saw your link to the ICEFaces tutorial, but that doesn't help me because it doesn't show how to use SEAM annotations to provide the ICEFaces component what it needs.


                    I'm sorry. I can't get it. Call me stupid, but I'm on the brink of losing sanity.
                    Could you please provide me a working solution?
                    Thank you.


                    • 7. Re: How to read and show a table
                      Pietro M. Newbie

                      I find out how to make it work. Don't know if it is the best solution, but at least it works now:



                      @Name("SperimentazioneList")
                      @Scope(ScopeType.EVENT)
                      public class SperimentazioneList extends EntityQuery<Sperimentazione>
                      {
                           private static final String EJBQuery = "SELECT sperimentazione FROM Sperimentazione sperimentazione";
                           private static final long serialVersionUID = 7598286873082408222L;
                           
                           @DataModel
                           List<Sperimentazione> sperimentazioni;
                           
                           public SperimentazioneList() {
                               setEjbql(EJBQuery);
                               sperimentazioni = getResultList();
                           }
                           
                           public List<Sperimentazione> getSperimentazioni() {
                                return sperimentazioni;
                           }
                      }
                      



                           <ice:dataTable var="_sperimentazione" value="#{SperimentazioneList.sperimentazioni}">
                                <ice:column style="background-color: gray">
                                     <f:facet name="header"><ice:outputText value="id"/></f:facet>
                                     <ice:outputText value="#{_sperimentazione.id}"/>
                                </ice:column>
                                <ice:column>
                                     <f:facet name="header"><ice:outputText value="idAmministrativo"/></f:facet>
                                     <ice:outputText value="#{_sperimentazione.idAmministrativo}"/>
                                </ice:column>
                                <ice:column>
                                     <f:facet name="header"><ice:outputText value="Tipo di sperimentazione"/></f:facet>
                                     <ice:outputText value="#{_sperimentazione.clsSperimentazione.tipo}"/>
                                </ice:column>
                                <ice:column>
                                     <f:facet name="header"><ice:outputText value="Descrizione"/></f:facet>
                                     <ice:outputText value="#{_sperimentazione.descrizione}"/>
                                </ice:column>
                           </ice:dataTable>



                      • 8. Re: How to read and show a table
                        xsa lefter Newbie

                        May be you can try this:



                        @Name("SperimentazioneList")
                        public class SperimentazioneList extends EntityQuery<Sperimentazione> {
                             private static final String EJBQuery = 
                                "SELECT sperimentazione FROM Sperimentazione sperimentazione";
                             
                                private static final long serialVersionUID = 7598286873082408222L;
                             
                             
                             public SperimentazioneList() {
                                 setEjbql(EJBQuery);
                             }
                        }
                        



                        and this:




                        <ice:dataTable var="_sperimentazione" value="#{SperimentazioneList.resultList}">
                        
                            <ice:column style="background-color: gray">
                            <f:facet name="header">
                                <ice:outputText value="id"/>
                            </f:facet>
                            <ice:outputText value="#{_sperimentazione.id}"/>
                            </ice:column>
                        
                            <ice:column>
                            <f:facet name="header">
                                <ice:outputText value="idAmministrativo"/>
                            </f:facet>
                            <ice:outputText value="#{_sperimentazione.idAmministrativo}"/>
                            </ice:column>
                        
                            <ice:column>
                            <f:facet name="header">
                                <ice:outputText value="Tipo di sperimentazione"/>
                            </f:facet>
                            <ice:outputText value="#{_sperimentazione.clsSperimentazione.tipo}"/>
                            </ice:column>
                        
                            <ice:column>
                            <f:facet name="header">
                                <ice:outputText value="Descrizione"/>
                            </f:facet>
                            <ice:outputText value="#{_sperimentazione.descrizione}"/>
                            </ice:column>
                        
                        </ice:dataTable>
                        



                        And if there are some error, please let me know.

                        • 9. Re: How to read and show a table
                          Pietro M. Newbie

                          Your modifications works. Thank you for everything.