You need to sign in to do that
Don't have an account?
Big 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?
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
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
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
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?
Sorry, just read your reply properly - yes, as the values haven't been included in the postback, any rerendering will drop those values.
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!
Why would you rerender the section if those fields weren't submitted? Can you not just leave those as they are?
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.
Ah gotcha. That is a common problem. Are the fields required via FLS, or is this something that your page is enforcing?
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?
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.
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