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>
  • 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. – Martin Lezer Feb 14 '17 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? – Starley Flynn Feb 14 '17 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 Feb 14 '17 at 17:19
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;
}
  • 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? – Starley Flynn Feb 14 '17 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: Rerender not firing if required fields are empty and https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_compref_actionRegion.htm

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.