2 Replies Latest reply on Sep 10, 2009 7:50 PM by nagendra_singh_krishnawat

    Seam Conversation: Required Clarification.

      My understanding of conversation is:                                           
      1. By default for every request there is a conversation which ends after the response, thats the reason why I see different conversationID for each JSF request.


      2. If I write @Begin on the method and when that method is invoked the conversation is promoted to long running conversation (which means whatever components I am outjecting in seam context will remain in seam context until End is called), For entire long running conversation cid remains same.


      3. "@End" will destroy the long running conversation and the default behavior(As per point 1, that is for each conversation new conversation id) is restored.


      Taking this assumption I created a functionality which starts the conversation when the user make a search and ends the conversation when user updates the search results


      I used @Begin(join=true) and  @End(beforeRedirect=true) on search and update function respectively.


      But after I leave the page the conversation is not ending and everytime I am visiting the portfolio page for any portfolio through a link its taking me to same portfolio. Seems like conversation has not actually ended and all the outjected variables are restored from conversation context.


      Are my assumptions wrong, Am I doing anything fundamentally wrong.

        • 1. Re: Seam Conversation: Required Clarification.
          asookazian

          In Seam apps, there is always either a temporary conversation or long-running conversation for each HTTP request/response cycle.


          @Begin will promote a temporary conversation to LRC after method completion.


          @End will demote the LRC to temporary conversation (for later destruction) after method completion.


          You will need to show your code for more answers...

          • 2. Re: Seam Conversation: Required Clarification.

            I could reply on very day, I was busy in other stuff, ok here is the code which kind of looks big but its very simple:


            ok, Here is very simple logic of this page: This is an xhtml page containing bulk update functionality, it shows a scrollable table, user selects some rows and then user selects new values from select menu, then press 'save', thus new values get updated for selected rows:


            <!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:a="http://richfaces.org/a4j"
                            xmlns:rich="http://richfaces.org/rich"
                               template="#{theme.template}">
                                   
            <ui:define name="body">
                      <style>
                        .scrolls{
                            width:300px;
                            height:200px;
                            overflow:auto;
                        }
                      </style> 
                    
                 <rich:panel headerClass="wamHeaderClass" header="Update Custodian Account Information">
                  <f:facet name="header">Update Custodian Account Information</f:facet>
            
                 <a:form>
                      <h:panelGroup id="globalmessagepanel">
                          <rich:messages globalOnly="true" styleClass="message" id="globalMessages"/>
                     </h:panelGroup>
                      <rich:toolTip followMouse="true" direction="top-right" showDelay="500" styleClass="tooltip" attached="true" id="toolTipForUpdateCustodianSteps" for="portfolioName" >
                            <span  style="white-space:nowrap">
                                <h:panelGrid columns="2" width="55%">
                                <strong>1.</strong> <h:outputText value="Search a Custodian by Bank Name or CCA."/>
                                <strong>2.</strong> <h:outputText value="From search results, select a row by clicking on row; for multiple row selection press CTRL key, and then make selections."/>
                                <strong>3.</strong> <h:outputText value="Select the new value in the dropdown below and press 'Update' to update for selected rows for corrosponding values."/>
                                </h:panelGrid>
                            </span>
                        </rich:toolTip>
                      <h:panelGrid columns="2" id="searchGrid" styleClass="gridStyle" border="0">
                           <h:inputText id="portfolioName" size="15" value="#{custodianAccountList.name}" style="width:200px" />
                           <a:commandButton id="search" value="Search Custodian" action="#{custodianAccountList.getSearchedPortfolios}"  reRender="portfolioListId,ajaxLoadingModalBox" onclick="Richfaces.showModalPanel('ajaxLoadingModalBox',{width:300, top:300})"/>
                  </h:panelGrid>
                   </a:form>  
                  <a:form>
                       <rich:spacer height="30"/>
                   <rich:scrollableDataTable width="100%" 
                                  id="portfolioListId" rows="40" selectionMode="multi" rowKeyVar="rkv" 
                            value="#{searchedPortfolios}" var="costodianAccountRow" selection="#{custodianAccountList.selection}">
                            
                            <rich:column >
                                <f:facet name="header"><h:outputText styleClass="headerText" value="Portfolio Number" /></f:facet>
                                <h:outputText value="#{costodianAccountRow.portfolio.portfolioNumber}" />
                            </rich:column>
                            
                            <rich:column >
                                <f:facet name="header"><h:outputText styleClass="headerText" value="Portfolio Name" /></f:facet>
                                <s:link view="/portfolio/#{empty from ? 'Portfolio' : from}.xhtml" value="#{costodianAccountRow.portfolio.name}" id="account" styleClass="tooltip-text">
                                    <f:param name="portfolioId" value="#{costodianAccountRow.portfolio.id}" />
                                </s:link>
                            </rich:column>
                            
                            <rich:column >
                                <f:facet name="header"><h:outputText styleClass="headerText" value="Cash Control Administrator" /></f:facet>
                                <s:link view="/party/#{empty from ? 'Person' : from}.xhtml" value="#{costodianAccountRow.cca.fullName}">
                                    <f:param name="personId" value="#{costodianAccountRow.cca.id}" />
                                </s:link>  
                            </rich:column>
                            
                            <rich:column >
                                <f:facet name="header"><h:outputText styleClass="headerText" value="Lending Agent" /></f:facet>
                                <s:link view="/party/#{empty from ? 'Person' : from}.xhtml" value="#{costodianAccountRow.lendingAgent.name}">
                                    <f:param name="personId" value="#{costodianAccountRow.lendingAgent.id}" />
                                </s:link>  
                            </rich:column>
                            
                            <rich:column >
                                <f:facet name="header"><h:outputText styleClass="headerText" value="Trade Contact" /></f:facet>
                                <s:link view="/party/#{empty from ? 'Person' : from}.xhtml" value="#{costodianAccountRow.tradeContact.name}">
                                    <f:param name="personId" value="#{costodianAccountRow.tradeContact.id}" />
                                </s:link>  
                            </rich:column>
                            
                            <rich:column >
                                <f:facet name="header"><h:outputText styleClass="headerText" value="Custodian Bank" /></f:facet>
                                <h:outputText value="#{costodianAccountRow.bank.name}" /> 
                            </rich:column>
                            
                            <rich:column >
                                <f:facet name="header"><h:outputText styleClass="headerText" value="Branch" /></f:facet>
                                <h:outputText value="#{costodianAccountRow.branch.name}" />
                            </rich:column>
                            
                            <rich:column >
                                <f:facet name="header"><h:outputText styleClass="headerText" value="Failed Trade DataSource" /></f:facet>
                                <h:outputText value="#{costodianAccountRow.failedTradeDataSource}" /> 
                            </rich:column>
                            
                            <rich:column >
                                <f:facet name="header"><h:outputText styleClass="headerText" value="Security Lending Allowed" /></f:facet>
                                <h:outputText value="#{costodianAccountRow.securityLendingAllowed}" />
                            </rich:column>
            
                  </rich:scrollableDataTable>
                   <rich:spacer height="20px"/>
                  <h:panelGrid columns="6" id="updateCcaGrid" border="0">
                  <s:decorate id="ccaDecoration" template="../layout/edit.xhtml">
                                <ui:define name="label">#{messages['label.custodianAccount.cca']} </ui:define>
                                
                                <h:selectOneMenu value="#{custodianAccountList.cca}"  style="width:110px" id="ccaId" required="false">
                                     <s:selectItems value="#{allPersonExcludingEmployeeContext}" var="ccaVar"  label="#{ccaVar.name}" noSelectionLabel="Please Select.."/>
                                     <s:convertEntity/>
                                </h:selectOneMenu>
                   </s:decorate>
                   <s:decorate id="tradeContactDecoration" template="../layout/edit.xhtml">
                                <ui:define name="label">#{messages['label.custodianAccount.tradeContact']} </ui:define>
                                <h:selectOneMenu value="#{custodianAccountList.tradeContact}"  style="width:110px" id="tradeContactaId" required="false">
                                     <s:selectItems value="#{allPersonExcludingEmployeeContext}" var="tradeContactVar"  label="#{tradeContactVar.name}" noSelectionLabel="Please Select.."/>
                                     <s:convertEntity/>
                                </h:selectOneMenu>
                   </s:decorate>
                   <s:decorate id="accountingContactDecoration" template="../layout/edit.xhtml">
                                <ui:define name="label">#{messages['label.custodianAccount.accountingContact']} </ui:define>
                                <h:selectOneMenu value="#{custodianAccountList.accountingContact}"  style="width:110px" id="accountingContactId" required="false">
                                     <s:selectItems value="#{allPersonExcludingEmployeeContext}" var="accountingContactVar"  label="#{accountingContactVar.name}" noSelectionLabel="Please Select.."/>
                                     <s:convertEntity/>
                                </h:selectOneMenu>
                   </s:decorate>
                   
                   <s:decorate id="lendingAgentDecoration" template="../layout/edit.xhtml">
                                <ui:define name="label">#{messages['label.custodianAccount.lendingAgent']} </ui:define>
                                <h:selectOneMenu value="#{custodianAccountList.lendingAgent}"  style="width:110px" id="lendingAgentId" required="false">
                                     <s:selectItems value="#{allPersonExcludingEmployeeContext}" var="lendingAgentVar"  label="#{lendingAgentVar.name}" noSelectionLabel="Please Select.."/>
                                     <s:convertEntity/>
                                </h:selectOneMenu>
                   </s:decorate>
                   
                   <s:decorate id="bankDecoration" template="../layout/edit.xhtml">
                                <ui:define name="label">#{messages['label.account.custodian']} </ui:define>
                                <h:selectOneMenu value="#{custodianAccountList.bank}"  style="width:110px" id="bankId" required="false">
                                     <s:selectItems value="#{allCustodians}" var="bankVar"  label="#{bankVar.name}" noSelectionLabel="Please Select.."/>
                                     <s:convertEntity/>
                                </h:selectOneMenu>
                   </s:decorate>
                   
                   <s:decorate id="branchDecoration" template="../layout/edit.xhtml">
                                <ui:define name="label">#{messages['label.account.custodianbranch']} </ui:define>
                                <h:selectOneMenu value="#{custodianAccountList.branch}"  style="width:110px" id="custodianId" required="false">
                                     <s:selectItems value="#{allCustodianBranches}" var="custodianVar"  label="#{custodianVar.name}" noSelectionLabel="Please Select.."/>
                                     <s:convertEntity/>
                                </h:selectOneMenu>
                   </s:decorate>
                   <h:commandButton action="#{custodianAccountList.updateSelection}" value="Update"/>
                                 
                  </h:panelGrid>
                 </a:form>
                 </rich:panel>
                 </ui:define>
            </ui:composition>
            




            Java Bean code:



            package com.xyz.party.action;
            
            import java.util.Iterator;
            import java.util.List;
            
            import javax.persistence.EntityManager;
            
            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.Scope;
            import org.jboss.seam.annotations.datamodel.DataModel;
            import org.jboss.seam.faces.FacesMessages;
            import org.jboss.seam.framework.EntityQuery;
            import org.richfaces.model.selection.Selection;
            
            import com.xyz.party.Bank;
            import com.xyz.party.BankBranch;
            import com.xyz.party.Person;
            import com.xyz.portfolio.CustodianAccount;
            import com.xyz.portfolio.action.ArmConstant;
            
            
            /**
             * @author NKrishnawat
             *
             */
            @Name("custodianAccountList")
            @Scope(ScopeType.CONVERSATION)
            public class CustodianAccountList extends EntityQuery<CustodianAccount>{
            
                private static final String EJBQL = "select t.id, t.name,t.primary_account_number, t.cca, t.lending_agent,t.data_source from custodian_account t";
            
                @In
                private transient FacesMessages facesMessages;
                
                @In
                EntityManager entityManager;
            
                public CustodianAccountList() {
                    setEjbql(EJBQL);
                    setMaxResults(new Integer(ArmConstant.MAX_QUERY_RESULTS_CONSTANT));
                }
            
                private Person cca,tradeContact,accountingContact,lendingAgent;
                
                private Bank bank;
                
                private BankBranch branch;
            
                private Selection selection;
                
                public Selection getSelection() {
                    return selection;
                }
                
                public void setSelection(Selection selection) {
                    this.selection = selection;
                }
            
                @End(beforeRedirect=true)
                public String updateSelection() {
                    Iterator<Object> itr = selection.getKeys();
                    try{
                        while(itr.hasNext()){
                            Integer indexNumber = (Integer)itr.next();
                            CustodianAccount managedEntity = ((CustodianAccount)searchedPortfolios.get(indexNumber.intValue()));
                            managedEntity.setCca(cca);
                            if(tradeContact!=null){
                                 managedEntity.setTradeContact(tradeContact);
                            }
                            if(accountingContact!=null){
                                 managedEntity.setAccountingContact(accountingContact);
                            }
                            if(lendingAgent!=null){
                                 managedEntity.setLendingAgent(lendingAgent);     
                            }
                            if(bank!=null){
                                 managedEntity.setBank(bank);     
                            }
                            if(branch!=null){
                                 managedEntity.setBranch(branch);     
                            }
                            entityManager.persist(managedEntity);
                        }
                        entityManager.flush();
                        this.facesMessages.addFromResourceBundle("custodianaccountccaupdate.success");
                    }catch(Exception exception){
                        this.facesMessages.addFromResourceBundle("custodianaccountccaupdate.faliure");
                    }
                    return null;
                }
                
                @DataModel
                List<CustodianAccount> searchedPortfolios;
                
                List<CustodianAccount> toUpdateList;
                
                @SuppressWarnings("unchecked")
                @Begin(join=true)
                public List<CustodianAccount> getSearchedPortfolios(){
                    if(name==null){ return null; }
                    searchedPortfolios = entityManager.createQuery(ArmConstant.getUpdatePortfolioResultListQuery(name)).getResultList();
                    return searchedPortfolios;
                }
                
                private int portfolioNumber;
                
                private String name;
            
                public String getName() {
                    return name;
                }
            
                public void setName(String name) {
                    this.name = name;
                }
            
                public int getPortfolioNumber() {
                    return portfolioNumber;
                }
            
                public void setPortfolioNumber(int portfolioNumber) {
                    this.portfolioNumber = portfolioNumber;
                }
                
                public void search(){
                    
                }
                
                public Person getCca() {
                    return cca;
                }
                public void setCca(Person cca) {
                    this.cca = cca;
                }
            
                 public Person getTradeContact() {
                      return tradeContact;
                 }
            
                 public void setTradeContact(Person tradeContact) {
                      this.tradeContact = tradeContact;
                 }
            
                 public Person getAccountingContact() {
                      return accountingContact;
                 }
            
                 public void setAccountingContact(Person accountingContact) {
                      this.accountingContact = accountingContact;
                 }
            
                 public Bank getBank() {
                      return bank;
                 }
            
                 public void setBank(Bank bank) {
                      this.bank = bank;
                 }
            
                 public BankBranch getBranch() {
                      return branch;
                 }
            
                 public void setBranch(BankBranch branch) {
                      this.branch = branch;
                 }
            
                 public Person getLendingAgent() {
                      return lendingAgent;
                 }
            
                 public void setLendingAgent(Person lendingAgent) {
                      this.lendingAgent = lendingAgent;
                 }
            }