1

I have a code in which I am calling change method on select Radio.. Code

<apex:form >
    <apex:selectRadio value="{!kind}">
        <apex:selectOptions value="{!choice}"/>
        <apex:actionSupport event="onchange" reRender="up" action="{!change}"/>  <!-- Change is Working -->
        </apex:selectRadio>
    <apex:selectRadio id="up" value="{!fooditem}">
        <apex:selectOptions value="{!offer}"/>
        </apex:selectRadio>
</apex:form>

In the above code, change is working well but If I update my code as follow, Change is not Working..Please help out

<apex:form >
       <apex:pageBlock title="New Account">
            <apex:pageBlockButtons >
                <apex:commandButton action="{!save}" value="Save"/>
            </apex:pageBlockButtons>
        <apex:pageBlockSection title="Add New Account">
            <apex:inputField value="{!acc.Name}"/>
            <apex:inputField value="{!acc.Website}"/>
            <apex:inputField value="{!acc.Phone}"/> 
            <apex:selectRadio value="{!kind}">
                <apex:selectOptions value="{!choice}"/>
                <apex:actionSupport event="onchange" reRender="up" action="{!change}"/> <!-- Change is not Working -->
            </apex:selectRadio>
            <apex:selectRadio id="up" value="{!fooditem}">
                <apex:selectOptions value="{!offer}"/>
            </apex:selectRadio>
        </apex:pageBlockSection>
    </apex:pageBlock>
</apex:form>
  • Not working in the sense change method not getting invoked? – Reshma Oct 23 '18 at 5:57
  • Yes,Change is not getting invoked – Akshit Gupta Oct 23 '18 at 5:57
1

From your code, it seems that during testing you are not entering mandatory input values which have been specified in inputField.

Better, you should wrap the actionSupport code snippet within actionRegion so that it should not depend on any other inputs.

<apex:pageBlockSection title="Add New Account">
    <apex:inputField value="{!acc.Name}"/>
    <apex:inputField value="{!acc.Website}"/>
    <apex:inputField value="{!acc.Phone}"/> 
    <apex:actionRegion>
        <apex:selectRadio value="{!kind}">
            <apex:selectOptions value="{!choice}"/>
            <apex:actionSupport event="onchange" reRender="up" action="{!change}"/> <!-- Change will work here -->
        </apex:selectRadio>
    </apex:actionRegion> 
    <apex:selectRadio id="up" value="{!fooditem}">
        <apex:selectOptions value="{!offer}"/>
    </apex:selectRadio>
</apex:pageBlockSection>
0

Here's an additional wrinkle on why it appears sometimes that your actionSupport action isn't executing:

A snippet of a simple controller

public String selectedOption {get; set;}
public Boolean getIsFoo() {return selectedOption=='Foo';}
public Boolean getIsBar() {return selectedOption=='Bar';} 

A simple page with a radio button that controls whether one of two outputPanels is rendered (given two radio button option: Foo and Bar

<apex:page ....>
  <apex:pageMessages/>
  <apex:selectRadio value="{!selectedOption}"  layout="pageDirection">                         
    <apex:selectOptions value="{!options}"/>
    <apex:actionSupport reRender="fooOP,barOP" event="onchange"/>
  </apex:selectRadio>

  <apex:outputPanel id="fooOP">
    <apex:pageBlock rendered="{!isFoo}">
    <apex:selectList value="{!selectedItem}" required="true"/>
      <apex:selectOptions value="{!itemOptions}"/>
      ... other components ...
    </apex:pageBlock>
  </apex:outputPanel>

  <apex:outputPanel id="barOP">
    <apex:pageBlock rendered="{!isBar}"/>
  </apex:outputPanel>

</apex:page>

With this sequence:

  1. Display page, neither pageBlock Foo nor Bar is displayed as no radio button has been selected
  2. Choose radio button Foo; the actionSupport sends the form data (at this point, only the radiobutton) to the controller and the getter isFoo() returns true, the getter isBar() returns false. The Foo pageblock is rendered
  3. Choose radio button Bar
  4. Because actionSupport has scope of the entire form (absence of actionRegion), the page attempts to send the form data but because there is a required= attribute on Foo's pageblock's selectList, there is an error. This error will not appear in pageMessages (observed V43). The rerender still occurs but because the controller never was sent any data, it looks as if the radio button click had no affect.

As @santanuboral points out, using actionRegion to scope the fields sent to the controller bypasses the required= attributes on other parts of the form and avoids this masked error.

related post on required field error message display

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.