You need to sign in to do that
Don't have an account?
Apex method in visualforce page
Hi!
I want to include an apex method, which needs an object as variable, into my own visualforce page. So, if anybody clicks on a commandLink the method should be envoked with the relative object.
My approach:
<apex:pageBlock title="Title">
<apex:dataTable value="{!method}" var="object" width="100%">
<apex:column >
<apex:facet name="header">ID</apex:facet>
<apex:form >
<apex:commandLink value="{!object.name}" action="{!method(object)}"/>
</apex:form>
</apex:column>
</apex:dataTable>
</apex:pageBlock>
The method [in dataTable value] is defined in an apex class and returns a list of several objects with some attributes, e.g. the name.
The method(object) [in commandLink action] is also defined in an apex class. Unfortunately I can't refer to the object.
Does anybody know why?
Thanks in advance!
Phil
Commandlink action methods can't take parameters in this way. You'll need something along these lines:
<apex:commandLink action="{!editConsumable}" value="{!object.name}" styleClass="btn" status="status">
<apex:param name="theObject" assignTo="{!selectedObject}" value="{!object}"/>
</apex:commandLink>
All Answers
Commandlink action methods can't take parameters in this way. You'll need something along these lines:
<apex:commandLink action="{!editConsumable}" value="{!object.name}" styleClass="btn" status="status">
<apex:param name="theObject" assignTo="{!selectedObject}" value="{!object}"/>
</apex:commandLink>
unfortunately param value can't contain objects...but after a little time, everything works :-)
So thanks a lot for your great answer!