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
Starz26Starz26 

Rerender Outputpanel does not seem to update data inside the outputpanel

I have a checkbox on a VF page that when checked sets a controller value to TRUE.

 

It rerenders and outputpanel with an apex:inputfield inside that displays a value say 12345.

 

The action on the checkbox causes the controller to set the value of the field in the controller (the same field that in in the inputfield) to say 4567.

 

Saving the record at this point save the correct value 4567 in the record.

 

HOWEVER, if I uncheck the checkbox, the outputpanel is again shown (rendered is based on the controller variable for the checkbox), BUT the value in the inputfield is the original value. 

 

If I save at this point the value saved is 12345.

 

Example code would be

 

 

public class simpletest{

public account a {get;set;}
public boolean isselected {get;set;}

    public simpletest(apexpages.standardcontroller con){
        a = (account)con.getRecord();
        a.BillingPostalCode = '12345';
    }


    public void changevalue(){
    
        if(isselected)
            a.billingpostalcode = '99999';
    
    }

}

 

<apex:page standardcontroller="Account" extensions="simpletest">
<apex:form >
  <apex:inputCheckbox value="{!isselected}" >
  <apex:actionSupport event="onchange" action="{!changeValue}" rerender="opp"/>
</apex:inputCheckBox>

<apex:outputPanel id="opp" layout="block">
<apex:pageblock id="thepgblk" rendered="{!!isSelected}">
<apex:pageblockSection >
<apex:inputfield value="{!a.billingPostalCode}"/>
</apex:pageblockSection>
</apex:pageblock>
</apex:outputPanel>
<apex:commandButton value="Save" action="{!save}" rerender="nothing"/>
</apex:form>
</apex:page>

 

 

 

anyone have any ideas as to why when the outputpanel is shown again it is not updated with the current value but infact reset the value to what was originally there?

 

Steps to reproduce:

 

1. Open VF page with know account id as ID parameter

2. Check the check box

   - The outputpanel dissapears and the controller sets the zip to 99999

3. Click save

4. Note on the account the billing zip is 99999

 

Not open the page again

 

1. Check the check box (we proved that is set the zip to 9999 above

2. Now uncheck the checkbox

3. NOTE the input field has 12345 in it

4. Click save

5. Note the Zip is now 12345

   - No where in the controller did it set the value back.

  - It appears when the outputpanel is rendered again only the setters fire and the getters do not. (Is this expected)

themattythematty

I do appoligize if I have misinterpreted what you want here, but are you saying that on check it does not display 99999, but only on save and re-open it shows 99999?  It's posssible that by using the standard controller to get the postalcode will only get the db's postalcode value of that record.  Have you tried creating a string that instaniates with the postalcode and changes with the check box?

 

 

 

public class simpletest{

public account a {get;set;}
public boolean isselected {get;set;}
public string postalCode {get; set;}
public simpletest(apexpages.standardcontroller con){ a = (account)con.getRecord(); postalCode = a.BillingPostalCode; } public void changevalue(){ if(isselected)
{ postalCode = '99999';
}
else
{
postalCode = a.BillingPostalCode;
} } }