Good questions! Let me see if I can answer them...
draegoon Z wrote:
What about errors in the ActionForm?
APT doesn't say anything at all about what happens on the server, so,
the short answer is its up to you :) The longer answer is that each of
the response handlers (as of the latest beta5 release) has a
matchPattern parameter, which is a regex... with that, you can examine
the response and either fire the handler or skip it.
So, for instance, it may be that you want to make an AJAX request when
the user clicks a button to do some validations... there are two
possible outcomes... one is an "OK" response, for which you just want to
put the returned message into a <div> let's say... the other outcome is
validation errors, in which case you want to pop the response via
alert() let's say. So, configure two response handlers:
<responseHandler type="std:InnerHTML" matchPattern="/ok/">
<parameter>myResultDiv</parameter>
</responseHandler>
<responseHandler type="std:Alerted" matchPAttern="/error/">
<parameter />
</responseHandler>
Now, my regex is a bit rusty, so pay attention more to the theory than
the details :) The idea is that the first handler will only fire is "ok
" is found in the response. Likewise, the second one will only fire if
"error" is found. Since you can absolutely use a JSP to render the two
responses, you use the same set of Struts skills as you always have to
create the response.
What about firing javascript function before the submit?
I.e., to validate the form (I don't use Validator).
As of the latest beta5 release, you can specify both a post-processing
and pre-processing function to do exactly that. You can set this on the
<group>, <element> or <event> levels.
Alternatively, if your really doing something more complex, you can
write a custom handler. This amounts to an entry in the config file
like so:
<handler name="MyHandler" type="request">
<function>MyJSHandler</function>
<location>local</location>
</handler>
From then on, you can use MyHandler as the value of the type attribute
of a <requestHandler> element. You can do whatever you want there, and,
you STILL won't have to write much code because you can use the built-in
RequestSender() function, which takes care of all the AJAX details for
you... you just write the "business logic", so to speak, and call
RequestSender() to take care of all the call details.
Does the Action have to return 'null' and write directly to the
response, or can the struts config still be used?
You can do either. Your response can be rendered via JSP, which we
actually recommend 99% of the time, so you can write your struts-config
the same as always. In fact, I've taken an existing Struts app and
added AJAX to it using APT, and all I had to do was alter the JSPs, the
actual code didn't even need a recompile!
-Joe
Frank
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]