0
<apex:page controller="testActionSupport">
 <apex:pageblock>
    <apex:form>
            <apex:pageblocksection id="pb">
                <apex:inputfield value="{!cont.lastname}" />
                <apex:inputField id="id3" value="{!cont.gender__c}" >
                    <apex:actionsupport event="onchange" action="{!checkgender}"  />
                </apex:inputField>
                <apex:inputfield id="id4" value="{!cont.Upanayanam__c}" rendered="{!id4rend}" />
                </apex:pageblocksection>
    </apex:form>
  </apex:pageblock>  
  </apex:page>

 Controller code

public class testActionSupport {
public Contact cont{get;set;}
public Boolean id4rend{get;set;}

public testActionSupport(){
    if (cont==null) {cont = new Contact();}
    id4rend=false;
}
public void checkGender(){
    system.debug('inside checkGender');
    if (cont.gender__c == 'Male'){
        id4rend=true;
    }
    else
    {id4rend=false;}

    }

  }

OK, here's the steps. First, when I choose the Gender, I'm being forced to enter the name, when I enter the name and then try to toggle around the gender, it works fine....But the additional fields don't show up automatically for the gender I selected previously (unless I come back and change it a second time), how do I get those extra fields displayed in this scenario automatically?

Any advise would be appreciated.

  • did you try immediate="true" on your actionSupport? – cropredy Jul 6 '15 at 20:53
  • Yes, I tried that but no luck. the page just refreshes but the additional fields aren't displayed. – JJSHHS Jul 6 '15 at 20:58
  • 1
    and did you try rerender= on the actionSupport. There are three "knobs" at play here - actionRegion (what gets sent to the controller), immediate="true" (bypasses form validations), and rerender= (decides which portions of the page are refreshed). Some or all of these may be needed. Note you should also add apex:pageMessages in order to see errors – cropredy Jul 6 '15 at 21:07
1
<apex:page controller="testActionSupport">
<apex:pageblock>
    <apex:form>
            <apex:pageblocksection id="pb">
                <apex:inputfield value="{!cont.lastname}" />
                <apex:inputField id="id3"  value="{!cont.gender__c}" >
                    <apex:actionsupport event="onchange" action="{!checkgender}"
                                        immediate="true" rerender="pb" />
                </apex:inputField>
                <apex:inputfield id="id4" value="{!cont.Upanayanam__c}" rendered="{!id4rend}" />
                </apex:pageblocksection>
    </apex:form>
  </apex:pageblock>  
 </apex:page>

This is how I modified the code. But it's still not working. I'm not using the ACTIONREGION attribute. Should I be using that attribute?

| improve this answer | |
  • Thanks Crop1645. It's working now after making the change as you suggested. – JJSHHS Jul 6 '15 at 22:10

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.