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
Pooja05Pooja05 

Rerender is not working

<apex:outputText value="Use the same address as sold to"/>
    <apex:inputCheckBox value="{!useSameAddress}">
        <apex:actionSupport event="onchange" rerender="shipTo, billTo"/>
    </apex:inputCheckBox>
    <apex:pageBlockSection title="Partner Function Information"columns="2" collapsible="true">
     <apex:inputField id="shipTo" value="{!quote.Ship_To__c}" rendered="{NOT(!useSameAddress)}"/>
    <apex:inputField id="billTo" value="{!quote.Bill_To__c}" rendered="{NOT(!useSameAddress)}"/>

    </apex:pageBlockSection>

 

when I check the box, the input fields dont show up. The value of useSameAddress doesnt change. i have getter and setter functions for useSameAddress in the apex class.

 

Can you please help?

 

 

Thanks,

Pooja

Best Answer chosen by Admin (Salesforce Developers) 
jwetzlerjwetzler

Not what I meant.  Did you see the part where I said outputText is not outputting an id so there's nothing to rerender?

 

 

<apex:page controller="Sample"> <apex:form > <apex:inputCheckBox id="myCheckBox" value="{!checkBoxValue}"> <apex:actionSupport event="onclick" reRender="shipTo"/> </apex:inputCheckBox> <apex:outputPanel id="shipTo"> <apex:outputText value="hello" rendered="{!checkBoxValue}" /> </apex:outputPanel> </apex:form> </apex:page>

 


 

All Answers

jwetzlerjwetzler
Well the first thing I see wrong is your rendered attribute.  I think what you mean is {!NOT(useSameAddress)}
Pooja05Pooja05

I changed it but didnt work. Simplified the versionbelow also doesnt work.

 

<apex:page controller="Sample">
    <apex:form >
        <apex:inputCheckBox id="myCheckBox" value="{!checkBoxValue}"> 
            <apex:actionSupport event="onclick" reRender="shipTo"/>
        </apex:inputCheckBox>

        <apex:outputText id="shipTo" value="hello" rendered="{!checkBoxValue}" /> 

    </apex:form>
</apex:page>

 

public class Sample
{
    boolean checkBoxValue;
    public boolean getCheckBoxValue()
    {
        return checkBoxValue;
    }   
    public void setCheckBoxValue(boolean checkBoxValue)
    {
        this.checkBoxValue = checkBoxValue;
    }
}

jwetzlerjwetzler

So your second example doesn't work because outputText doesn't actually output any kind of tag with an id, it just outputs the text.  So there's nothing there to rerender.  Yes, we consider this a bug and have been discussing how to handle it (most likely if you specify an id with outputText we will output a span).  If you wrap your outputText in an outputPanel and rerender that instead, it will work.

 

I'd have to dig into why you're having the same issue with inputField but for now you should just rerender the pageBlockSection instead of each individual inputField. 

Pooja05Pooja05

I wrapped it into outputPanel and also used a formula as well.

It still doesnt work.

 

<apex:page controller="Sample">
    <apex:form >
        <apex:inputCheckBox id="myCheckBox" value="{!checkBoxValue}"> 
            <apex:actionSupport event="onclick" reRender="panel"/>
        </apex:inputCheckBox>
   
    <apex:outputPanel id="panel" rendered="{!checkBoxValue}">
        <apex:outputText id="shipTo" value="{!hello}" /> 
    </apex:outputPanel>
    </apex:form>
</apex:page>

 

public class Sample
{
    boolean checkBoxValue;
    public boolean getCheckBoxValue()
    {
        return checkBoxValue;
    }   
    public void setCheckBoxValue(boolean checkBoxValue)
    {
        this.checkBoxValue = checkBoxValue;
    }
    String hello = 'hey';
    public String getHello()
    {
        return hello;
    }
    public void setHello(String hello)
    {
        this.hello = hello;
    }
}

jwetzlerjwetzler

Not what I meant.  Did you see the part where I said outputText is not outputting an id so there's nothing to rerender?

 

 

<apex:page controller="Sample"> <apex:form > <apex:inputCheckBox id="myCheckBox" value="{!checkBoxValue}"> <apex:actionSupport event="onclick" reRender="shipTo"/> </apex:inputCheckBox> <apex:outputPanel id="shipTo"> <apex:outputText value="hello" rendered="{!checkBoxValue}" /> </apex:outputPanel> </apex:form> </apex:page>

 


 

This was selected as the best answer
Pooja05Pooja05

If you see in message 5, I am using hello as a variable in the controller class.

 

Am I understanding this wrong? Can you write a sample code or correct my code? My actual code (which as inputFields which should be rendered when a check box is selected and another scenario where inputFields should be rendered based on a dropdown selection) is a little different. But if this concept works it should work. 

 

 

Thanks a lot for all the help so far !! I have to get this working before Monday morning EST.

 

 

Pooja.

jwetzlerjwetzler
put id="thePageBlockSection" on your pageBlockSection, and change your rerender on your actionsupport from shipTo,billTo to rerender="thePageBlockSection".  Follows the exact same logic that my corrected example follows.
Pooja05Pooja05

Thanks a tonne!!

 

 

It works perfect now..

 

Apart from rerendering the pageBlockSection i was writing the rendered attribute with the pageBlockSection which was messing it up.

 

 

Thanks again,

Pooja