struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Marco Tedone" <mted...@jemos.org>
Subject Re: Struts doesn't execute my ActionForm.
Date Sun, 08 Jun 2003 17:02:06 GMT
Tom, the type attribute in the action element should point to an Action, not
to a class which extends the ActionForm class, therefore the source you
enclosed in your mail seems to be correct, but shouldn't be indicated in the
input attribute. When you indicate the attribute 'validate' = true, the
validate() method of your ActionForm will be executed.

Your element could be written something like the following:

<action path="/postTest"
        input="/jsp/postTest.jsp"
        name="postTestForm"
        scope="request"
        validate="true"
        type="com.mycompany.PostTestAction">
  <forward name="posttest.success" path="/execute/homePageSetup"/>
</action>

provided that postTestForm has been declared as
"com.mycompany.PostTestAction" in the <form-beans> element. If you declared
it as a DynaValidatorForm or a DynaValidatorActionForm, then your validation
should pass through the validation.xml file.

The input attribute tells the framework only where to redirect the control
if an exception is thrown in the executed Action.

Marco

----- Original Message ----- 
From: "Thomas Miskiewicz" <thomas.miskiewicz@web.de>
To: "Marco Tedone" <mtedone@jemos.org>; "Struts Users Mailing List"
<struts-user@jakarta.apache.org>
Sent: Sunday, June 08, 2003 5:37 PM
Subject: Re: Struts doesn't execute my ActionForm.


> Marco,
>
> > >       <action path="/postTest"
> > >              input="/WEB-INF/jsp/postTest.jsp"
> > >             name="postTestForm"
> > >             scope="request"
> > >             validate="true"
> > >             type="com.mycompany.PostTestForm">
> > >             <forward name="posttest.success"
> > path="/execute/homePageSetup"/>
> > >       </action>
>
> > the input elemement should not contain the /WEB-INF specification (but I
> > could be wrong).
>
> I tried it already. You mean input="/postTest", right? I doesn't work too.
> I'm being send to the application entrypage anyway. Can you explain what
> the %20name= thing in the URL is? I have no idea where does it come
> from...
>
> >It seems to me also that as type you specified a class
> > representing your Form more than the action to execute.
>
> The class specified as type is the ActionForm for the HTML form.
> Here how it looks like:
>
> package com.mycompany;
>
> import org.apache.struts.action.Action;
> import org.apache.struts.action.ActionMapping;
> import org.apache.struts.action.ActionForm;
> import org.apache.struts.action.ActionForward;
> import org.apache.struts.action.ActionErrors;
> import org.apache.struts.action.ActionError;
> import org.apache.struts.action.ActionServlet;
> import org.apache.struts.util.MessageResources;
>
> import javax.servlet.http.HttpServletRequest;
> import javax.servlet.http.HttpServletResponse;
> import javax.servlet.http.HttpSession;
>
> import java.lang.String;
>
> public class PostTestForm extends ActionForm
> {
>    private String field1 = "";
>    private String field2 = "";
>    private String field3 = "";
>
>    private void checkForEmpty(String fieldName, String fieldKey, String
> value,
>                               ActionErrors errors)
>    {
>     if (value.trim().length() == 0)
>     {
>   System.out.println("***checkForEmpty***");
>      ActionError error = new ActionError("error.posttest.field.null",
> fieldName);
>      errors.add(fieldKey, error);
>     }
>    }
>
>    private void checkForLength(String fieldName, String fieldKey, String
> value,
>                                int maxLength, ActionErrors errors)
>    {
>     if (value.length() > maxLength)
>     {
>      ActionError error =  new ActionError("error.posttest.field.length",
> fieldName);
>      errors.add(fieldKey, error);
>     }
>    }
>
>
>    public ActionErrors validate(ActionMapping mapping,
>      HttpServletRequest request)
>    {
>     ActionErrors errors = new ActionErrors();
>
>     checkForEmpty("field1", "error.field1.empty", getField1(), errors);
>     checkForEmpty("field2", "error.field2.empty", getField2(), errors);
>     checkForEmpty("field3", "error.field3.empty", getField3(), errors);
>     System.out.println("***checkForEmpty zu Ende***");
>
>     checkForLength("field1", "error.field1.lenght", getField1(), 5,
errors);
>     checkForLength("field2", "error.field2.lenght", getField2(), 5,
errors);
>     checkForLength("field3", "error.field3.lenght", getField3(), 5,
errors);
>
>     return errors;
>    }
>
>    public void reset(ActionMapping mapping, HttpServletRequest request)
>    {
>     field1 = "";
>     field2 = "";
>     field3 = "";
>    }
>
>    public String getField1()
>    {
>     return field1;
>    }
>
>    public void setField1(String feld1)
>    {
>     this.field1 = field1;
>    }
>
>    public String getField2()
>    {
>     return field2;
>    }
>
>    public void setField2(String field2)
>    {
>     this.field2 = field2;
>    }
>
>    public String getField3()
>    {
>     return field3;
>    }
>
>    public void setField3(String field3)
>    {
>     this.field3 = field3;
>    }
>
> }
>
> I'm sitting on it since couple of hours already, but I'm no step further.
> I using the Professional Struts Applicatons book. I wonder if there
> are some many error in there or what else is going on?
>
> Thanks
> Tom
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: struts-user-help@jakarta.apache.org
>




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


Mime
View raw message