Hey Frank,

Check out this code from my first post using dojo.io.bind() :


function submitNewMail(){

//validateNewMail(form); //use javascript validate before form submit

      var bindArgs = {
      url: "<html:rewrite action="process_new_mail" />",
      error: function(type, data, evt){
          alert("An error occurred submitting new mail: " + data);
      },
      load: function(type, data, evt){

DWRUtil.setValue("social_mail_right_con", data); /* setValue doesn't execute javascript! */ document.getElementById('social_popup_layer_container').innerHTML=document.getElementById('ajax_hidden_helper').innerHTML;
          popup('social_popup_layer_container',true);

      },
      mimetype: "text/html",
      formNode: document.getElementById("compose_mail_form")
      };

      dojo.io.bind(bindArgs);
  }

I'm sure you're probably familiar with dojo, so forgive me if I'm beating a dead horse.

What happens here is that my action, /process_new_mail.do, processes like
a normal struts app,i.e., ActionForm.validate() gets called first.

If there are ActionErrors, the "input mapping" page is returned via the 'data' object.
It is the 'responseText'.

The error: argument:

error: function(type, data, evt){
          alert("An error occurred submitting new mail: " + data);
      }

is NOT called because no Javascript error was thrown.

Instead, the load: function is called:

function(type, data, evt){

DWRUtil.setValue("social_mail_right_con", data); /* setValue doesn't execute javascript! */ document.getElementById('social_popup_layer_container').innerHTML=document.getElementById('ajax_hidden_helper').innerHTML;
          popup('social_popup_layer_container',true);

      }


The line:

     DWRUtil.setValue("social_mail_right_con", data);

is what displays the response, which is the "input" page.

Anyways, if there are ActionErrors in the ActionForm and the server naturally forwards to
the input mapping in the struts-config,

Why doesn't APT get this same response?

Why doesn't it get forwarded to the "input" page automatically, returning it in the response?

Does it go through the ActionForm.validate() method in the first place?

If this could happen, you would pretty much have a drop-in solution!

I could be missing something, so feel free to yell at me, but if dojo does it
I can't see why this shouldn't work for APT also.

-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 17:47:06 -0400

draegoon Z wrote:
That CodeExecuter is nice!

Thanks! The interesting thing is that as of beta5, it doesn't matter what response handler you use, the script blocks will ALWAYS be executed. That's why there's a seemingly superfluous DoNothing handler... you may want to use that instead of CodeExecuter in some cases.

About below, I'm talking about when my MyForm (extends ActionForm, not Action) returns an ActionErrors object as it is configured in the example struts-config below.

Like if "to" parameter was supposed to be a valid email address and someone
entered: blah blah blah

Will this be handled normally, like a Non-Ajax struts action app, returning the
input mapping to display the errors, or whatever else.

That's what I kinda thought you meant :) I got confused because you showed an action mapping... anyway... if you took an existing Struts app that handled this, then no, APT would probably not work right... although it still could... imagine if the page that the input JSP renders is displayed in an iFrame... in that case, you could use the std:IFrame handler to re-render it, so you wouldn't have to change a thing about your app. Likewise, you could display it in a <div> and get the same effect.

However, more than likely your app isn't built this way today, so it wouldn't work unaltered. What you would more than likely do is copy the action mapping that uses that MyForm, and change the input attribute to point to a JSP that renders just a snippet of markup displaying the error. Then, insert that markup into a <div> using std:InnerHTML, or maybe pop it in an alert() with std:Alerter, etc. This way, you kind of have a "parallel" action mapping, one for the AJAX request, one for the regular form submission (I've done this in a proof of concept by the way, it works great).

-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]

Reply via email to