This response is horrendously late because of my schedule, but the answers
are still useful.
On Mon, 23 Apr 2001, Regular Expression wrote:
> These are three unrelated questions that have arisen as I've learned Struts;
> I thought I'd lump them together for brevity's sake. I've perused quite a
> bit of documentation and never found answers to any of these, else I
> wouldn't resort to spamming the list.
>
> 1) While ActionForm.validate() can return some ActionErrors, it seems the
> only way an action itself can signal an error condition is to forward to an
> appropriate page--but even in this case, there is no standardized way to
> return descriptive error information. Might it not make sense to allow
> actions to somehow associate an ActionErrors with the ActionForward they
> return, and let the errors become available to the target? That way, an
> action can perform business logic-related validation from within its
> perform() method, and simply findForward("input") if it finds some error.
> Right now, I plan on remedying this by subclassing Action and providing a
> method which will stuff an ActionErrors into the request (with the
> appropriate attribute key) and forward to the "input" forward. This
> mechanism will break whenever someone decides to change the name of the key
> under which ActionErrors are stored.
>
The example application does something like this, because there are some
things you can check in a validate() method -- was the username
entered? -- and some things you cannot -- does this username exist in the
database?. Check out how the logon action
(org.apache.struts.webapp.example.LogonAction) creates its own
ActionErrors object, and then forwards to the input page, if it encounters
any problems that were not found by the validate() method.
> 2) Is there some way for my lowly Actions to get access to the
> ServletContext under which they're running? I'd like to be able to get the
> values of application-context variables.
>
You can call getServlet().getServletContext() to get the ServletContext
for your web application. From there, you can access application
attributes, call log() to write logging messages, and so on.
> 3) The user guide mentions that sessions may have a Locale associated with
> them, which will control the ResourceBundle used for things like the
> <bean:message> tag. But it fails to mention the name of the session key
> under which the Locale will be stored. Does anybody have an idea what the
> key is, and if it's subject to change between versions?
>
>
To reference this in your code, you should use the symbolic string
constant Action.LOCALE_STRING which resolves to the literal string value
"org.apache.struts.action.LOCALE".
Craig McClanahan