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

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

//this is a nonvoid method 

 public decimal  c1(){
    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:commandButton value="returntest"  action="{!c1}" reRender="t"/>
Deepali KulshresthaDeepali Kulshrestha
Hi sreeja,
Greetings to you!
VF page : -

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


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

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'));


                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.