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
sreejasreeja 

how to return a value in visualforce page with a nonvoid method..

//this is a nonvoid method 

 public decimal  c1(){
    
       taxvalue=223.44;
        
     
          
    return taxvalue;
    
    } 


 visualforce i had used the commandbutton to dispaly the value of tax value,it is throughing an error .. how can it display it...

<apex:form>
<apex:commandButton value="returntest"  action="{!c1}" reRender="t"/>
    {!taxvalue}
</apex:form>  
Deepali KulshresthaDeepali Kulshrestha
Hi sreeja,
Greetings to you!
VF page : -

    <apex:page controller="userInputDisplay" showHeader="false" sidebar="false">

        <apex:form>
            <apex:pageBlock>
                <apex:pageMessages></apex:pageMessages>

                <apex:pageBlockSection>
                    <apex:inputText value="{!userInput}"/>
                    <apex:outputText value="{!empty}"/>
                </apex:pageBlockSection>
                <apex:pageBlockButtons>
                    <apex:commandButton action="{!doSubmit}" value="Submit"/>
                </apex:pageBlockButtons>

            </apex:pageBlock>
        </apex:form>
    </apex:page>
    
Class  : -

    public with sharing class userInputDisplay {

        public String userInput{get;set;}
        public String empty{get;set;}

        public PageReference doSubmit(){
            if(userInput==NULL || userInput=='' ){

                empty = 'Your value is empty';
                ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'Fail'));

            }
            else{

                empty = 'Your value is ' +userInput;
                userInput = '';
                ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.INFO, 'Pass'));
            }

            return null;
        }
    }
    
I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.

Thanks and Regards,
Deepali Kulshrestha.