[SalesForce] Problem with action region and apex:actionfunction

i am using action function as i need values of form in my controller after an on change event is fired.but there are some required fields also.when i change some value in dropdown action function is called and it gives the required validation error on other required fields .when i fill them and again onchange event is fired ,i get the changed value in backend.but i want that it should avoid the required validation error on other fields for that i use immediate="true " with action function but now it does not gives required error but in my controller method i did not get values.whats the reason for that .how can i overcome this?

<apex:actionRegion >
    <!-- Displaying Personal Data section -->
    <apex:repeat value="{!contactInformation}" var="contact" rendered="{!contactInformation.size>0}">
        <apex:repeat value="{!ContactFields}" var="contactInfo">
            <apex:pageBlockSection columns="2" title="Contact Information">
                <apex:repeat value="{!Fields}" var="current">
                    <apex:inputField styleClass="country" label="Country"  value="{!contact[current.fieldPath]}" onChange="dynamicConditions();" required="{!OR(current.required, current.dbrequired)}"/>  
                 </apex:repeat>
            </apex:pageBlockSection>          
        </apex:repeat>
    </apex:repeat>
    <apex:commandButton title="Save" value="Save" action="{!save}"/>
</apex:actionRegion>
    <apex:actionFunction name="dynamicConditions" action="{!dynamicConditions}"/>

Best Answer

Buried in the order of execution for visualforce postback requests section of the docs is this nugget of information:

During a postback request, the view state is decoded and used as the basis for updating the values on the page. Note: A component with the immediate attribute set to true bypasses this phase of the request. In other words, the action executes, but no validation is performed on the inputs and no data changes on the page.

So if you use immediate, it doesn't just skip the validation, it also discards the user input.

I think your problem should be solved by moving the actionFunction inside the actionregion - otherwise it will be posting back the entire form, including any required fields, rather than just your selected components.

Related Topic