9 Replies Latest reply on Oct 8, 2010 5:48 AM by lvdberg

    Preserving data from JSF(1.2) to Sean Component.

    rahulranchi

      Hi,


      I am fetching a list from Seam Component to JSF and again resending the list ( after editing the values) to Seam Component from JSF.


      This list is preserved when I use @Scope(ScopeType.SESSION). But when I use @Scope(ScopeType.CONVERSATION) the value in the list is not getting preserved on Seam component.


      I am just using only one feature of seam in mu Seam component and that is @Name(mainbean).


      Can anyone please guide me that how I can fetch the list value to the Seam Component while using  @Scope(ScopeType.CONVERSATION).


      Thnaks in advance


      Rahul

        • 1. Re: Preserving data from JSF(1.2) to Sean Component.
          lvdberg

          Hi Rahul,


          You must (a) put the @Scope(ScopeType.CONVERSATION) at the class level of the bean and begin a long-running conversation. This can be achieved in different ways being with a Begin-annotation at the method whic start the conversation, by adding an element in page(s).xml or programmatic.


          Please read the documentation because it contains all the explanation you need.


          Leo

          • 2. Re: Preserving data from JSF(1.2) to Sean Component.
            rahulranchi

            Good Afternoon Leo,


            Thanks for your reply.


            I have started a long running conversation through pages.xml but the problem still persists as mentioned above. I am unable to retrive the changed value of the List from JSF page when I use ScopeType.CONVERSATION . The changed value works fine (i.e retrieved) when I use @Scope(ScopeType.SESSION).


            Is it possible for me anyhow to send the code snippets to you? I will be thankful to you if you please guide me through.


            Thanks


            Rahul

            • 3. Re: Preserving data from JSF(1.2) to Sean Component.
              lvdberg

              Hi,


              no problem send the code to the forum.


              Leo

              • 4. Re: Preserving data from JSF(1.2) to Sean Component.
                rahulranchi
                Thanks Leo. Belo is the code snippet.


                JSF Code
                ***********

                <rich:message>Please Key in the Customer Name you want to edit</rich:message>
                          <h:inputText value="#{mainbean.customerName}" />
                          <h:commandButton value="Search" type="submit"
                               actionListener="#{mainbean.searchCustomer}" />
                          <br></br>
                          <br></br>

                          <h:panelGrid columns="3" width="100%"
                               columnClasses="tpanels,tpanels,tpanels">
                               <rich:simpleTogglePanel switchType="ajax"
                                    label="These are the customers matching search criteria"
                                    height="90px">

                                    <rich:dataTable width="483" id="findCustomerList" rows="10"
                                         columnClasses="col" value="#{mainbean.findCustomerlist}"
                                         var="findCustomerList">
                                         <f:facet name="header">
                                              <rich:columnGroup>
                                                   <h:column>
                                                        <h:outputText styleClass="headerText" value="Sr No" />
                                                   </h:column>
                                                   <h:column>
                                                        <h:outputText styleClass="headerText" value="Company Name" />
                                                   </h:column>
                                                   <h:column>
                                                        <h:outputText styleClass="headerText" value="Account Number" />
                                                   </h:column>
                                                   <h:column>
                                                        <h:outputText styleClass="headerText" value="Contact Number" />
                                                   </h:column>
                                                   <h:column>
                                                        <h:outputText styleClass="headerText" value="Contact Name" />
                                                   </h:column>

                                              </rich:columnGroup>
                                         </f:facet>

                                         <h:column>
                                              <h:outputText styleClass="headerText" value="#{findCustomerList.id}" />
                                         </h:column>
                                         <h:column>
                                              <h:inputText value="#{findCustomerList.companyName}" />
                                         </h:column>
                                         <h:column>
                                              <h:inputText value="#{findCustomerList.accountNumber}" />
                                         </h:column>
                                         <h:column>
                                              <h:inputText value="#{findCustomerList.contactNumber}" />
                                         </h:column>
                                         <h:column>
                                              <h:inputText value="#{findCustomerList.contactName}" />
                                         </h:column>
                                    </rich:dataTable>
                               </rich:simpleTogglePanel>

                               <h:commandButton value="Update" type="submit"
                                    action="#{mainbean.modifyCustomer}" />

                          </h:panelGrid>


                Seam Component
                ******************
                import java.io.Serializable;
                import java.util.List;

                import javax.faces.event.ActionEvent;

                import org.jboss.seam.ScopeType;
                import org.jboss.seam.annotations.Begin;
                import org.jboss.seam.annotations.End;
                import org.jboss.seam.annotations.Name;
                import org.jboss.seam.annotations.Out;
                import org.jboss.seam.annotations.Scope;


                /**
                * @author rahul.x.kumar
                *
                */
                @Name("mainbean")
                @Scope(ScopeType.CONVERSATION)
                public class MainBean implements Serializable{

                private List<Customer> findCustomerlist=null;

                public List<Customer> getFindCustomerlist() {
                          return findCustomerlist;
                     }

                     public void setFindCustomerlist(List<Customer> findCustomerlist) {
                          this.findCustomerlist = findCustomerlist;
                          }

                public void searchCustomer(ActionEvent actionEvent)
                    {
                         findCustomerlist=session.findCustomer(customerName);
                    }

                   
                  public void modifyCustomer()
                    {
                         session.updateCustomer(findCustomerlist);
                         System.out.println("Inside modifyCustomer");
                         System.out.println(findCustomerlist.get(0).getCompanyName());
                    }     
                  
                }

                Pages.xml
                ************

                <?xml version="1.0" encoding="utf-8"?>
                <pages xmlns="http://jboss.com/products/seam/pages" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                     xsi:schemaLocation="http://jboss.com/products/seam/pageshttp://jboss.com/products/seam/pages-2.1.xsd">
                     
                     <page view-id="/FirstRichPage.xhtml">
                          <begin-conversation join="true" />
                     </page>
                     …
                </pages>
                • 5. Re: Preserving data from JSF(1.2) to Sean Component.
                  lvdberg

                  Hi,


                  Have you tested if the search code works, because I can't see that specific part of your code.


                  - The rich:message tag is used incorrectly.
                  - Use the action method, because you need possibly the outcome for your navigation and change to the ajax-version of the button if you want partial reRendering.
                  - I assume that the button triggers the call and  because of a lack of a navigation rule the same page is reloaded, so the results show up when you have a Session-scoped bean.


                  So basically to achieve what you want:



                  <a4j:commandButton value="Search" type="submit"
                     action"#{mainbean.searchCustomer}" reRender="findCustomerList" />
                  



                  Or the same button and create a navigation rule which reRenders the whole page.


                  Leo



                  • 6. Re: Preserving data from JSF(1.2) to Sean Component.
                    rahulranchi
                    Hi Leo,

                    Thanks for your help so far.I really appreciate.

                    You asked :"Have you tested if the search code works, because I can't see that specific part of your code."

                    Ans: My search code is working. It is bascically populating a list of objects retrived from the DAO layer( hibernate) to the JSF screen.

                    I am trying to edit the same list and the pass it the Seam Component through the <h:commandButton value="Update" type="submit"
                        action="#{mainbean.modifyCustomer}" />

                    I applied both the solutions provide by you but it doesn't works.

                    When I press the update button it shows the same data which was retrived in search operation and the edited data goes off from the screen.

                    Is it possible for you to send me your email id so that I can send the codes to you?

                    Thanks in advance.
                    • 7. Re: Preserving data from JSF(1.2) to Sean Component.
                      lvdberg

                      Hi,


                      You can find me on LinkedIn:


                      LinkedIn

                      • 8. Re: Preserving data from JSF(1.2) to Sean Component.
                        rahulranchi

                        Okay. Thanks. I will do that as I need some guidance from Seam Experts to hone up my Seam and JSF skills. I am really grateful to you Mr. Berg.


                        Do you have any immediate thought on the problem mentioned by me above. Am I missing something?


                        Rahul

                        • 9. Re: Preserving data from JSF(1.2) to Sean Component.
                          lvdberg

                          Hi,


                          if you are sure the data retrieval from the DB works, it is just a matter of getting your page right. Because the bean is (or is supposed to be) in conversation scope. The complete list is in memory ready to render.


                          In most cases it is just a matter of getting the ajax ok.


                          Do some simple test and put as much lof.info statements as possible. Addtionally you can try to make a simple a4j:outputPanel with a


                          <h:outputText value="#{whatEverYourBeanname.resultCount}" id="resultCount">



                          inside which is reRendered , as a value, you use the size of the resultlist. This is the most simple approach you can have abnd if that doesn't work either you should focus on the scope of you bean. This can be observerd with debugging, but the simplest one is adding a method with a create-annotation and one with a destroy annotation. Put a simple log.info statement with a clear line I am created!! These logs are called at exactly creation and remove, so the resultlist you get from the DB should be BETWEEN these lines.If not, the converation is not active and you're retrieving a lot of data, but it is erased prior to rendering.


                          Leo