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
Big EarsBig Ears 

Rerendering, validation rules and data retention

Hey folks,

 

Is there an elegant way to rerender a page (or area of a page) and retain the data that has been entered into any forms without running validation rules?

 

I have a segment of page that, upon refreshing, adds a new segment below. If the mandatory fields haven't been filled in, it won't allow the refresh (which is a bad experience for the user), but if I use the "immediate" tag in the rerender, the fields that HAVE been filled in get blanked out.

 

Is there a simple way around this?

Best Answer chosen by Admin (Salesforce Developers) 
bob_buzzardbob_buzzard
I think so. You'd have to enforce the requiredness in the controller and allow the submission that is associated with the rerender to bypass it, but the submission that moved on to the next stage would enforce it. You'd also have to roll your own markup to produce the red bar but not enforce it. Its all doable but does require a little effort.

If you are interested in going this route I've written up a couple of blog posts on field level error messages that might help:

http://bobbuzzard.blogspot.co.uk/2011/04/field-level-error-messages-with.html

http://bobbuzzard.blogspot.co.uk/2011/04/field-level-error-messages-with_29.html

The latter shows how to decorate the page etc.

All Answers

bob_buzzardbob_buzzard

Yes - check out the apex:actionregion tag - this just submits back part of the form, so you don't have to send back fields that will have validation applied.  

 

http://www.salesforce.com/us/developer/docs/pages/Content/pages_compref_actionRegion.htm

bob_buzzardbob_buzzard

There's a great blog on this from my fellow MVP Abhinav Gupta at:

 

http://www.tgerm.com/2010/09/visualforce-actionregion-deep-dive.html

AndyRouseAndyRouse

Bob,

 

Thanks for your quick response. If the fields aren't included in the action region, but are re-rendered, does that not mean that anything input into them will be lost?

bob_buzzardbob_buzzard
The values won't be lost, as they are still on the page in the HTML input elements. They don't go back to the controller until you submit the entire form.
bob_buzzardbob_buzzard

Sorry, just read your reply properly - yes, as the values haven't been included in the postback, any rerendering will drop those values.

AndyRouseAndyRouse

It's a shame there's no magic way around this. I may need to re-think my page set-up.

 

Thanks for your response, though!

bob_buzzardbob_buzzard

Why would you rerender the section if those fields weren't submitted?  Can you not just leave those as they are?

AndyRouseAndyRouse

It's a section with a list being repeated over. A button at the bottom says "Add a new segment". The rerender acts across the whole repeating section, with the controller adding a new element to the list being repeated over. I couldn't think of another way to present and re-render the repeating section.

bob_buzzardbob_buzzard

Ah gotcha.  That is a common problem.  Are the fields required via FLS, or is this something that your page is enforcing?

AndyRouseAndyRouse
It's page level.

Ideally, there'd be a way to allow the rerender on the page without issue, but the page wouldn't let you move onto the next stage in the process without filling in the fields.

I'm guessing that would have to be achieved within the controller?
bob_buzzardbob_buzzard
I think so. You'd have to enforce the requiredness in the controller and allow the submission that is associated with the rerender to bypass it, but the submission that moved on to the next stage would enforce it. You'd also have to roll your own markup to produce the red bar but not enforce it. Its all doable but does require a little effort.

If you are interested in going this route I've written up a couple of blog posts on field level error messages that might help:

http://bobbuzzard.blogspot.co.uk/2011/04/field-level-error-messages-with.html

http://bobbuzzard.blogspot.co.uk/2011/04/field-level-error-messages-with_29.html

The latter shows how to decorate the page etc.
This was selected as the best answer
AndyRouseAndyRouse
Thanks, Bob!

As it happens, I was looking at the first blog post of yours a couple of hours ago as I was Googling around this very issue!

Thank you for your time,
Andy