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
Mike LeachMike Leach 

Binding outputText to Functions

How come I can bind outputText to a global macro like this:

 

<apex:outputText value="The formatted time right now is: {0}">

<apex:param value="{!NOW()}" />

</apex:outputText>

 

But I can't bind to a function on a custom controller like this:

 

<apex:outputText value="The formatted time right now is: {0}">

<apex:param value="{!MyCustomFunction()}" />

</apex:outputText>

 In the second example (above) the error message is

 

Save error: Unknown function MyCustomFunction. Check spelling. 

 

The method is public. Changing it to a property seems to work, but I lose the ability to pass arguments to the function, which is ultimately what I'm trying to achieve.

 

Thanks! 

 

 

 

Cool_DevloperCool_Devloper

Well, I am afraid you can only bind to the property methods in the controller:(

But, you can still pass arguments to your controller method by using the params, right?

Am i missing something here?:S

Cool_D 

Mike LeachMike Leach

This doesn't work either. 

 

<!-- VF Page -->

<apex:outputText value="{!MyCustomProperty}">

<apex:param assignTo="{!GetSetProperty}" value="Display this" />

</apex:outputText>

 

//Controller

public with sharing class MyPageController {

public String GetSetProperty {get; set;}

public String MyCustomProperty{

get{

return GetSetProperty;

}

}

}

 

Looking at the page lifecycle documentation, I'd expect the param assignTo setter to have already happened before the outputText binding to MyCustomProperty. But it's not happening.

 

There must be an easier way to pass params to Apex functions for use in dynamic VF pages (?)

 

Cool_DevloperCool_Devloper

As per what i have read in the docs, the dependency between methods in the controller should be minimal as the order of execution is not fixed.

So, the best practice says, do not rely on methods getting executed in the systematic order. In case, there is a dependency, then try invoking the other method explicitly.

Maybe, you can try something like this-


<!-- VF Page -->

<apex:smileysurprised:utputText value="{!MyCustomProperty}">

<apex:smileytongue:aram name="myProperty" value="Display this" />

</apex:smileysurprised:utputText>

 

//Controller

public with sharing class MyPageController {

public String GetSetProperty; 

public String MyCustomProperty{

get{

String myProperty = ApexPages.currentPage().getParameters().get('myProperty'); 

// Add ur logic here and see if the myProperty is set to "Display this" 

return GetSetProperty;

}

}

}

 

Cool_D 

benwrigleybenwrigley

Hi There,

 

Did you ever get this to work?

 

I'm having exactly the same issue:

 

 

                        <apex:outputText value="{!SiteAbbreviations}">
                            <apex:param name="pbid" value="{!pb.ID}" assignTo="{!SiteAbbreviations}"/>
                        </apex:outputText>

 

 

Get method simply doesn't get called at all.

 

TIA