+ Start a Discussion
nimdharnimdhar 

assignTo for the commandLink is working only for the first record

Hi,
I have the following code that displays all the locations iterating through the locationresults. The commandLink sends the correct id to the controller only for the first record.  For the rest of the records it sends null. I think it is set only once. Can anyone tell me how to do this?
<apex:pageblocksection title="Locations" id="locationresults">
   <apex:pageblocklist value="{!locationresults}" var="location" rendered="{!NOT(ISNULL(locationresults))}">
                    <apex:column headerValue="Name">
                               <apex:outputlink value="/{!location.id}">{!location.name}</apex:outputlink>
                      </apex:column>
                       <apex:column value="{!location.Address__c}" />
                        <apex:column value="{!location.City__c}" />
                         <apex:column value="{!location.State__c}" />
                          <apex:column value="{!location.ZipCode__c}" />
                            <apex:column>
                                   <apex:commandLink value="Attach"  action="{!attach}" oncomplete="closewindow()">
                                           <apex:param assignTo="{!myclient}" value="{!location.id}"/>
                                     </apex:commandLink> 
                               </apex:column>
                                </apex:pageblocklist>
                        </apex:pageblocksection>

Thanks,
Nimdhar
nimdharnimdhar
Hi,

Can anyone please tell is there any other way to pass the correct id to the method in the controller.

Thanks,
nimdhar
nimdharnimdhar
This is my controller attach action method code
public PageReference attach()
{
Lead lead = [select Id,Location__c,LastName from Lead where Id= :System.currentPageReference().getParameters().get('q')];
lead.Location__c=myclient;
update lead;
return null;
}

And this is my visual force page
<apex:pageblocksection title="Locations" id="locationresults">
 <apex:pageblocklist value="{!locationresults}" var="location"  rendered="{!NOT(ISNULL(locationresults))}">
                   <apex:column headerValue="Name">
                                  <apex:outputlink value="/{!location.id}">{!location.name}</apex:outputlink>
                     </apex:column>
                      <apex:column value="{!location.Address__c}" />
                       <apex:column value="{!location.City__c}" />
                        <apex:column value="{!location.State__c}" />
                         <apex:column value="{!location.ZipCode__c}" />
                           <apex:column>
                                       <apex:commandLink value="Attach" action="{!attach}" oncomplete="closewindow()">
                                           <apex:param assignTo="{!myclient}" value="{!location.id}"/>
                                        </apex:commandLink>
                                        </apex:column>
                                </apex:pageblocklist>
                        </apex:pageblocksection>

locationresults is a list which has different locations. Problem I am facing is that the commandLink Attach is passing the parameter "myclient"  which is location  id  correctly only for the first record.  If I click  "Attach" link on the second record nulll is getting passed to the controller.

Thanks,
Nimdhar