0 Replies Latest reply on Oct 18, 2009 2:22 PM by pulkit.mehra

    Concurent Conversation in POP-UP window

      Hi frends,

      I am new to Seam framework and I am facing some problem in implementing Conversation.

      I am working on fixing Appointment.My Appointment.xhtml consist of command button which opens a modal panel and show list of Attendees in an Appointment.
      Attendees generate randomly in number per appointment.In Attendees.xhtml i need to view calendar of attendees(shown as list) in pop up window.
      So i need parllel coversation to view attendees calendar.Conversation should be resumed and should work concurrently

      1.Appointment.xhtml : opens a Attendees modal panel
      ===================================================
      <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"
                      xmlns:a4j="http://richfaces.org/a4j"
                      xmlns:rich="http://richfaces.org/rich"
                      xmlns:t="http://myfaces.apache.org/tomahawk">   <ui:include src="/view/Attendees.xhtml"/>

      <ui:include src="/view/Attendees.xhtml"/>

      <a4j:form>

      <h:panelGrid  columns="2" border="0" cellspacing="2" cellpadding="4" id="appointmentGrid" width="90%" columnClasses="oneTenthWidth columnClass1,twoFifthWide columnClass2">

      <h:column>
          <h:outputText value=" Attendees"/>
      </h:column>

      <h:column>

          <h:inputText value="#{invitationContext.selectedInviteeName}" readonly="true"/>
          <rich:spacer width="2px"/>
           <a4j:commandButton  value="Add Attendees"
                                           image="/files/images/assigntouser.jpg"
                                                    style="width:20px;height:20px;vertical-align: bottom;"
                                         action="#{calenderContext.showAttendees}"
                                         oncomplete="javascript:Richfaces.showModalPanel('attendeesModalPanel');" />

      </h:column>

      </ui:composition>

      2.Attendees.xhtml(modal panel) : opens viewNotaryCalendar as pop up.I am passing conversationId in its URL to resume conversation
      ===================================================================

      <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:c="http://java.sun.com/jstl/core"
                      xmlns:t="http://myfaces.apache.org/tomahawk"
                      xmlns:s="http://jboss.com/products/seam/taglib"
                      xmlns:a4j="http://richfaces.org/a4j"
                      xmlns:rich="http://richfaces.org/rich" xml:lang="en" lang="en">




      <script type="text/javascript">
          function openCalendarView(name,userId){

              mywin=window.open('ViewNotaryCalendar.xhtml'+'?converationId='+userId,userId,'location=0,status=0,resizable=1,scrollbars=1,width=860,height=530');
          }

      </script>



      <a4j:outputPanel ajaxRendered="true">
      <rich:modalPanel id="attendeesModalPanel"
                       rendered="#{calenderContext.attendeesFlag}"
                       headerClass="richPanelClass"
                       autosized="true"
                       keepVisualState="true"
                       showWhenRendered="true"
                       width="500" height="230"
      >

      <f:facet name="header">
          <h:outputText value="Add/View Attendees" />
      </f:facet>

      <a4j:form>

      <h:panelGrid columns="1" id="appointmentGrid_atendees"  cellspacing="5" cellpadding="2"   width="100%">

      <h:column>

      <rich:dataTable columns="2" width="100%" value="#{calenderContext.invitations}" var="_use"
                      columnClasses="oneThirdWide,oneTenthWidth"
                      onRowMouseOver="highlightRow(this)" onRowMouseOut="unHighlightRow(this)"
              >
          <rich:column>
              <f:facet name="header">
                  <h:outputText value="Name"/>
              </f:facet>

              <h:outputText value="#{_use.name}"/>
          </rich:column>

          <rich:column>
              <f:facet name="header">
                  <h:outputText value="View "/>
              </f:facet>


             <a4j:commandButton image="/files/images/Calendar-3-32x32.png"
                                 title="View Invited Attendees Calendar"
                                 style="width:20px;"
                                 oncomplete="openCalendarView('#{_use.name}','#{_use.userId}');"
                          action="#{calenderContext.startViewCalendar}"
                      reRender="my"
                      >
                      <f:param name="id" value="#{_use.userId}"/>
      </a4j:commandButton>

          </rich:column>
       
      </rich:dataTable>

      </h:column>
      </h:panelGrid>

      <div class="commandsBar">
          <a4j:commandButton  value="Close"
                              action="#{calenderContext.hideAttendees}"
                              reRender="appointmentGrid"
                  />
      </div>
      </a4j:form>

      </rich:modalPanel>
      </a4j:outputPanel>

      </ui:composition>

      3. ViewNotaryCalendar.xhtml: pop up window to view calendar . must resume conversation started by Attendees.xhtml.
      ==================================================================================================================
      n 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"
                      xmlns:a4j="http://richfaces.org/a4j"
                      xmlns:rich="http://richfaces.org/rich"
                      xmlns:t="http://myfaces.apache.org/tomahawk">

      <script type="text/javascript">


      </script>

      <a4j:outputPanel id="myPanel" ajaxRendered="true" >

          <a4j:form>

              <h:panelGrid id="e3">
                  <h:outputText value="#{calendarViewContext.userInconversation}"></h:outputText>
                  <h:inputText value="#{calendarViewContext.testString}"/>
                  <a4j:commandButton action="#{calendarViewContext.testing('aa')}" value="click" reRender="e3"/>
              </h:panelGrid>
           </a4j:form>
      </a4j:outputPanel>


      </ui:composition>

      4.CalendarContext : a session bean which starts conversation per attendee.
      ===========================================================================
      @Stateful
      @Name("calenderContext")
      @Scope(ScopeType.SESSION)
      public class CalenderContextBean implements CalenderContext{


           @RequestParameter
           private String id;

            @Logger
            Log log;
           
          @Out(value="userInconversation",required=false,scope=ScopeType.CONVERSATION)
          private String userInconversation;

            private boolean attendeesFlag=false;
         
            private List<InvitationHelper> invitations;
           
           @Create
           public void create(){
                 invitations=new ArrayList<InvitationHelper>();
              InvitationHelper help1=new InvitationHelper();
              help1.setDefaultSelected(true);
              help1.setEmail("hannahMontana@female.com");
              help1.setName("Hannah Montana");
              help1.setRegisterFlag(true);
              help1.setSelected(true);
              help1.setUserId("hannah");

              InvitationHelper help2=new InvitationHelper();
              help2.setDefaultSelected(false);
              help2.setEmail("JackSmith@female.com");
              help2.setName("Jack Smith");
              help2.setRegisterFlag(true);
              help2.setSelected(false);
              help2.setUserId("jack");

              InvitationHelper help3=new InvitationHelper();
              help3.setDefaultSelected(false);
              help3.setEmail("Peter@female.com");
              help3.setName("Peter Anderson");
              help3.setRegisterFlag(true);
              help3.setSelected(false);
              help3.setUserId("peter");

              invitations.add(help1);
              invitations.add(help2);
              invitations.add(help3);

           }

           
           @Begin(id="#{calenderContext.id}")
           public String startViewCalendar(){
                 userInconversation=id;
                 System.out.println("str : "+id);
                 log.info("Conversation {0}", Conversation.instance().getId());
                 return "";
             }

            public String getId() {
              return id;
          }

          public void setId(String id) {
              this.id = id;
          }
           
           public void showAttendees(){
             attendeesFlag=true;
         }

          public void hideAttendees(){
              attendeesFlag=false;
          }
           
           public boolean isAttendeesFlag() {
              return attendeesFlag;
          }

          public void setAttendeesFlag(boolean attendeesFlag) {
              this.attendeesFlag = attendeesFlag;
          }
           
            public List<InvitationHelper> getInvitations() {
              return invitations;
          }

          public void setInvitations(List<InvitationHelper> invitations) {
              this.invitations = invitations;
          }     
         
           @Remove @Destroy
          public void removeDestroy() {
              log.info("Conversation {0}", Conversation.instance().getId());
          }

      }

      5.CalendarViewContext : conversation bean this should resume conversation stared
      =================================================================================


      @Stateful
      @Name("calendarViewContext")
      @Scope(ScopeType.CONVERSATION)
      public class CalendarViewContextAction implements CalendarViewContext {


          @In(value="userInconversation",required=false,scope=ScopeType.CONVERSATION)
          private String userInconversation;

            @Logger
            Log log;
           
          @Create
          public void create()
          {
              log.info("object is being created");
              log.info("Conversation {0}", Conversation.instance().getId());
          }


         
          public String testing(String s){
              log.info("Conversation {0}", Conversation.instance().getId());
              System.out.println(""+testString);
              return "";
          }

         
        

          public String getUserInconversation() {
              return userInconversation;
          }

          public void setUserInconversation(String userInconversation) {
              this.userInconversation = userInconversation;
          }

        
          @Remove
          @Destroy
              public void removeDestroy(){
                System.out.println("CalendarViewContext object destroyed");
              log.info("Starting Manual Conversation {0}", Conversation.instance().getId());
          }



      }

      6.Pojo : used in rich datatable
      ================================
      public class InvitationHelper implements Serializable,Comparable<InvitationHelper> {


          private String userId;
          private String name;
         
           
           //getter and setter
           
           //equals / hashcode /compareable on userId field
           
           
      }


      Please tell me if my design is wrong or any another appropriate design i should follow to implement conversation.

      Thanks,
      Pulkit