1 Reply Latest reply on Mar 7, 2010 4:42 AM by chetan padhye

    Conversation example

    chetan padhye Newbie

      HI ,


      I have requirement of opening new window /tab for page flows which fits for seam conversational scope


      below is code of same .. i m not sure what i am doing wrong in it. To open window ui have normal wndow.open js call. object to be shared between multiple tab is kept in conversation scope . The action before starting new tab is annotated with @Begin ... Please suggest any idea



      Action class




      package com.mydomain.registration;
      
      import org.jboss.seam.annotations.Begin;
      import org.jboss.seam.annotations.End;
      import org.jboss.seam.annotations.In;
      import org.jboss.seam.annotations.Name;
      
      @Name("register")
      public class RegisterAction {
      
              @In
              private User user;
      
              @End
              public void confirm() {
      
              }
      
              @Begin(join = true)
              public void register() {
                      user.getTestlist().add( user.getUsername() );
                      System.out.println(user.getUsername());
              }
      }
      



      User object which is put in conversation scope




      package com.mydomain.registration;
      
      import java.util.ArrayList;
      import java.util.List;
      
      import org.jboss.seam.ScopeType;
      import org.jboss.seam.annotations.Name;
      import org.jboss.seam.annotations.Scope;
      
      @Name("user")
      @Scope(ScopeType.CONVERSATION)
      public class User {
      
              private String username;
              private List<String> testlist = new ArrayList<String>();
      
              public String getUsername() {
                      return username;
              }
      
              public void setUsername(String username) {
                      this.username = username;
              }
      
              public List<String> getTestlist() {
                      return testlist;
              }
      
              public void setTestlist(List<String> testlist) {
                      this.testlist = testlist;
              }
      
      }
      




      Register Page




      <?xml version="1.0" encoding="utf-8"?>
      <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
                            "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
      <html xmlns="http://www.w3.org/1999/xhtml"
              xmlns:s="http://jboss.com/products/seam/taglib"
              xmlns:h="http://java.sun.com/jsf/html"
              xmlns:f="http://java.sun.com/jsf/core"
              xmlns:a4j="http://richfaces.org/a4j">
      <head>
      <title>Register New User</title>
      </head>
      <body>
      <script>
              function openWindow()
                      {
                               open("registered.seam","_blank","left=0,top=0, height=673, width=1014, resizable=yes, toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,dependent=yes");
                      }
      </script>
      <f:view>
              <a4j:form>
                      <h:panelGrid columns="2">
                        Username: <h:inputText value="#{user.username}" />
                      </h:panelGrid>
                      <a4j:commandLink value="Register Command Link"
                              action="#{register.register}" oncomplete="openWindow();">
                              <f:param name="conversationId" value="#{conversation.id}" />
                      </a4j:commandLink>
              </a4j:form>
      </f:view>
      </body>
      </html>
      








      New tab/Window opens up with following page



      <?xml version="1.0" encoding="utf-8"?>
      <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
                            "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
      <html xmlns="http://www.w3.org/1999/xhtml"
              xmlns:f="http://java.sun.com/jsf/core">
      
      <head>
      <title>Successfully Registered New User</title>
      </head>
      <body>
      <f:view>
              Here is Username :- , #{user.name}
               
         #{user.testlist} ---  #{user.testlist.size}
               
            </f:view>
      </body>
      
      </html>
      







        • 1. Re: Conversation example
          chetan padhye Newbie


          
          "package com.mydomain.registration;
          
          import java.io.Serializable;
          import java.util.ArrayList;
          import java.util.List;
          
          import org.jboss.seam.ScopeType;
          import org.jboss.seam.annotations.Name;
          import org.jboss.seam.annotations.Scope;
          
          
          
          
          
          
          @Name("sandy")
          @Scope(ScopeType.CONVERSATION)
          public class Sandy implements Serializable {
          
               List<String> demo = new ArrayList<String>();
          
               String name = "";
          
               public List<String> getDemo() {
                    return demo;
               }
          
               public void setDemo(List<String> demo) {
                    this.demo = demo;
               }
          
               public String getName() {
                    return name;
               }
          
               public void setName(String name) {
                    this.name = name;
               }
          
          }
          "
          
          
          
          
          
          
          
          //$Id: HotelSearchingAction.java 6987 2007-12-23 19:53:07Z pmuir $
          package com.mydomain.registration;
          
          import java.io.Serializable;
          import java.util.ArrayList;
          import java.util.List;
          
          import org.jboss.seam.ScopeType;
          import org.jboss.seam.annotations.Name;
          import org.jboss.seam.annotations.Scope;
          import org.jboss.seam.annotations.datamodel.DataModel;
          
          @Name("firstAction")
          @Scope(ScopeType.SESSION)
          public class FirstAction implements Serializable {
          
               @DataModel
               private List<Sandy> sandies;
          
               public void find() {
          
                    queryHotels();
               }
          
               private void queryHotels() {
          
                    sandies = new ArrayList<Sandy>();
                    Sandy e;
                    for (int x = 0; x < 5; x++) {
                         e = new Sandy();
                         e.setName("My name is Samdy" + x);
                         sandies.add(e);
                    }
          
                    System.out.println(sandies);
               }
          
          }
          
          
          
          package com.mydomain.registration;
          
          import org.jboss.seam.ScopeType;
          import org.jboss.seam.annotations.Begin;
          import org.jboss.seam.annotations.End;
          import org.jboss.seam.annotations.In;
          import org.jboss.seam.annotations.Name;
          import org.jboss.seam.annotations.Out;
          import org.jboss.seam.annotations.Scope;
          
          @Name("registerAction")
          @Scope(ScopeType.SESSION)
          public class RegisterAction {
          
               @In(required = false)
               @Out
               private Sandy sandy;
          
               @End
               public void confirm() {
          
               }
          
               @Begin
               public void selectItem(Sandy selected) {
                    
                    
                    selectedHotel.getDemo().add(selected.getName());
          
                    sandy = selected;
               }
          }
          
          
          
          
          <pages xmlns="http://jboss.com/products/seam/pages"
               xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
               xsi:schemaLocation="http://jboss.com/products/seam/pages http://jboss.com/products/seam/pages-2.0.xsd">
          
          
               <page view-id="/register.xhtml" login-required="false">
          
                    <navigation from-action="#{registerAction.selectHotel(hot)}">
                         <redirect view-id="/registered.xhtml" />
                    </navigation>
          
               </page>
          
          
          </pages>
          
          
          
          
          <?xml version="1.0" encoding="utf-8"?>
          <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
                                "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
          <html xmlns="http://www.w3.org/1999/xhtml"
               xmlns:s="http://jboss.com/products/seam/taglib"
               xmlns:h="http://java.sun.com/jsf/html"
               xmlns:f="http://java.sun.com/jsf/core"
               xmlns:a="http://richfaces.org/a4j">
          <head>
          <title>Register New User</title>
          </head>
          <body>
          
          <f:view>
          
               <div class="section"><h:form id="main">
          
                    <span class="errors"> <h:messages id="messages"
                         globalOnly="true" /> </span>
          
                    <h1>Search Hotels</h1>
                    <fieldset><a:commandButton id="findHotels"
                         value="List Values" action="#{hotelSearch.find}"
                         reRender="searchResults" /></fieldset>
          
               </h:form></div>
          
               <a:outputPanel id="searchResults">
                    <div class="section"><h:outputText id="NoHotelsFoundMessage"
                         value="No Hotels Found"
                         rendered="#{hotels != null and hotels.rowCount==0}" /> <h:dataTable
                         id="hotels" value="#{sandies}" var="hot"
                         rendered="#{sandies.rowCount>0}">
                         <h:column>
                              <f:facet name="header">Name</f:facet>
                         #{hot.name}
                    </h:column>
                         <h:column>
                              <f:facet name="header">Action</f:facet>
                              <s:link id="viewHotel" value="View Hotel" target="_blank"
                                   action="#{registerAction.selectHotel(hot)}" />
          
                         </h:column>
                    </h:dataTable></div>
               </a:outputPanel>
          </f:view>
          </body>
          </html>
          
          
          
          
          <!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
          <ui:composition xmlns="http://www.w3.org/1999/xhtml"
               xmlns:ui="http://java.sun.com/jsf/facelets"
               xmlns:h="http://java.sun.com/jsf/html"
               xmlns:f="http://java.sun.com/jsf/core"
               xmlns:s="http://jboss.com/products/seam/taglib">
          
               <!-- content -->
          
               <div class="section">
               <h1>View Hotel</h1>
               </div>
               <div class="section">------------ #{sandy.demo}------------</div>
          
          
          
          
          </ui:composition>