8 Replies Latest reply on Apr 28, 2010 12:39 PM by vasukihn

    Help required in writing java code in seam framework

    vasukihn

      Hi all,


      I am very new to this framework. I wanted to know whether any Jboss seam developers guide book is available at store or online download?


      Another question is, i am struck in writing code for adding values from the database to rich:combobox list.
      Can anyone help me guiding the procedure/steps to be followed to complete the work?
      As i don't have any idea of what all files to be created to add values in combobox list from the database.



      Thanks
      Vasuki

        • 1. Re: Help required in writing java code in seam framework
          amitev

          Read Seam reference manual and Seam in Action.


          As for the comobox i recommend you to fetch the values using @Factory and use the factory in the child selectItems of rich:combobox

          • 2. Re: Help required in writing java code in seam framework
            vasukihn

            Hi Adrian,


            Can you give me an example java to explain the @Factory functionality?


            • 3. Re: Help required in writing java code in seam framework
              sappo

              Hi Vasuki,


              check out the Seam reference manual:


              http://docs.jboss.org/seam/2.2.1.CR1/reference/en-US/html_single/#d0e4355


              For further reading I really recommand Seam in Action.


              Kind regards,
              Kevin

              • 4. Re: Help required in writing java code in seam framework
                vasukihn

                Hi Kevin,


                I have 2 entity files (Custom.java and CustomType.java). I want to have a list of CustomTypename(property of CustomType.java)as drop down in CustomEdit.xhtml file.


                I have added CustomType class instance in Custom.java file and also setter and getter method for the instnace.
                Later what i have to do? Just explain what functions to be written in which files?


                Thanks
                Vasuki

                • 5. Re: Help required in writing java code in seam framework
                  sappo

                  Hi Vasuki,


                  seam has build in support for converting entities. The only thing you've to do is add the s:convertEntity tag to your drop-down component.


                  <h:selectManyListbox value="#{yourBean.customTypeList}">
                    <s:selectItems var="c" value="#{yourBean.selectedType}" label="#{c.name}"/>
                    <s:convertEntity/>
                  </h:selectManyListbox>
                  



                  //Kevin

                  • 6. Re: Help required in writing java code in seam framework
                    vasukihn

                    Hi Kevin,


                    Please can you explain me in detail? I just have two entity files Custom.java and CustomType.java. I have added CustomType class instance in Custom.java and i have the getter and setter methods. Except this i have nothing else. What functions i have to write in each file? Once the functions are written what value should be passed to .xhtml file?


                    As i 'm new to this, please explain me in detail.

                    • 7. Re: Help required in writing java code in seam framework
                      sappo

                      Hi Vasuki,


                      there is no need to change anything inside your entity classes. Just create an action class like the one below, to pass a list to your drop-down and obtain the selected value.



                      CustomTypeAction.java (you may want to change the scope):


                      @Name("customTypeAction")
                      @Scope(ScopeType.SESSION)
                      public class CustomTypeAction implements Serializable {
                          @In
                          EntityManager entitymanager;
                      
                          @Out
                          List<CustomType> customTypeList;
                          @In(required = false)
                          CustomType selectedType;
                      
                          @Factory(value="customTypeList")
                          public List<CustomType> initList() {
                              return (ArrayList<CustomType>)
                                  entityManager.createQuery("select s from Schulform s").getResultList();
                          }
                      }
                      


                      *.xhtml


                      <h:selectManyListbox value="#{customTypeList}">
                        <s:selectItems var="c" value="#{selectedType}" label="#{c.name}"/>
                        <s:convertEntity/>
                      </h:selectManyListbox>
                      



                      //Kevin

                      • 8. Re: Help required in writing java code in seam framework
                        vasukihn

                        Hi Kevin,



                        As you said, I created CustomtypeAction.java file and wrote the code as you explained. I used my table name and fields in the query. Later added the belowcode to my CustomEdit.xhtml


                        <h:selectManyListbox value="#{customTypeList}">
                          <s:selectItems var="c" value="#{selectedType}" label="#{c.name}"/>
                          <s:convertEntity/>
                        </h:selectManyListbox>
                        



                        When i add the above code to my CustomEdit.xhtml file i get the following error:
                        I didn't understand about var and label attributes of 


                        <s:selectItems>



                        tag.


                        java.lang.IllegalArgumentException: Expected a child component type of UISelectItem/UISelectItems for component type javax.faces.SelectMany(j_id41).  Found null.




                        Can you guide where i am going wrong?