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
Robin BarnwellRobin Barnwell 

Multiple apex:actionSupport event="onchange"

In my VisualForce page, if I have more than one apex:actionSupport event="onchange" then the event doesn't fire until a second input component is accessed.  If there is one then it fires immdiately.  If there anyway to make event fire everytime?

VF Code:
<apex:page controller="TextApex" >
<apex:form >
<apex:pageBlock >

<apex:selectRadio id="slctRd" dir="ltr" required="true" layout="pageDirection" value="{!selectedValue}" immediate="true">
<apex:actionSupport event="onchange" action="{!MethodOne}" reRender="test"/>
<apex:selectOptions id="selRdOptn" value="{!Options}"/>
</apex:selectRadio>

<apex:selectRadio id="slctRd1" dir="ltr" required="true" layout="pageDirection" value="{!selectedValue1}" immediate="true">
<apex:actionSupport event="onchange" action="{!MethodTwo}" reRender="test1"/>
<apex:selectOptions id="selRdOptn1" value="{!Options1}"/>
</apex:selectRadio>

<apex:outputText id="test" value="{!test}"></apex:outputText><br/>
<apex:outputText id="test1" value="{!test1}"></apex:outputText>

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

Apex:
public class TextApex {

    public String selectedValue {get; set;}
    public List<SelectOption> Options {get; set;}
    public String test {get;set;}
    
    public String selectedValue1 {get; set;}
    public List<SelectOption> Options1 {get; set;}
    public String test1 {get;set;} 
       
    public TextApex() {
        Options = new List<SelectOption>();
        Options.add(new SelectOption('test1', 'test1'));
        Options.add(new SelectOption('test2', 'test2'));

        Options1 = new List<SelectOption>();
        Options1.add(new SelectOption('test3', 'test3'));
        Options1.add(new SelectOption('test4', 'test4'));
    }
    
   public void MethodOne() { test = 'Hello World' + selectedValue ; }
   public void MethodTwo() { test1 = 'Hello World' + selectedValue1 ; }
}
Best Answer chosen by Robin Barnwell
Alain CabonAlain Cabon
Hi,

For this kind of problem,  <apex:actionregion> is often the solution.

https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_compref_actionRegion.htm
 
<apex:page controller="TextApex" >
    <apex:form >
        <apex:pageBlock >
            <apex:actionregion>
                    <apex:selectRadio id="slctRd" dir="ltr" required="true" layout="pageDirection" value="{!selectedValue}" immediate="true">
                    <apex:actionSupport event="onchange" action="{!MethodOne}" reRender="test"/>
                    <apex:selectOptions id="selRdOptn" value="{!Options}"/>
                </apex:selectRadio>
            </apex:actionregion>
            <apex:actionregion>
                    <apex:selectRadio id="slctRd1" dir="ltr" required="true" layout="pageDirection" value="{!selectedValue1}" immediate="true">
                    <apex:actionSupport event="onchange" action="{!MethodTwo}" reRender="test1"/>
                    <apex:selectOptions id="selRdOptn1" value="{!Options1}"/>
                </apex:selectRadio>
            </apex:actionregion>   
            <apex:outputText id="test" value="{!test}"></apex:outputText><br/>
            <apex:outputText id="test1" value="{!test1}"></apex:outputText>
            
        </apex:pageBlock>
    </apex:form>
</apex:page>

 

All Answers

Alain CabonAlain Cabon
Hi,

For this kind of problem,  <apex:actionregion> is often the solution.

https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_compref_actionRegion.htm
 
<apex:page controller="TextApex" >
    <apex:form >
        <apex:pageBlock >
            <apex:actionregion>
                    <apex:selectRadio id="slctRd" dir="ltr" required="true" layout="pageDirection" value="{!selectedValue}" immediate="true">
                    <apex:actionSupport event="onchange" action="{!MethodOne}" reRender="test"/>
                    <apex:selectOptions id="selRdOptn" value="{!Options}"/>
                </apex:selectRadio>
            </apex:actionregion>
            <apex:actionregion>
                    <apex:selectRadio id="slctRd1" dir="ltr" required="true" layout="pageDirection" value="{!selectedValue1}" immediate="true">
                    <apex:actionSupport event="onchange" action="{!MethodTwo}" reRender="test1"/>
                    <apex:selectOptions id="selRdOptn1" value="{!Options1}"/>
                </apex:selectRadio>
            </apex:actionregion>   
            <apex:outputText id="test" value="{!test}"></apex:outputText><br/>
            <apex:outputText id="test1" value="{!test1}"></apex:outputText>
            
        </apex:pageBlock>
    </apex:form>
</apex:page>

 
This was selected as the best answer
Robin BarnwellRobin Barnwell
Yes, that did the trick, many thanks!