Sounds great so far, but I think I lost you on the first part.
Let's work through a simple problem...
Let's say I have in my struts-config:
<action path="/my_action" forward="tile.my_action" />
<action path="/success" forward="tile.success" />
<action path="/error" forward="tile.error" />
<action name="MyForm" path="/process_my_action" input="/my_action.do"
scope="request" type="com.draegoonZ.action.MyAction">
<forward name="success" path="/success.do" />
<forward name="error" path="/error.do" />
</action>
First, what happens if MyForm just simply returns an ActionError?
Second, what if MyAction has ActionErrors and forwards to its 'error' page?
Are you saying that APT gets the response (JSP,text,HTML, whatever) and
matches
the regex to that entire response string?
If so, how do you advise setting flags in the response to ensure the proper
responseHandler
is called without neccessarily displaying the flag itself. Like,
THIS_IS_MY_UGLY_FLAG_BEFORE_CONTENT_AND_FIRST_IN_THE_RESPONSE:<p>content</p>
-Joe
-----------------------------------------------------------------------------------
WEB DESIGN BY DRAEGOONZ
Joseph "DraegoonZ" McGranaghan
http://www.draegoonZ.com
603-620-0854
[EMAIL PROTECTED]
From: "Frank W. Zammetti" <[EMAIL PROTECTED]>
Reply-To: "Struts Users Mailing List" <user@struts.apache.org>
To: Struts Users Mailing List <user@struts.apache.org>
Subject: Re: Struts and AJAX
Date: Mon, 03 Jul 2006 14:54:47 -0400
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]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]