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
Sonali GonnadeSonali Gonnade 

How to set inputtext value of VF page using Controller

Hi,

 

I want to set grandtotal value to input text using apex controller.

VF code is:

<apex:inputText value="{!gtotal}" id="gtotal"/> 
Controller code is like

 gtotal=gtotal- dto.price;

 

Here gtotal value is changed in controller  but not reflecting in VF page.

Please assist.

 

Thanks

Sonali 

 

bmabma

Do you have a get function associated with "gtotal"? Also, where is the assignment "gtotal = gtotal-dto.price" perform?

Sonali GonnadeSonali Gonnade

Yes I have called delete_item method/action on Delete button where I  used gtotal = gtotal-dto.price and I want to assign same changed gtotal on VF page. But VF page showing old value.

 

Thanks

Sonali

Pradeep_NavatarPradeep_Navatar

For getting the values of gtotle, make a getter and setter property in controller class:

 

        Public string gtotal{get;set;}

RamboRambo

Hi,

       I think this could help u out...

 

VF:

 

 

<apex:page controller="Remo">
<apex:form>
<apex:pageBlock>
<apex:pageBlockButtons>
<apex:commandButton action="{!done}" value="Done"/>
</apex:pageBlockButtons>
<apex:pageBlockSection title="first">
<apex:inputText value="{!gtotal}"/>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>

 

 

Controller:

 

public class Remo {

Integer gtotal = 0;

     public Integer getGtotal(){
     return gtotal;
     }
     
     public void setGtotal(Integer gt){
     gtotal = gt;
     }
      
    public PageReference done(){
    gtotal += 100;
    return null;
    }
}

 

Sonali GonnadeSonali Gonnade

Thanks for your quick help.

But no luck with Decimal data type.

Its working fine with Integer but not for Decimal. I have Decimal data type set for price.

Please assist.

 

Thanks

Sonali.

 

RamboRambo

Try changing the datatype to string and try converting to decimal.. I have tried this... just chk whether it ill be useful..

 

public class Remo {

String gtotal = '';
Decimal d ;

     public Decimal getGtotal(){
      return d;
     }
     
     public void setGtotal(String gt){
     gtotal = gt;
     }
     
           
    public PageReference done(){
     d =decimal.valueOf(gtotal);
    d += 100;
       return null;
    }
}

Sonali GonnadeSonali Gonnade

Thank you all for your quick help.