[SalesForce] Showing String value in apex:outputText for visualforce

I have a method which is supposed to return a string. I now want to pass that method as a value to apex:outputText in order to see what the returned string is. However, I keep getting an error on the Visualforce Page which says that the method is an unknown property. What exactly is the problem? When I test a method which returns an integer, it seems to work perfectly.

Heres a basic breakdown in terms of code of what I'm trying to do:

public String showSAstring(){ 

String x= '';

        if(accwrapper.selected == true)
        {
            System.debug('TESTING');
            utility.selectedAssets.add(accwrapper.acc);
            x+='    ' +  accwrapper.acc.Name;
        }    

String showString = 'The substrings are'+x;
return showString;

}

and here is what my apex statement looks like:

<apex:pageBlockSection Title="Actions" >
                <apex:commandButton action="{showSAstring}" value="Submit"/>
                <apex:outputText value="{!showSAstring}"/>

            </apex:pageBlockSection>  

so basically when I press submit using the command button, it should go through my method. I'm only using outputText value right now to make sure I'm getting the right results and this will not be included in the final version of the method.

However, when i compile on developer console, it tells me that showSAstring is an unknown property.

Best Answer

This line of your code:

<apex:outputText value="{!showSAstring}"/>

is actually looking for a method named: getshowSAstring()

If you would like the string to display on initial load (without a button click), you could change your Apex to:

public String getshowSAstring() { 

String x= '';

        if(accwrapper.selected == true)
        {
            System.debug('TESTING');
            utility.selectedAssets.add(accwrapper.acc);
            x+='    ' +  accwrapper.acc.Name;
        }    

String showString = 'The substrings are'+x;
return showString;
}

And Visualforce:

<apex:pageBlockSection Title="Actions" >
    <apex:outputText value="{!showSAstring}"/>
</apex:pageBlockSection> 
Related Topic