5 Replies Latest reply on Oct 22, 2008 3:24 AM by Jason Porter

    Conversation propagation issues

    Jason Porter Master

      Not sure what's going on, but it's driving me crazy.  We have one page where we start the conversation in the page.xml, then when we click an ice:commandLink the conversation stops and we get the @In must not be null exception.  We've tried lots different things and I'll post the current sections.  If someone could tell me what we're doing wrong I would really appreciate it.


      first component


      @Name("nomineeSearch")
      @Scope(ScopeType.CONVERSATION)
      public class NomineeSearch
      {
      
          @In
          private EntityManager entityManager;
          
          @Logger
          private Log log;
          
          private Employee employee = new Employee();
          
          @DataModel(scope = ScopeType.PAGE)
          private List<Employee> results;
          
          @DataModelSelection
          private Employee employeeForDetails = new Employee();
          
          @Out(required = false)
          private Employee nominee;
          
          private boolean popupVisible = false;
      
          public void searchNominee()
          {
              this.log.trace("Firstname: #{firstname}");
              this.log.trace("Lastname: #{lastname}");
              this.results = entityManager.createQuery("select employee from Employee employee where lower(employee.firstname) like #{firstname} and lower(employee.lastname) like #{lastname}").getResultList();
              this.log.trace("return size: " + this.results.size());
          }
      
          @Factory(value = "firstname", scope = ScopeType.EVENT)
          public String getFirstNamePattern()
          {
              return this.employee.getFirstname() == null ? "%" : this.employee.getFirstname().toLowerCase().replace('*', '%') + '%';
          }
      
          @Factory(value = "lastname", scope = ScopeType.EVENT)
          public String getLastNamePattern()
          {
              return this.employee.getLastname() == null ? "%" : this.employee.getLastname().toLowerCase().replace('*', '%') + '%';
          }
      
          public void closePopup(ActionEvent event)
          {
              this.setPopupVisible(false);
          }
      
          public void showPopup(ActionEvent event)
          {
              this.setPopupVisible(true);
          }
      
          public void rowSelection(RowSelectorEvent e)
          {
              int itemRow = e.getRow();
              
              this.log.debug("Item index: " + itemRow);
              
              if (this.results.get(itemRow).getSelected())
              {
                  this.employeeForDetails = this.results.get(itemRow);
                  return;
              }        
          }
          
          public void selectNominee(Employee pNominee)
          {
              this.nominee = pNominee;
              log.debug("set this.nominee with " + this.nominee.getFirstname());
          }
      
          public Employee getEmployee()
          {
              return this.employee;
          }
      
          public void setEmployee(Employee pEmployee)
          {
              this.employee = pEmployee;
          }
      
          public boolean isPopupVisible()
          {
              return this.popupVisible;
          }
      
          public void setPopupVisible(boolean pPopupVisible)
          {
              this.popupVisible = pPopupVisible;
          }
      
          public Employee getEmployeeForDetails()
          {
              return this.employeeForDetails;
          }
      
          public void setEmployeeForDetails(Employee pEmployeeForDetails)
          {
              this.employeeForDetails = pEmployeeForDetails;
          }
      
          public Employee getNominee()
          {
              return nominee;
          }
      
          public void setNominee(Employee nominee)
          {
              this.nominee = nominee;
          }
      }



      page.xml for first page


      <?xml version="1.0" encoding="UTF-8"?>
      <page 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">
          <begin-conversation join="true"/>
          <description>
                    Create Nomination
                    Finds a nominee
          </description>
          <navigation from-action="#{nomineeSearch.selectNominee(_employee)}">
              <redirect view-id="/CreateNomination.xhtml" />
          </navigation>
      </page>



      view for first page:


      <!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:s="http://jboss.com/products/seam/taglib"
                      xmlns:ui="http://java.sun.com/jsf/facelets"
                      xmlns:f="http://java.sun.com/jsf/core"
                      xmlns:h="http://java.sun.com/jsf/html"
                      xmlns:ice="http://www.icesoft.com/icefaces/component"
                      template="layout/emptytemplate.xhtml">
          
          <ui:define name="body">
              <h:messages globalOnly="true" styleClass="message" id="globalMessages" />
              
              <ice:form id="listemployeeFormId" styleClass="edit">
                  <ice:panelPopup id="popupDiv"
                                  rendered="#{nomineeSearch.popupVisible}"
                                  visible="#{nomineeSearch.popupVisible}"
                                  modal="false"
                                  draggable="true"
                                  autoCenter="true"
                                  style="text-align:left; width: 250px; height: 100px; position:absolute; z-index:1001;">
                      
                      <f:facet name="header">
                          <ice:panelGrid width="100%" cellpadding="0" cellspacing="0" columns="2" style="text-align: center;">
                              <ice:outputText style="color: #FFFFFF;" value="Employee Information"/>
                              <ice:commandButton type="button" image="img/close.gif" actionListener="#{nomineeSearch.closePopup}" title="Close this draggable popup"/>
                          </ice:panelGrid>
                      </f:facet>
                      
                      <f:facet name="body">
                          <ice:panelGrid width="100%" columns="2" style="text-align: center">
                              <ice:outputText value="First Name" />
                              <ice:outputText value="#{nomineeSearch.employeeForDetails.firstname}" />
                              <ice:outputText value="Last Name" />
                              <ice:outputText value="#{nomineeSearch.employeeForDetails.lastname}" />
                              <ice:outputText value="Employee Id" />
                              <ice:outputText value="#{nomineeSearch.employeeForDetails.employeeid}" />
                              <ice:outputText value="Email" />
                              <ice:outputText value="#{nomineeSearch.employeeForDetails.email}" />
                          </ice:panelGrid>
                      </f:facet>
                      
                  </ice:panelPopup>
                  
                  <ice:panelGroup id="searchGroup" styleClass="formBorderHighlight">
                      <ice:panelGroup id="listPanelGroupEmployeeId" styleClass="edit">
                          <s:decorate id="firstnamedecId" template="layout/display.xhtml">
                              <ui:define name="label">First Name</ui:define>
                              <ice:inputText id="listfirstnameTextId"
                                             value="#{nomineeSearch.employee.firstname}" />
                          </s:decorate>
                          
                          <s:decorate id="lastnamedecId" template="layout/display.xhtml">
                              <ui:define name="label">Last Name</ui:define>
                              <ice:inputText id="listlastnameTextId"
                                             value="#{nomineeSearch.employee.lastname}" />
                          </s:decorate>
                      </ice:panelGroup>
                      
                      <div class="actionButtons">
                          <ice:commandButton
                              id="listSearchButtonId" value="Search"
                              action="#{nomineeSearch.searchNominee}" />
                      </div>
                  </ice:panelGroup>
                  
                  <ice:panelGroup styleClass="formBorderHighlight"
                                  rendered="#{not empty results}">
                      
                      <h3>Nominees</h3>
                      
                      <div class="searchResults" id="listemployeeResults">
                          <ice:dataTable
                              id="nomineeSearchTableId" var="_employee"
                              value="#{results}" columnClasses="allCols"
                              rendered="#{not empty results}">
                              <ice:column id="listfirstnameId#{_employee.id}">
                                  <ice:rowSelector id="selected"
                                                   value="#{_employee.selected}"
                                                   multiple="false"
                                                   selectionListener="#{nomineeSearch.rowSelection}"/>
                                  <f:facet name="header">Employee Name</f:facet>
                                  <ice:commandLink action="#{nomineeSearch.selectNominee(_employee)}" 
                                                   id="listemployeeId#{_employee.id}">
                                      #{_employee.firstname} #{_employee.lastname}
                                      <s:conversationId />
                                  </ice:commandLink>
                              </ice:column>
                              <ice:column id="listemployeeidId#{_employee.id}">
                                  <f:facet name="header">Employee Id</f:facet>
                                  #{_employee.employeeid}&amp;nbsp;
                              </ice:column>
                              <ice:column id="listColumnEmployeeId#{_employee.id}">
                                  <f:facet name="header">View Details</f:facet>
                                  <ice:commandButton id="details#{_employee.id}"
                                                     value="View Details"
                                                     actionListener="#{nomineeSearch.showPopup}"/>
                              </ice:column>
                          </ice:dataTable>
                      </div>
                  </ice:panelGroup>
              </ice:form>
          </ui:define>
      </ui:composition>



      second page view:


      <!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:s="http://jboss.com/products/seam/taglib"
                      xmlns:ui="http://java.sun.com/jsf/facelets"
                      xmlns:f="http://java.sun.com/jsf/core"
                      xmlns:h="http://java.sun.com/jsf/html"
                      xmlns:ice="http://www.icesoft.com/icefaces/component"  
                      template="layout/emptytemplate.xhtml">
          
          <ui:define name="body">
          
          <h:messages globalOnly="true" 
                      styleClass="message" 
                      id="globalMessages"/>
              
          <ice:form id="createNominationForm">
            <ice:panelGroup>
              <h2>Create Nomination</h2>
              <ice:panelGroup id="createNominationPanel" 
                              styleClass="edit">
                <ice:panelCollapsible id="detailPanel" 
                                      expanded="true" >
                  <f:facet name="header">
                    <ice:outputText id="detailHeader" 
                                    value="Employee Details"/>
                  </f:facet>
                  <ice:panelGrid id="detailGrid" 
                                 columns="2" 
                                 cellpadding="4" 
                                 cellspacing="4" 
                                 width="100%">
                    <!-- detail-->
                    <ice:outputLabel for="detailName"
                                     value="Employee Name"/>
                    <ice:outputText id="detailName" 
                                    value="#{nominee.lastname}, #{nominee.firstname}" />
                    <ice:outputLabel for="detailEmployeeId"
                                     value="Employee Id"/>
                    <ice:outputText id="detailEmployeeId" 
                                    value="#{nominee.employeeid}" />
                  </ice:panelGrid>
                </ice:panelCollapsible>
                <ice:panelCollapsible id="awardLevelPanel" 
                                      expanded="true" >
                  <f:facet name="header">
                    <ice:outputText id="awardLevelHeader" 
                                    value="Award Level"/>
                  </f:facet>
                  <ice:panelGrid id="awardLevelGrid" 
                                 columns="2" 
                                 cellpadding="4" 
                                 cellspacing="4" 
                                 width="100%">
                    <!-- award level-->
                    <ice:outputLabel for="awardLevelSelect"
                                     value="Award Level"/>
                    <h:selectOneMenu id="awardLevelSelect" 
                                     value="#{nominationAction.nomination.awardlevel}" 
                                     required="true">
                      <s:selectItems value="#{nominationAction.awardLevels}" var="level" 
                                     label="#{level.name}" 
                                     noSelectionLabel="Please Select..."/>
                      <s:convertEntity />
                    </h:selectOneMenu>
                  </ice:panelGrid>
                </ice:panelCollapsible>
                <ice:panelCollapsible id="achievementPanel" 
                                      expanded="false" >
                  <f:facet name="header">
                    <ice:outputText id="achieveHeader" 
                                    value="Achievement"/>
                  </f:facet>            
                  <ice:panelGrid id="achievementGrid" 
                                 columns="2" 
                                 cellpadding="4" 
                                 cellspacing="4" 
                                 width="100%">
                    <!-- achievement-->
                    <ice:outputLabel for="achievementInput"
                                     value="Achievement"/>
                    <h:inputTextarea id="achievementInput" 
                                     value="#{nominationAction.nomination.achievement}" 
                                     required="true"/>
                  </ice:panelGrid>
                </ice:panelCollapsible>
                <ice:panelCollapsible id="notesPanel"
                                      expanded="false" >
                  <f:facet name="header">
                    <ice:outputText id="notesHeader" 
                                    value="Notes"/>
                  </f:facet>
                  <ice:panelGrid id="notesGrid"
                                 columns="2" 
                                 cellpadding="4" 
                                 cellspacing="4" 
                                 width="100%">
                    <!-- notes-->
                    <ice:outputLabel for="notesInput"
                                     value="Notes"/>
                    <h:inputTextarea id="notesInput" 
                                     value="#{nominationAction.nomination.notes}" 
                                     required="false"/>
                  </ice:panelGrid>
                </ice:panelCollapsible>
                <ice:panelCollapsible id="approversPanel" 
                                      expanded="false" >
                  <f:facet name="header">
                    <ice:outputText id="approversHeader" 
                                    value="Approvers"/>
                  </f:facet>
                  <ice:panelGrid id="approversGrid"
                                 columns="2" 
                                 cellpadding="4" 
                                 cellspacing="4" 
                                 width="100%">
                    <!-- approvers-->
                    <ice:outputLabel for="approversInput"
                                     value="Last Name Starts With"/>
                    <ice:selectInputText id="approversInput"
                                         rows="6" 
                                         width="300"
                                         listVar="approver"
                                         valueChangeListener="#{approverService.updateApproverList}"
                                         listValue="#{approverService.approverList}">
                      <f:facet name="selectInputText">
                        <ice:panelGrid id="approverAutoCompleteGrid"
                                       columns="2">
                          <ice:outputText value="#{approver.lastname},&#160;"/>
                          <ice:outputText value="#{approver.firstname}"/>
                        </ice:panelGrid>
                      </f:facet>
                    </ice:selectInputText>          
                    <ice:outputLabel for="selectedApproversList"
                                     value="Selected Approvers"/>
                    <ice:panelGroup style="margin-top:10px;">
                      <ice:panelPositioned id="selectedApproversList"
                                           var="approver"
                                           value="#{approverService.selectedApproverList}"
                                           styleClass="positionPanelContainer"
                                           listener="#{approverService.positionApprovers}"
                                           constraint="vertical">
                        <ice:panelGroup style="cursor:move;" styleClass="container">
                          <ice:panelGroup styleClass="moveLabel"
                                          style="border: 4px red">
                            <ice:outputText id="approverName"
                                            value="#{approver.formattedName}"/>
                          </ice:panelGroup>
                        </ice:panelGroup>
                      </ice:panelPositioned>
                    </ice:panelGroup>
                  </ice:panelGrid>
                </ice:panelCollapsible>
              </ice:panelGroup>  
              <div class="actionButtons">
                <ice:commandButton id="createNominationButton" value="Submit" action="#{nominationAction.createNomination}"/>
              </div>
            </ice:panelGroup>
          </ice:form>
        </ui:define>
      </ui:composition>



      second page.xml:


      <?xml version="1.0" encoding="UTF-8"?>
      
      <page 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" 
            no-conversation-view-id="/SearchNominee.xhtml">
                <description>
                    Create Nomination for #{nominee.firstname} #{nominee.lastname}
                    Walks the user through the process of creating a nomination
                </description>
      
      </page>



      Second component:


      @Name("nominationAction")
      @Scope(ScopeType.CONVERSATION)
      public class NominationAction
      {
          @In
          private EntityManager entityManager;
          
          @In (required = false)
          private List<Employee> selectedApproverList;
          
          @In
          private Employee nominee;
          
          @Logger
          private Log log;
          
          
          private Nomination nomination = new Nomination();
          
          @Factory (value = "awardLevels")
          public List<Awardlevel> getAwardLevels()
          {
              return this.entityManager.createQuery("from Awardlevel").getResultList();
          }
      
          public Nomination getNomination()
          {
              
              return this.nomination;
          }
      
          public void setNomination(Nomination pNomination)
          {
              this.nomination = pNomination;
          }
          
          @End
          public void createNomination()
          {
              Employee nominator = new Employee();
              nominator.setId(1l);
              this.nomination.setEmployeeByNominatorid(nominator);
              this.nomination.setNominationdate(new Date());
              this.nomination.setEmployeeByNomineeid(this.nominee);
              entityManager.persist(this.nomination);
              this.setApprovals();
              entityManager.persist(this.nomination);
              entityManager.flush();
          }
      
          private void setApprovals()
          {
              if (this.selectedApproverList != null && this.selectedApproverList.size() > 0)
              {
                  ApprovalId id;
                  Approval approval;
                  for (Employee approver : this.selectedApproverList)
                  {
                      approval = new Approval();
                      id = new ApprovalId();
                      approval.setId(id);
                      id.setEmployeeid(approver.getId());
                      id.setNominationid(this.nomination.getId());
                      approval.setNomination(this.nomination);
                      approval.setEmployee(approver);
                      this.nomination.getApprovals().add(approval);
                      
                  }
              }
          }
      
      
          public Employee getNominee()
          {
              return this.nominee;
          }
      
          public void setNominee(Employee pNominee)
          {
              this.nominee = pNominee;
          }
      }