0

I'm trying to display some text if a particular value is chosen on a picklist. I thought that I could do this by using reRender however I am wondering if I also need a method in my controller? I've been researching, but have not identified why the message is not rendering. Below is the section of the page:

<apex:pageBlockSection id="FlagType">
     <apex:inputField id="redflagtype" value="{!Loan_Memo__c.RedFlagType__c}" required="true">
        <apex:actionsupport event="onchange" rerender="Reminder" />
     </apex:inputField>       
     <apex:outputpanel id="Reminder" > 
          <apex:outputText value="You have selected Direct Pay, Please attach a copy of the check." rendered="{!Loan_Memo__c.RedFlagType__c == 'Direct Pay'}" /> 
      </apex:outputpanel>   
</apex:pageBlockSection>
3
  • 1
    You can't rerender an element wich have a rendered condition. Try to add an outputpanel as parent of your ouputText and rerender this panel. Commented Feb 14, 2017 at 17:09
  • So nest like this? <apex:outputpanel id="Reminder" > <apex:outputpanel > <apex:outputText value="You have selected Direct Pay, Please attach a copy of the check." rendered="{!Loan_Memo__c.RedFlagType__c == 'Direct Pay'}" /> </apex:outputpanel> </apex:outputpanel> I tried that but am still not seeing the text display? Commented Feb 14, 2017 at 17:13
  • 1
    I think it's already structured correctly in that regard. It seems to me like perhaps your actionSupport may not be firing.
    – Adrian Larson
    Commented Feb 14, 2017 at 17:19

2 Answers 2

1

I have tried to modify your code, putting an action at actionSupport and returning back the value from the controller.

So from the action it will call dummyActions() method of the controller, then assign the selected value in redFlagType variable.

Finally, based on redFlagType == 'Direct Pay' displaying the outputText

<apex:pageBlockSection id="FlagType">
     <apex:inputField id="redflagtype" value="{!Loan_Memo__c.RedFlagType__c}" required="true">
        <apex:actionsupport event="onchange" rerender="Reminder" action="{!dummyActions}"/>
     </apex:inputField>       
     <apex:outputpanel id="Reminder" > 
          <apex:outputText value="You have selected Direct Pay, Please attach a copy of the check." 
          rendered="{!redFlagType == 'Direct Pay'}" /> 
      </apex:outputpanel>   
</apex:pageBlockSection>

public String redFlagType {get; set;}
public PageReference dummyActions(){
    //do your stuff
    redFlagType = Loan_Memo__c.RedFlagType__c;
    return null;
}
1
  • on this line: redFlagType = Loan_Memo__c.RedFlagType__c I assume that I would actually use the variable that I've set? public Loan_Memo__c myMemo {get;set;} so it would read: redFlagType = mymemo.RedFlagType__c? I've tried that but I'm still not seeing the text displayed. Do I need to do something else to pass the value back to the controller? Commented Feb 14, 2017 at 18:02
1

I didn't realize that required fields would prevent rerender from firing. Enclosing the section in actionRegion tags solved the issue:

<apex:pageBlockSection id="FlagType">
   <apex:actionRegion>
        <apex:inputField id="redflagtype" value="{!Loan_Memo__c.RedFlagType__c}" required="true">
           <apex:actionsupport event="onchange" rerender="Reminder"  />
        </apex:inputField>       
        <apex:outputpanel id="Reminder" > 
                     <apex:outputText value="You have selected Direct Pay, Please attach a copy of the check." rendered="{!Loan_Memo__c.RedFlagType__c == 'Direct Pay'}" /> 
        </apex:outputpanel>  
    </apex:actionRegion>       
</apex:pageBlockSection> 

References:

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .