+ Start a Discussion
AgendumAgendum 

Execute controller method in apex page?

I know this is a very simple question, but my search in the IDE help revealed nothing.  If I have a method in a controller, how do I execute it in the view?  For example:

 

// ----------------------

// In the controller

 

    public static String test(String arg)
    {
        return arg;
    }

 

// ----------------------

// In the view

 

<div>{!test('foo')}</div>

 

Thanks!

 

~ devin

Best Answer chosen by Admin (Salesforce Developers) 
shra1_devshra1_dev

You cannot call a method which has arguments from a page.

 

Better you define a constructor and call your method from the constructor.

 

/*Under your constructor*/

test('foo');

 

 

Regards,

Shravan

All Answers

_Prasu__Prasu_

It will depend on the event. You want to execute it on Page Load or at any specific event?

kiranmutturukiranmutturu

put the action attribute in the page component in ordre to run that method

 

 

<apex:page action="{!test}"/>

 

 

 

shra1_devshra1_dev

You cannot call a method which has arguments from a page.

 

Better you define a constructor and call your method from the constructor.

 

/*Under your constructor*/

test('foo');

 

 

Regards,

Shravan

This was selected as the best answer
kiranmutturukiranmutturu

sorry i missed out that.. my intension is to give him a thought in how to call a method from page.. when it loads...