+ Start a Discussion
minkeshminkesh 

component not rerendered properly.

Hello All,

                I have developped one component. the component is used to display account hierarchy in tree view manner.

                I called this component in searchAccount class in which i have given one text box to search account and also given another button i.e. ADD which will add  that searched selected account into that tree hierarchy by assigning parentAccount.

                Now when i added that account i need it to rerender that component so that i will be able to display that account into that hierarchy but unfortunately hierarchy view is distracted and another columns are automatically appended to the last row.

                can anyone help me in this matter?

bob_buzzardbob_buzzard

I think you'll need to post some code for us to look at.

LakshmanLakshman

You might be using the component in some VFP which might be having a form, so try rerendering the form when you add a Account. I hope you are working on apex/VFP name or a custom tab having VFP in it. If you are working on Account layout and added the page in layout then the scenario would be different.

 

Let me know the details if this is not the case.

Thank you!

 

Regards,

Lakshman

minkeshminkesh

Hello Bob,

                   Thank you for quick reply. here below i am posting the code:

<apex:page standardController="Account" tabStyle="Account" showHeader="false" sidebar="false" extensions="SearchAccount" id="pg"> 
   <script>
                     
        function startSplash() {
            //var divObj = document.getElementById('splashDiv');
            document.getElementById('splashDiv').style.display="block";
            //alert('start');
        }
        
      
        
        function endSplash(){
            //var divObj = document.getElementById('splashDiv');
            document.getElementById('splashDiv').style.display="none";
            alert('end');
        }
   </script>
        <apex:outputPanel id="comp">
            <c:AccountHierarchyTree currentId="{!Account.id}" id="component" />
        </apex:outputPanel>
    
    <div>
        <apex:form title="Search Account" id="frm">
            
            <apex:pageBlock id="pgblock">
               
            <apex:actionStatus id="splashStatus" onstart="startSplash();" onstop="endSplash(); "/>
                <apex:pageMessages id="msgs"></apex:pageMessages>
                <table>
                    <tr>
                        <td> <b> Search Name:</b></td>
                        <td> <apex:inputText value="{!searchedString}"/> </td> 
                        <td> <apex:commandButton value="Go" action="{!fetchedAccounts}" status="splashStatus" reRender="msgs,searchedrecords"/></td>
                        <td> <apex:commandButton value="Add" action="{!assignParent}" reRender="msgs,searchedrecords,comp" status="splashStatus"/> </td>
                        <td> <div id="splashDiv" style="display:none;color:red;font-weight:bold;padding-bottom:4px;border: 0px;">
                               Please Wait. Loading...
                            </div>
                        </td>
                    </tr>
                 </table>
                    
                <apex:outputPanel id="searchedrecords" style="">
                    <apex:pageblockTable value="{!accWrapper}" var="sfn">
                        <apex:column >
                              <apex:facet name="header">
                                   <input type="checkbox" selected="false" id="chk"/>
                              </apex:facet>
                                  <apex:inputCheckbox value="{!sfn.selectedAcc}" id="selected">
                              </apex:inputCheckbox>
                        </apex:column>
                
                      <apex:column headervalue="Parent #" value="{!sfn.searchedAccount.Parent.AccountNumber}" />
                      <apex:column headervalue="Account Number">
                          <apex:outputLink value="/{!sfn.searchedAccount.Id}" target="_blank">{!sfn.searchedAccount.AccountNumber}</apex:outputLink>
                      </apex:column>
                      <apex:column headervalue="Account Name" value="{!sfn.searchedAccount.Name}" />
                      <apex:column headervalue="Total AR" value="{!sfn.searchedAccount.Total_AR__c}" />
                     
                   </apex:pageblockTable> 
                </apex:outputPanel>           
            </apex:pageblock>
       </apex:form>  
  </div> 
</apex:page>

 

 

 

bob_buzzardbob_buzzard

The page looks reasonable.  Can you clarify what you mean by the hierarchy view is distracted and another columns are automatically appended?  Are the columns automatically appended to the hierarchy view or the search results?

minkeshminkesh


Hello bob,

                   suppose i have 5 columns and 4 rows plus 1 row for total column.now when i am adding searched account one row will be automatically added to the table but unfortunately the extra rows of first account is repeated five times. e.g.

               

      before rerender

         

   Account           balance            ar              credit limit         credit utilized
   a1                    5000                 20                   251                 5422
    a2                   20250                50                  410                 5525
    a4                   26406             5252                22152             4521
  
Total                  something     something        something    something     

 

  

 

after rerender and adding the account

 

 

 

 

Account           balance            ar              credit limit         credit utilized
   a1                    5000                 20                   251                 5422
    a2                   20250                50                  410                 5525
    a3                  1212.102         5242                24242            2424
     a4                   26406             5252                22152             4521
 
Total                  something     something        something    something    5000                 20                   251                 5422   5000                 20                   251                 5422    5000                 20                   251                 5422

 

 

 

 

what is the reason ?

 

bob_buzzardbob_buzzard

Can you post the component and controller?  It sounds like the list that is backing the grid maybe isn't being cleared down correctly.

minkeshminkesh

Hello bob,

                   here is the piece of code of controller.

                   

 public List<ObjectStructureMap> getObjectStructure(){
        asm.clear();
        
        if ( currentId == null ) {
            currentId = System.currentPageReference().getParameters().get( 'id' );
            System.debug('-------------> '+currentId);
        }
        
        System.assertNotEquals( currentId, null, 'sObject ID must be provided' );
        asm = formatObjectStructure( CurrentId );
        
        Integer flag = 0;
       
        //for(ObjectStructureMap asm1 : asm){}
        Schema.Sobjecttype objType = Account.getSObjectType();
        Schema.Describesobjectresult sobjRes = objType.getDescribe();
        Map<String, Schema.Sobjectfield> fieldMap = sobjRes.fields.getMap();

        
        
        
        boolean temp = true;
       
        for(ObjectStructureMap asm1 : asm)
        {
            totalfieldWrapper tfw;
            totalfieldWrapper tfw1;
            Integer i = 0; 
            asm1.objList = new List<totalfieldWrapper>();
            String fieldType;
            for(TreeFieldConfiguration__c tfc : treeConfigList){
                Schema.Sobjectfield field = fieldMap.get(tfc.akritiv__CustomField__c);
                fieldType = field.getDescribe().getType().name();
                tfw = new totalfieldWrapper();
                System.debug(fieldType +'+++++accStr++++++'+tfc.akritiv__CustomField__c );
                if(fieldType.equals('CURRENCY') || fieldType.equals('NUMBER') || fieldType.equals('DOUBLE') || fieldType.equals('PERCENT')){
                    tfw.accNumber = (Double)asm1.Account.get(tfc.akritiv__CustomField__c);
                    if(UtilityController.isMultiCurrency()){
                        tfw.currencyIsoCode = (String)asm1.account.get('CurrencyIsoCode');
                    }else{
                        SysConfig_Singlec__c sysConfObj = ConfigUtilController.getSystemConfigObj();
                        tfw.currencyIsoCode = sysConfObj.Default_Currency__c;
                    }
                    if(tfw.accNumber == null)
                    {
                        tfw.accNumber = 0.0;
                    }
                    asm1.objList.add(tfw);
                }else if(fieldType.equals('STRING')){
                    tfw.accStr = (String)asm1.Account.get(tfc.akritiv__CustomField__c);
                    if(tfw.accStr == null)
                    {
                        tfw.accStr = '-';
                    }
                    asm1.objList.add(tfw);
                }
                
                System.debug('+++++accStr++++++'+tfw.accStr);

                tfw1 = new totalfieldWrapper(tfw);

              
                if(tfc.akritiv__Summary_Field__c){
                    if(flag > 0){
                            System.debug('++++++flag++++++' + flag);  
                            temp = false;
                            if(fieldType.equals('STRING')){
                                tfw1.accStr = '-';
                                totalOfFields1.set(i,tfw1);
                            }
                            else{
                                if(UtilityController.isMultiCurrency()){
                                    tfw1.currencyIsoCode = (String)asm1.account.get('CurrencyIsoCode');
                                }else{
                                    SysConfig_Singlec__c sysConfObj = ConfigUtilController.getSystemConfigObj();
                                    tfw1.currencyIsoCode = sysConfObj.Default_Currency__c;
                                }
                                System.debug((Double)totalOfFields1.get(i).accNumber + '++++++Ankur++++++' + tfw1.accNumber ); 
                                tfw1.accNumber =  (Double)tfw1.accNumber + (Double)totalOfFields1.get(i).accNumber;
                                totalOfFields1.set(i,tfw1);
                             }                              
                        }else{
                            if(fieldType.equals('STRING')){
                                tfw1.accStr = '-';
                                totalOfFields1.add(tfw1);
                            }
                            else{
                                totalOfFields1.add(tfw1);
                            }                           
                        }
                    }
                    else if(temp)
                    {
                    System.debug('=====temp====='+temp);
                        if(fieldType.equals('STRING')){
                            tfw1.accStr = '-';
                            totalOfFields1.add(tfw1);
                        }
                        else{
                            totalOfFields1.add(tfw1);
                        }
                    }                        
                system.debug('-----------tfw1------------>'+tfw1);    
                i++;
             }       
             system.debug('----------totalOfFields------------->'+totalOfFields1);
             flag++;
        }  
              
      system.debug('----------totalOfFields------------->'+totalOfFields1.size());
       
        return asm; 
    }

 

 

 

 

below is the piece of component code 

 

<apex:repeat value="{!ObjectStructure}" var="pos" >
           
            <tr id="node-{!pos.account.Id}" class="{!IF(pos.account.ParentId != '' ,'child-of-node-'+pos.account.ParentId,'a')}">
                <td class="{!IF(OR(pos.nodeType=='child_end',pos.nodeType=='child'),'file','folder')}">
                    
                    <span height="16" v="top">
                        <apex:outputText rendered="{!IF(pos.nodeType=='start',true,false)}">
    
                            <apex:image id="Icon_start" url="{!ParentImageURL}" width="16" height="16" rendered="{!IF(pos.currentNode,false,true)}"/>
                            <apex:image id="Icon_start_current" url="{!ParentImageURL}" width="16" height="16" rendered="{!IF(pos.currentNode,true,false)}"/>
                        </apex:outputText>
                        
                        <apex:outputText rendered="{!IF(OR(pos.nodeType=='parent',pos.nodeType=='parent_end'),true,false)}">
                            
                            <apex:image id="Tree_parent_end" url="/img/tree/minusEnd.gif" rendered="{!IF(pos.nodeType=='parent_end',true,false)}" height="16" width="20" title="Click to expand/collapse nested items." />
                            <apex:image id="Icon_parent" url="{!ParentImageURL}" width="16" height="16" rendered="{!IF(pos.currentNode,false,true)}"/>
                            <apex:image id="Icon_parent_current" url="{!SelectedRecordImageURL}" width="16" height="16" rendered="{!IF(pos.currentNode,true,false)}"/>
                        </apex:outputText>
                        
                        <apex:outputText rendered="{!IF(OR(pos.nodeType=='child',pos.nodeType=='child_end'),true,false)}">
                            <apex:image id="Tree_child" url="/img/tree/node.gif" rendered="{!IF(pos.nodeType=='child',true,false)}" height="16" width="20" title="Click to expand/collapse nested items." />
                            <apex:image id="Tree_child_current" url="/img/tree/nodeEnd.gif" rendered="{!IF(pos.nodeType=='child_end',true,false)}" height="16" width="20" title="Click to expand/collapse nested items." />
                            <apex:image id="Icon_child" url="{!ChildImageURL}" width="16" height="16" rendered="{!IF(pos.currentNode,false,true)}"/>
                            <apex:image id="Icon_child_current" url="{!SelectedRecordImageURL}" width="16" height="16" rendered="{!IF(pos.currentNode,true,false)}"/>
                        </apex:outputText>
                        
                        <apex:outputText rendered="{!IF(pos.nodeType=='end',true,false)}">
                            <apex:image id="Tree_end" url="/img/tree/nodeEnd.gif" height="16" width="20"/>&nbsp;
                            <apex:image id="Icon_end" url="{!ChildImageURL}" width="16" height="16" rendered="{!IF(pos.currentNode,false,true)}"/>
                            <apex:image id="Icon_end_current" url="{!SelectedRecordImageURL}" width="16" height="16" rendered="{!IF(pos.currentNode,true,false)}"/>
                        </apex:outputText>
                        <!-- Change Below -->
                        <apex:outputLink value="/{!pos.account.id}" style="{!IF(pos.currentNode,'font-weight: bold;font-size:12px','')}" styleClass="columnHeadActiveBlack" target="_top">{!pos.account.name}</apex:outputLink>
                    </span>
                 </td>
                <apex:repeat value="{!pos.objList}" var="obj">
                  <td style="background-color:#fff;border:1px solid gray;text-align: right;padding: 6px 6px 6px 3px;font-size:12px">
                        <apex:outputText value="{!obj.accStr}" rendered="{!If(obj.accStr == null,false,true)}" escape="false" > </apex:outputText>
                        <apex:outputText value="{0, number,{!obj.CurrencyIsoCode} ##,###,###.##}" rendered="{!If(obj.accStr == null,true,false)}">
                            <apex:param value="{!obj.accNumber}" />
                        </apex:outputText>                        
                    </td>
                </apex:repeat>
            </tr>
        </apex:repeat>
        <tr>
            <td style="background-color:#E6EAE9;border:1px solid gray;text-align: center;padding: 6px 6px 6px 3px;font-size:14px">
            <b>Total</b>
            </td>
                <apex:repeat value="{!totalOfFields1}" var="total" >
                   <script>alert('{!total}'); </script>
                   <td style="background-color:#fff;border:1px solid gray;text-align: right;padding: 6px 6px 6px 3px;font-size:12px">
                    <apex:outputText value="{!total.accStr}" rendered="{!If(total.accStr == null,false,true)}" escape="false"> </apex:outputText>
                    <apex:outputText value="{0, number,{!total.CurrencyIsoCode} ##,###,###.##}" rendered="{!If(total.accStr == null,true,false)}">
                        <apex:param value="{!total.accNumber}" />
                    </apex:outputText>
                </td>
            </apex:repeat>
        </tr>       
       </tbody>
    </table>

 

 

bob_buzzardbob_buzzard

I'd imagine its to do with these lines:

 

 }else{
                            if(fieldType.equals('STRING')){
                                tfw1.accStr = '-';
                                totalOfFields1.add(tfw1);
                            }
                            else{
                                totalOfFields1.add(tfw1);
                            }                           
                        }
                    }
                    else if(temp)
                    {
                    System.debug('=====temp====='+temp);
                        if(fieldType.equals('STRING')){
                            tfw1.accStr = '-';
                            totalOfFields1.add(tfw1);
                        }
                        else{
                            totalOfFields1.add(tfw1);
                        }
                    }                        

which add values to the totalOfFields1 list each time the method is invoked.  Prior to this you use the set method, which will overwrite existing values, but at this point they will be tacked on to the end each time.  Should you be clearing down the totals list prior to recalculating the values?