I'm trying to pass a parameter to a method in a visualforce page when the users clicks on a detail icon (a static resource image).
I'm trying with a commandButton since I need the button to be an image. The problem is that the parameter doesn't seem to get passed, cause from this code I get the error message 'Nothing found'. Do you have any idea why this happen? Should I use another approach?
page code:
<apex:commandButton action="{!getRichiestaDetail}" image="{!$Resource.detail_icon}" id="getRichiestaDetail" style="border:none;background:none;padding:0px;vertical-align:top;">
<apex:param name="richiestaId" value="{!richiesta.Id}" assignTo="{!detailRichiestaId}"/>
</apex:commandButton>
controller code:
public PageReference getRichiestaDetail() {
List<Riga_Richiesta__c> righeRichiesta =
[SELECT Id, Richiesta__c
FROM Riga_Richiesta__c
WHERE Richiesta__c =: detailRichiestaId];
if (righeRichiesta != null && righeRichiesta.size() > 0) {
showRichiestaDetail = true;
righeRichiestaDetail = righeRichiesta;
} else {
ApexPages.Message errorMsg = new ApexPages.Message(ApexPages.severity.ERROR, 'Nothing found');
ApexPages.addMessage(errorMsg);
}
return null;
}
Also, is it bad that I make a query call everytime someone clicks on a detail icon?
Thanks.