Tuan,

(If this rambles since it is late at night for me, skip to the "WHY" section
below for suggestions)

What class does your below included Java come from?  Is it from a subclass
of Action or ActionForm?  I ask because of the following issues I have with
your code in Struts v1.2.NNNN:

o. Action does not have a validate() method.

o. Action has various saveErrors(...) methods but they all take ActionErrors
objects as parameters, not ActionError or ActionMessage.

o. The ActionForm.validate() method you would probably need (in 1.2.X) has
this signature, which is NOTHING like the method signature your cut/pasted
below:

public ActionErrors validate(ActionMapping mapping,
        javax.servlet.http.HttpServletRequest request)

o. ActionForms do not have any saveErrors(), saveMessages(), addErrors(), or
addMessages() methods. If your below code is for an ActionForm, then your
Java error messages, also included below, make complete sense.

WHY DID I POINT ALL OF THIS OUT?

This makes me think that the code you listed isn't ever going to be
automatically invoked by the Struts servlet. Well, not unless you're doing
something special in your Action.execute() method to call your
validate(request) method which has it's own custom signature.  So, I
recommend you put your validate() method in a subclass of ActionForm, push
your errors or other messages into an ActionErrors instance, and return that
ActionErrors instance from the ActionForm.validate() method as the JavaDocs
indicate is the normal procedure.  Again, you could make your own validate
method in your Action instance, but you would have to add a hook to create
it as Struts doesn't invoke any validate() named methods on an Action.

I hope all of that made sense.  I tend to babble when I write after midnight
(my time).

Regards,
David

-----Original Message-----
From: Tuan Jean Tee [mailto:[EMAIL PROTECTED]
Sent: Thursday, August 18, 2005 12:06 AM
To: user@struts.apache.org
Subject: RE: What do you do with ActionError in Struts 1.2

David,

Thank you for the good link. Base on it, I have change the code to the
following:
----------------------------------------------------------------------------
--------
import javax.servlet.http.HttpServletRequest;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessages;
import org.apache.struts.action.ActionMessage;
import org.apache.struts.util.MessageResources;
.
.
.
public ActionMessage validate(HttpServletRequest request) {
    ActionMessages messages = new ActionMessages();

    if (firstName == null || firstName.trim().equals("")) {
          messages.add( ActionMessages.GLOBAL_MESSAGE,
                        new ActionMessage( "not.authorized.for.account"
) );
        saveErrors(request,messages);
      }
}

----------------------------------------------------------------------------
--------
I have got the error of:
The method saveErrors is undefined.
Have I missed out anything.
Thank you again.
Regards,
Tuan

>>> [EMAIL PROTECTED] 18/Aug/2005 12:27:14 pm >>>
Tuan,

I think you should check out various wiki sections relating to the
versions
you're using and the one you plan on switching over to.  You probably
want
to scroll down to the section marked "ActionError(s) and
ActionMessage(s)"
in the page: http://wiki.apache.org/struts/StrutsUpgradeNotes11to124

Regards,
David

-----Original Message-----
From: Tuan Jean Tee [mailto:[EMAIL PROTECTED]
Sent: Wednesday, August 17, 2005 10:14 PM
To: user@struts.apache.org
Subject: What do you do with ActionError in Struts 1.2

I am learning Struts 1.2 and would like to find out what is the
replacement
for ActionError knowing it's deprecated in Struts 1.2

if (firstName == null || firstName.trim().equals(""))
{
        errors.add("firstName", new
                ActionError("error.cust.firstname.empty"));
}


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to