+ Start a Discussion
Brendan LallyBrendan Lally 

ReRender not showing 'now deleted' row in detail section using DataTable

I have a 'Cases' parent record that looks at associated 'Listings' records via a two-way Master-Detail join table (Case_to_Listings). All of these are custom objects and work ok.

I've VF code that gives a better interface when dealing with a Case. It displays one detail record (like an Account) and then a list of listings (sort of like unconnected Contacts). The user can then click on a specific listing (via Action Add2Case) and that listing is then written to the junction table so its now associated.

That works but on the way back I want to re-render the listings so the one just picked is now gone (as Sql query will have that dropped now - I also do an updated on Listings and reset assigned field),
However my re-re-render doesn't seem 2 work?
If I do a refresh when the page comes back the line/row goes.
1) What am I doing wrong?


2) Love to have the ability for the user to select multiple records at a time (like S-Control GETRECORDIDs) but don't see any examples of that.

3) Also if the user comes into this without picking a case id (no ?id= is passed into VF page) how do I redirect back to the 'Cases' standard view (/aOA/o ). I have several views defined on Cases butl can't see how to pick (or redirect from controller) the default (no view selected) view.

Thanks
Lal

Code:
 <apex: page standardController="Case_to_Listings__c" extensions="CL_extn" showHeader="true" cache="false">

<apex: outputPanel id="msgs">
     <apex: messages layout="list"/>
</apex: outputPanel>

<apex: form >
 <apex: pageBlock title="Detail">
   <apex: detail subject="{!Case_to_Listings__c.Cases__c}" relatedList="Cases__c" />  
 </apex: pageBlock>

 <apex: pageBlock title="Listings that can be associated">
    <apex: dataTable value="{!All_Listings}" var="lists" id="AllListings" headerClass="headerRow" rowClasses="dataRow" styleClass="list">   
        <apex: column >
             <apex: facet name="header"><b>Action</b></apex: facet>
             <apex: commandLink style="font-weight: bold" action="{!Add2Case}" value="Add to Case" rerender="AllListings">
                <apex: param name="listingsId" value="{!lists.Id}"/>    
            </apex: commandLink>
            <apex: actionSupport event="onclick" rerender="AllListings"> </apex: actionSupport>
        </apex: column>
        <apex: column >
             <apex: facet name="header"><b>Listing ID</b></apex: facet>
             <apex: outputLink value="/{!LEFT(lists.Id,15)}"> {!lists.Name} </apex: outputLink>
         </apex: column>
   </apex: dataTable>    
 </apex: pageBlock>    

 </apex: form>

</apex: page>

and extn controller
Code:
public class CL_extn 
{
    private final Case_to_Listings__c curr_CL_rec ;
    private List<Listings__c> lists = new List<Listings__c>();

    public CL_extn( ApexPages.StandardController controller )
    {
        Id id = ApexPages.currentPage().getParameters().get('id');
        curr_CL_rec = (Case_to_Listings__c)controller.getSubject();

//      if an empty id then send pack (Pageref—) to Cases std view - HOW–

        loadAllListings();
    }

    private void loadAllListings()
    {
        List<Listings__c> sql_lists;
        sql_lists = [SELECT Id, Name FROM Listings__c WHERE assigned__c <> true ];
        for ( Listings__c one_rec : sql_lists )
          { lists.add( one_rec);}
    }

    public List<Listings__c> getAll_Listings()
    { return lists; }

   public PageReference Add2Case()
    {
        Id curr_id = ApexPages.currentPage().getParameters().get('listingsId');
        Case_to_Listings__c new_CL;        // new CL record
        try {
            new_CL = new Case_to_Listings__c( Cases__c    = curr_CL_rec.Cases__c, 
                                              Listings__c = curr_id );
            Database.insert( new_CL );
            //update the Listings record with assigned=true ....
            } 
          catch (DmlException e) 
            { System.debug(e.getMessage()); }

        return new PageReference( '/apex/Case2Listings˜id=' + curr_id );
      }
}


 

 

Brendan LallyBrendan Lally
any help on this?
Brendan LallyBrendan Lally
still need help on this.

Interesting that a Delete on the join table (top section of Apex for Listings Tab) works fine and it also refreshs both sections (top where it was deleted from and 2nd section that now shows its assignable)

(it returns to main inner tab and not the tab I want but thats another issues - see http://community.salesforce.com/sforce/board/message?board.id=Visualforce&message.id=3659)

So what am I doing on the ADD that the DEL is not doing (and getting right) as regards a refresh
Brendan LallyBrendan Lally
Managed to get part of this working. gone thru so many variations (in coding) trying 2 get it 2 work

So at moment in my Add2Case if I 'return null' it stays on the same tab (partly helping with http://forums.sforce.com/sforce/board/message?board.id=Visualforce&message.id=3610) BUT it only updates one section and not the other.

I've tried different ways of wrapping the sections (outputPanels, panelBlocks etc.) and just can't seem 2 get the right combination.
I've tried   rerender='panel1, panel2'  but only get the first one 'activated' even thou docs seem 2 indicate it should do more than one.

Apex code (changed a little) is as follows (note: on return from Add2Case I only get the top section (
listings_assigned ) refreshed, the bottom section (listings_not_assigned)does not refresh)

Code:
 <apex:tabPanel switchType="client" selectedTab="{!Hop_to_tab}"   id="CaseTabPanel" tabClass="activeTab" inactiveTabClass="inactiveTab">

...  not showing other tabs here

    <apex:tab label="Listings" name="listings" id="tab_listings">    
       <apex:outputPanel id="all_listings_section">

        <apex:outputPanel id="listings_assigned">
             <apex:relatedList list="Listings__r" title="Listings already assigned to this case"/>      
        </apex:outputPanel>             

        <apex:form >  
          <apex:outputPanel id="listings_not_assigned">
          <apex:pageBlock title="Listings that can be assigned to this Case" >
                         
             <apex:dataTable value="{!All_Listings}" var="lists" id="AllListings" headerClass="headerRow" rowClasses="dataRow"  styleClass="list">    

             <apex:column > 
                 <apex:facet name="header"><b>Action</b></apex:facet> 
                 <apex:commandLink style="font-weight: bold" action="{!Add2Case}" value="Add" rerender="listings_assigned" > 
                    <apex:param name="listing&caseIDs" value="{!lists.Id}.{!$CurrentPage.parameters.id}"/>     
                 </apex:commandLink>   
<!--                 <apex:actionSupport event="onclick" reRender="tab_listings"> </apex:actionSupport>   -->
             </apex:column> 

             <apex:column > 
                    <apex:facet name="header"><b>Listing ID</b></apex:facet> 
                    <apex:outputLink value="/{!LEFT(lists.Id,15)}"> {!lists.Name} </apex:outputLink>
<!--                 getting wrong value so need 2 drop  /apex  and last 3 chars at end = checksum for child recs  -->
             </apex:column>
             <apex:column > <apex:facet name="header"><b>Product       </b></apex:facet> <apex:outputField value="{!lists.Products_ID__c}"/>     </apex:column>    
              ... other columns
            </apex:dataTable>     

           </apex:pageBlock>     
        </apex:outputPanel>             

         </apex:form>  
       </apex:outputPanel>             
    </apex:tab>                                                        

   </apex:tabPanel>

</apex:page>

 Any ideas?

Brendan LallyBrendan Lally
Managed to fix this.

The second section does get refreshed (currently have rerender="listings_not_assigned, listings_assigned" but may not need that exact combo or could try another panel id to refresh into)
BUT the !Lists value in the (second) listings needs to have the (now assigned so it now moves to the top section (**) listing record REALLY deleted from its array - in Apex custom controller)

Tried a Lists[i].remove (see http://community.salesforce.com/sforce/board/) but that doesn't compile so had to setup a 2nd copy (list2) and then copy all the good ones (drop the 'now deleted' row) over.
I then reassigned that back to Lists and that renders properly.

so ? remains (maybe a bug) as to why it doesn't require any special coding in the top section ** (that gets refreshed and you see the new row appearing) but the bottom section requires behind the scenes array manipulation?

Lal