0

I have a basic form in which I need to fill in details about a Case. The form also has a section to fill out Account information. So my standard controller is Case with an extension: CaseInputFormExt

I create an Account mPerson in my constructor and then reference the fields in my visualforce page: <apex:inputText value="{!mPerson.PersonEmail}" />

My submit button calls a function validate() in which I perform some custom validation. In this case compare the value of mPerson.PersonEmail to a valid email regex. If it returns false (not a valid email) I show a custom ApexMessage error.

The problem is now if the user goes back, changes the email value, clicks submit again - the new value for mPerson.PersonEmail isn't changed in the controller.

Why are the new values on visualforce page not getting passed back into the controller?

  • 1
    Are you using reRender or immediate attributes, or actionRegion elements? There are a few reasons why the controller wouldn't be seeing the new values. – sfdcfox Dec 7 '15 at 18:06
  • Yes, I am using immediate on the submit button. The submit button also reRenders the section for ApexMessages. – Austin Nelson Dec 7 '15 at 18:25
  • @sfdcfox - it looks like the immediate=true was the cause. I removed it and it seems to be working. I just hope that does affect anything else. Thanks! – Austin Nelson Dec 7 '15 at 18:30
1

The immediate attribute, when set to true, skips all getters, setters, and default validations (e.g. required attribute on input fields). You should only be using immediate when you absolutely don't care about the input (e.g. you want to implement a cancel button that should work without passing validation).

You may be able to get away with using an actionRegion, although these are tricky to use. Basically, any action that occurs within the region only validates elements within that region (and only sets values from that region). This usually means an actionFunction will be involved, unless you can fit the button that calls the reRender within the actionRegion (this is usually pretty annoying to do).

However, any reRender or actionRegion that's less than the entire page usually results in some of the view state not being available in the controller; you can only explicitly depend on values that are bound to elements within the reRender or actionRegion area. You may also need to set renderRegionOnly to false in order to get your pageMessages element to see any new messages that appear as a result of the actionFunction executing. The entire thing might look like this:

<apex:form>
    <apex:pageMessages id="messages" />
    <apex:actionRegion renderRegionOnly="false" id="region1">
        <apex:actionFunction name="doSomething" action="{!validate}" reRender="region1,messages" />
        <apex:inputText value="{!myfieldvalue}" />
    </apex:actionRegion>
    <apex:commandButton onclick="doSomething(); return false;" value="Do Something" />
</apex:form>

You'll want to read the manual on actionRegion, as it'll probably take a few tries to get it working as you expect.

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.