function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
SeraphSeraph 

Return Row Value when Clicking Outputlink

I have a table and a controller
<apex:page sidebar="false" controller="DisplayStatus">
          <apex:pageBlock title="Gadget (Gadget__c)">
             <apex:pageBlockTable value="{!gadgetlist}" var="gadget">
                 <apex:column headerValue="Gadget" value="{!gadget.Name}"/>
                 <apex:column headerValue="Action">
                       <apex:outputlink>Edit</apex:outputlink>
                 </apex:column>
             </apex:pageBlockTable>
         </apex:pageBlock> 
</apex>
If I click Edit it will return the value of its corresponding row (gadget.Name) in a System.debug.
ex.

Gadget                     Action

Smartphone               Edit
Watch                       Edit
Camera                     Edit

If I click Edit in the 2nd row, I would return Smartphone in a System.Debug statement.
How could I do this?

 
Best Answer chosen by Seraph
Shrikant BagalShrikant Bagal
Hello Seraph,

Try following code
 
<apex:page sidebar="false" controller="DisplayStatus">
          <apex:pageBlock title="Gadget (Gadget__c)">
             <apex:pageBlockTable value="{!gadgetlist}" var="gadget">
                 <apex:column headerValue="Gadget" value="{!gadget.Name}"/>
                 <apex:column headerValue="Action">
                       <apex:commandLink value="Edit" action="{!showGadget}">
                                    <apex:param name="gadgetName"  value="{!gadget.Name}" />
                       </apex:commandLink>
                 </apex:column>
             </apex:pageBlockTable>
         </apex:pageBlock> 
</apex>

and you can get the Gadget Name at controller using following code:
 
public class DisplayStatus{

       public void showGadget(){
          String strGadgetName = ApexPages.currentPage().getParameters().get('gadgetName');
           System.debug(strGadgetName);
        }
}

If its helps, please mark as best answer so it will help to other who will serve same problem.
​Thanks!

All Answers

Mudasir WaniMudasir Wani
You can use apex:param 
Here is an example have a look and let me know 
http://blog.jeffdouglas.com/2010/03/03/passing-parameters-with-a-commandlink/
Shrikant BagalShrikant Bagal
Hello Seraph,

Try following code
 
<apex:page sidebar="false" controller="DisplayStatus">
          <apex:pageBlock title="Gadget (Gadget__c)">
             <apex:pageBlockTable value="{!gadgetlist}" var="gadget">
                 <apex:column headerValue="Gadget" value="{!gadget.Name}"/>
                 <apex:column headerValue="Action">
                       <apex:commandLink value="Edit" action="{!showGadget}">
                                    <apex:param name="gadgetName"  value="{!gadget.Name}" />
                       </apex:commandLink>
                 </apex:column>
             </apex:pageBlockTable>
         </apex:pageBlock> 
</apex>

and you can get the Gadget Name at controller using following code:
 
public class DisplayStatus{

       public void showGadget(){
          String strGadgetName = ApexPages.currentPage().getParameters().get('gadgetName');
           System.debug(strGadgetName);
        }
}

If its helps, please mark as best answer so it will help to other who will serve same problem.
​Thanks!
This was selected as the best answer
SeraphSeraph
Thx so much @Shrikant Bagal. I haven't tried using param and it worked as I wanted it too.

for those who wanna try this, here is my full working codes
visualforce page
<apex:page sidebar="false" controller="Disp">
          <apex:pageBlock title="Gadget (Gadget__c)">
             <apex:pageBlockTable value="{!gadgetlist}" var="gadget">
                 <apex:column headerValue="Gadget" value="{!gadget.Name}"/>
                 <apex:column headerValue="Action">
                     <apex:form >
                       <apex:commandLink value="Edit" action="{!showGadget}">
                           <apex:param name="gadgetName"  value="{!gadget.Name}" />
                       </apex:commandLink>
                     </apex:form>
                 </apex:column>
             </apex:pageBlockTable>
         </apex:pageBlock> 
</apex:page>
controller
public class Disp{
public List<Gadget__c> gadgetlist {get; set;}
        public Disp(){
            this.showTable();
        }
        
       public void showGadget(){
          String strGadgetName = ApexPages.currentPage().getParameters().get('gadgetName');
           System.debug(strGadgetName);
        }
       public void showTable(){
          gadgetlist = [select Name from Gadget__c];
       } 
}
hope this helps someone!!!