Originally posted by Scott Updike:
How do I access a request scoped attribute in the resulting error screen once the DynaValidatorForm has failed validation?
You don't. This has nothing to do with a
Struts limitation. It has to do with the way
Java EE Web Containers work.
Request scope means just that: It exists for the life of one request to the server and is gone after that. Once your Action class forwarded to the
JSP and the container processed the JSP and sent the plain HTML back to the browser, the request that was used during the creation of the JSP became out of scope. Even before the user re-submitted the page, the request was gone with no chance of getting it back.
There are several ways to work around this:
Put your variables in session scope rather than request scopeUse ActionForm properties rather than request scoped variables. ActionForm variables are carried forward from page to page even if the ActionForm itself is in request scope. If you have an ActionForm property for which there is no input field on the page and you want to preserve its value, put it in an <html:hidden> tag.Use client-side validation with JavaScript. That way if an error is reported, the page is not refreshed, so the fact that the variables are out of scope is not an issue.