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
QuickDEVQuickDEV 

Invoking method using <apex:actionSupport>

Hi,

 

I tried to invoke method in the controller Extension class from <apex:actionSupport> tag. Also, pass

 

a parameter using <apex:param>.

 

I got the error saying: the method does not exist in the Standard controller.

 

Is it not possible to invoke the above way? If we can't, is there any way to achieve this.

 

Please help.  Appreciate your time reading the post.

 

Thanks!

 

jeffdonthemic2jeffdonthemic2

Can you post your Controller and Visualforce code?

 

Thanks

 

Jeff Douglas

Appirio, Inc.

http://blog.jeffdouglas.com 

QuickDEVQuickDEV

Thanks Jeff for your reply.

 

Here is the abridged version of the code:

<!-- Page -->
<apex:page standardController="ProfileView__c" extensions="ProfileViewSearchExtn">
<apex:actionSupport action="{!ProcessLocation}">
<apex:param value="{!ProfileView__c.Account__r.Location__c }" />
</apex:actionSupport>
</apex:page>


<!--ProfileView__c is a custom object with lookup relation with "Account".
I tested the merge field value printing on page successfully -->

 

==============


//Controller Exetension : ProfileViewSearchExtn
public class ProfileViewSearchExtn{
public ProfileViewSearchExtn(ApexPages.StandardController controller) { }
String Loc;
// Removed irrelavant parts for simplicity
public PageReference ProcessLocation(String LocId){
this.Loc= LocId;
System.debug('Location Id :'+Loc);
//need to do some processing based on the value of "Loc"
return null;
}
}

 

 Thank You!

 

 

jeffdonthemic2jeffdonthemic2

What's the component that is wrapping this actionSupport in the top of your Visualforce page? Is it a picklist? Simple text?

 

Thanks

 

Jeff Douglas

Appirio, Inc.

http://blog.jeffdouglas.com

QuickDEVQuickDEV

"Location__C" is a simple text field.

 

I tested printing the value on the page itself successfully.

 

The problem is, when I try to save the page compiler is expecting the the method {!ProcessLocation} to be present in

 

standard controller where as in my case it is in Controller extension.

 

Thank You!

TehNrdTehNrd

Methods called from pages with the action tags cannont take arguements, but you are on the right track with the param approach

 

Page:
<apex:page standardController="ProfileView__c" extensions="ProfileViewSearchExtn">
<apex:actionSupport action="{!ProcessLocation}">
<apex:param name="location" value="{!ProfileView__c.Account__r.Location__c }" assignTo="{!location}"/>
</apex:actionSupport>
</apex:page>


Controller:
public class ProfileViewSearchExtn{
public ProfileViewSearchExtn(ApexPages.StandardController controller) { }

public String location {get; set;}

// Removed irrelavant parts for simplicity
public void ProcessLocation(){
System.debug('Location Id :'+ location);
//need to do some processing based on the value of "Loc"
}
}

If you use assignTo in the param you can assign this value directly to a variable in the controller. Your processLocatio() method and then reference this variable and do whatever you want with it.

 

Hope that helps,

Jason

Message Edited by TehNrd on 08-31-2009 08:55 AM
QuickDEVQuickDEV

Thank You Jason for your help.

 

I noticed that my <actionSupport> is not executed at all. I left out 'event' attribute as it is not mandatory.

 

I even tried keeping that event='onclick', as this tag is present in a form with <apex:commandButton>. But no

 

luck.   Any ideas why <actionSupport> is not executed? :smileysad:

 

Appreciate your time.  

 

Thanks!

TehNrdTehNrd

You definitely do not need actionSupport tags within a commandButton if I understood your last post. The event action of an actionSupport is not required but if it is blank this component is pretty useless.

 

actionSupport should be used with components that do not have action attributes themseleves, such as outputPanels:

 

<apex:outputPanel>
This is my panel....
<apex:actionSupport event="onclick" action="{!doSomething}"/>
</apex:outputPanel>

 

 

 

Message Edited by TehNrd on 08-31-2009 10:09 AM
QuickDEVQuickDEV

I am still not done.

 

I am sorry if I have been trying complex things to achive simple functionality.

 

Let me restate my requirement:

 

I have access to "{!ProfileView__c.Account__r.Location__c }" value available in my page.

 

I need to pass this value to the Extension class "ProfileViewSearchExtn" somehow.

 

It has nothing to do with any other tags in the page. But if we want to make use, we have

 

<apex:commandButton> available.

 

I am really sorry if I was unclear.

 

Please help me. Thank You so much !

 

k2sfdevk2sfdev

<apex:form>

 

 Your code ......

 

</apex:form> 

TehNrdTehNrd

Uh.... let me expand on that. This should work.

 

 

<apex:page standardController="ProfileView__c" extensions="ProfileViewSearchExtn"> <apex:commandButton value="click me" action="{!ProcessLocation}"> <apex:param name="location" value="{!ProfileView__c.Account__r.Location__c }" assignTo="{!location}"/> </apex:actionSupport> </apex:page> Controller: public class ProfileViewSearchExtn{ public ProfileViewSearchExtn(ApexPages.StandardController controller) { } public String location {get; set;} // Removed irrelavant parts for simplicity public void ProcessLocation(){ System.debug('Location Id :'+ location); //need to do some processing based on the value of "Loc" } }

 

 

 

QuickDEVQuickDEV

Thank You Jason & Jeff for your help.

 

I see the problem, my form not posted back to the controller, that is why "assignTo" did not assign the value to the

 

variable.  I solved the problem the other way:

 

In the controller, making use of relation between Account and custom object, did ApexPages.-----.getId(), instantiated

 

the Account object and got the field required.

 

But, I really tried so many other things based on your replies and learned.

 

Appreciate it! Thanks.