Here is a solution I came up with so far.  I wrote an action to
validate.  This calls my validateData() method.

 I Used the JSON plug in to return the fieldsErrors collection to dojo.

Here is some javascript:

Please note when looking at this that I have modified the original
template that displays error messages.   I also modified the
validation javascript addError to add errors to this box.  Hence the
null values.  I kept the same method signature in case someone needed
the old functionality. The old template would take the field name so
it could display the error message in the correct spot IIRC.

 function testAjaxSave() {

                    clearErrorMessages(null);

                    var kw = {
                        url:    '<s:url action="ValidateAction"/>',
                        load:    function(type, data, evt) {



                            for(i=0;i<data.error.length;i++) {
                                addError(null,data.error[i]);


                            }
                        },
                        method: "POST",
                        error: function(type, data, evt){
                            alert("error");
                        },
                        mimetype: "text/json",
                    };

                    dojo.io.bind(kw);

                }

I currently have this working.  But I still have a few questions:

First I wrote a method called validate.  At this point I found out
that I was overriding the ActionSupport method.  When I tried to find
more information on this method I couldn't.  When I search for XWork
or Struts 2 validation I always get the XML or Annotated validation.
These validations are too simple for the needs of this particular
form.

Where can I find out more information on how to implement the validate() method?
Will this method work with Ajax validation?
Will this require less work on my part if I do this?

My solution was very easy to implement thanks to the built in
fieldErrors and the JSON plug in.  I guess I'm just trying to find the
quickest and easiest way to do this.  I don't want to reinvent
anything if Struts can provide it out of the box.  By creating the
mechanism for populating the <s:fieldError/> did I rewrite somethign
that Struts can do for me?

On Thu, Jan 22, 2009 at 10:40 AM, Dave Newton <newton.d...@yahoo.com> wrote:
> Martin Gainty wrote:
>>
>> Richard-
>>
>> this is the AJAX doctype declaration from
>> src/main/resources/struts-ajax.xml
>>
>> <!DOCTYPE struts PUBLIC
>>    "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
>>    "http://struts.apache.org/dtds/struts-2.0.dtd";>
>> If you reference the URL you will see 4 distinct elements
>> <!ELEMENT struts (package|include|bean|constant)*>
>> Each element contains their own attribute list e.g.
>> <!ELEMENT result-type (param*)>
>> <!ATTLIST result-type
>>    name CDATA #REQUIRED
>>    class CDATA #REQUIRED
>>    default (true|false) "false">
>>
>> Did you have a question?
>
> IIRC the question was whether or not Ajax validation required the use of XML
> validation.
>
> Off the top of my head I don't actually know--since it takes about a minute
> to write a validate() method I'd probably just try it and see if it works.
>
> Dave
>
>>> From: richardsa...@gmail.com
>>> I was wondering if it is nessessary to use the XML for validation with
>>> Ajax?  I was hoping to use some validation on the server side action
>>> to do this.  Is it possible?
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
> For additional commands, e-mail: user-h...@struts.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
For additional commands, e-mail: user-h...@struts.apache.org

Reply via email to