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
spatel_cespatel_ce 

JavaScript and PageBlockTable Column

Hi,

 

I am trying to pass a value from Visualforce page to Controller, by clicking on image with <apex:commandlink /> from PageBlockTable Column. Though I found some solutions where if I don't use PageBlockTable then it works so great. But I have to use PageBlockTable as per my requirement. 

 

Here is a code for my Visualforce page:

 

 

<apex:outputPanel id="resultPanel" >
<apex:outputText ><b> {!SelectedValue} </b></apex:outputText>
</apex:outputPanel>

<apex:pageBlock id="Skulls"> <apex:pageblocksection id="pbsSkulls" rendered="true"> <apex:pageBlockTable id="pbtSkulls" value="{!lstSBones}" var="SB"> <apex:column > <apex:commandlink onclick="callActionMethod('{!SB.Skulls__c}');" > <apex:image url="{!$Resource.Plus}" height="20" width="20"/> </apex:commandLink> </apex:column> </apex:pageBlockTable> </apex:pageblocksection> </apex:pageBlock> <apex:actionFunction name="readCell" action="{!readCellMethod}" reRender="resultPanel" > <apex:param name="SkillNExpertise" assignTo="{!clickedCellValue}" value="" /> </apex:actionFunction> <script type="text/javascript"> function callActionMethod(txtSkull) { readCell(txtSkull); } </script>

 

And here is my controller where I am trying to receive value.

 

    public String clickedCellValue { get; set; }
    public String SelectedValue { get; set; }
        
    public void readCellMethod() {
        SelectedValue = 'Selected Value: ' + ClickedCellValue;
    }    

 

Any input would be really appreciated.

 

Thanks,

Sawan 

 

Best Answer chosen by Admin (Salesforce Developers) 
APathakAPathak

Hi,

Have you tried the action support? This works for me :

 

<apex:outputPanel id="resultPanel" >
    <apex:outputText ><b> {!SelectedValue} </b></apex:outputText>
</apex:outputPanel>

<apex:pageBlock id="Skulls">
<apex:pageblocksection id="pbsSkulls" rendered="true">
		<apex:pageBlockTable id="pbtSkulls" value="{!lstSBones}" var="SB">
			<apex:column >
				<apex:image url="{!($Resource.Plus)}" height="20px" width="20px" >
					<apex:actionSupport event="onclick" action="{!readCellMethod}" rerender="resultPanel">
						 <apex:param assignTo="{!clickedCellValue}" value="{!SB.Skulls__c}" name="SkillNExpertise"/>
					</apex:actionsupport>
				</apex:image>
			</apex:column>
		 </apex:pageBlockTable>
	</apex:pageblocksection>
 </apex:pageBlock>

 

 

All Answers

APathakAPathak

Hi,

Have you tried the action support? This works for me :

 

<apex:outputPanel id="resultPanel" >
    <apex:outputText ><b> {!SelectedValue} </b></apex:outputText>
</apex:outputPanel>

<apex:pageBlock id="Skulls">
<apex:pageblocksection id="pbsSkulls" rendered="true">
		<apex:pageBlockTable id="pbtSkulls" value="{!lstSBones}" var="SB">
			<apex:column >
				<apex:image url="{!($Resource.Plus)}" height="20px" width="20px" >
					<apex:actionSupport event="onclick" action="{!readCellMethod}" rerender="resultPanel">
						 <apex:param assignTo="{!clickedCellValue}" value="{!SB.Skulls__c}" name="SkillNExpertise"/>
					</apex:actionsupport>
				</apex:image>
			</apex:column>
		 </apex:pageBlockTable>
	</apex:pageblocksection>
 </apex:pageBlock>

 

 

This was selected as the best answer
spatel_cespatel_ce

Hi Angad,

 

Your solution works so great for me. I spend 3 days and your answer helped me to make it work in 3 minutes. Once again, thank you so much for your effort and help.

 

-Sawan