You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Thomas Miskiewicz <th...@web.de> on 2003/06/08 14:32:33 UTC

Struts doesn't execute my ActionForm.

Hi!

I have a small HTML-Form with 3 textfields. I've implemented the validation
rules in the validate() method of the ActionForm belonging to the html form.
Unfortunately Struts isn't using the ActionForm. Why?

Here my struts-config.xml

<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts
Configuration 1.1//EN"

"http://jakarta.apache.org/struts/dtds/struts-config_1_1.dtd">

<struts-config>
   <form-beans>
     <form-bean name="postTestForm"
                type="com.mycompany.PostTestForm"/>
   </form-beans>

   <global-forwards type="org.apache.struts.action.ActionForward">
      <forward name="system.error" path="/WEB-INF/jsp/systemError.jsp"/>
      <forward name="default.action" path="/execute/homePageSetuo"/>
   </global-forwards>

   <action-mappings>

      <action path="/homePageSetup"
              type="com.mycompany.HomePageSetupAction"
              unknown="true">
              <forward name="homepage.success"
path="/WEB-INF/jsp/homePage.jsp"/>
      </action>

      <action path="/postTestSetup"
             type="com.mycompany.PostTestSetupAction"
             name="postTestForm"
             scope="request"
             validate="false">
             <forward name="posttest.success"
path="/WEB-INF/jsp/postTest.jsp" />

      </action>

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

   </action-mappings>
</struts-config>

The validation checks, if the fields are not empty. Even through the fields
are
being empty, when I press the Submit button the applications presents me
the entryform of the whole application. Also the URL looks pretty strange
http://localhost/myapp/execute/postTest%20name=
What doesn the %20name= mean? I think this is part of the problem.
Can someone please tell me what am I doing wrong here?

Regards
Tom


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


Errata

Posted by Marco Tedone <mt...@jemos.org>.
----- Original Message ----- 
From: "Marco Tedone" <mt...@jemos.org>
To: "Struts Users Mailing List" <st...@jakarta.apache.org>; "Thomas
Miskiewicz" <th...@web.de>
Sent: Sunday, June 08, 2003 6:02 PM
Subject: Re: Struts doesn't execute my ActionForm.


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

    Sorry, here I had to say: provided that postTestForm has been declared
as "com.mycompany.PostTestForm" 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" <th...@web.de>
> To: "Marco Tedone" <mt...@jemos.org>; "Struts Users Mailing List"
> <st...@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
>




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


Re: Struts doesn't execute my ActionForm.

Posted by Marco Tedone <mt...@jemos.org>.
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" <th...@web.de>
To: "Marco Tedone" <mt...@jemos.org>; "Struts Users Mailing List"
<st...@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


Re: Struts doesn't execute my ActionForm.

Posted by Marco Tedone <mt...@jemos.org>.
----- Original Message ----- 
From: "Thomas Miskiewicz" <th...@web.de>
To: "Struts Users Mailing List" <st...@jakarta.apache.org>
Sent: Sunday, June 08, 2003 6:02 PM
Subject: Re: Struts doesn't execute my ActionForm.


> > I am new to Struts and learning myself but from what I have read the
> > input attribute is for validation if the form/Action fails it will
> > send it back to the view.
> My book states:
> "input - Used to define where the user should be redirected, if a
validation
> error occurs. Usually, the user is redirected back to the JSP page where
> the data was submitted."

    Correct.
>
> And this is exactly what I'm doing. I want to send the user back to the
> PostTest.jsp form to let him correct his entry and I want to tell him
which
> part is wrong showing error messages.
>
> And know that you should never has .jsp
> > pages located in your WEB-INF directory. Just an idea.
>
> I'm new to Struts too. But this is what I got from the Professional
> Struts Applications from WROX. They've placed the the jsp directory
> containing all jsps unter WEB-INF. BTW I wouldn't know what's the
> trouble with that would be?

    You can have jsp under WEB-INF and it's not a bad practice. Usually you
may want it for security reasons, as everything put under WEB-INF cannot be
accessed directly from clients.

>
> Thanks
> Tom

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


Re: Struts doesn't execute my ActionForm.

Posted by Sloan Bowman <sm...@nashlinux.com>.
With most Container's you always want to lock down the WEB-INF 
directory from any external access. If you use the container with 
lets say apache you would use the <Location> Override all deny etc.. 
to keep users out of this directory. Again though this is coming from 
the jsp/Servlet standpoint. With Struts framework you are using 
RequestDispatchers to access the files which will not reveal the 
location of the file and you should be able to access it because its 
not going through tcp/ip. So yes it will work but not recommend by 
several books I have read.


>  > I am new to Struts and learning myself but from what I have read the
>>  input attribute is for validation if the form/Action fails it will
>>  send it back to the view.
>My book states:
>"input - Used to define where the user should be redirected, if a validation
>error occurs. Usually, the user is redirected back to the JSP page where
>the data was submitted."
>
>And this is exactly what I'm doing. I want to send the user back to the
>PostTest.jsp form to let him correct his entry and I want to tell him which
>part is wrong showing error messages.
>
>And know that you should never has .jsp
>>  pages located in your WEB-INF directory. Just an idea.
>
>I'm new to Struts too. But this is what I got from the Professional
>Struts Applications from WROX. They've placed the the jsp directory
>containing all jsps unter WEB-INF. BTW I wouldn't know what's the
>trouble with that would be?
>
>Thanks
>Tom
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
>For additional commands, e-mail: struts-user-help@jakarta.apache.org
>* 141 FETCH (FLAGS (\Seen))


-- 
Sloan Bowman
www.nashlinux.com
www.q3networks.com
www.aboutgoodlettsville.com
www.spudibby.com
---------------------------
Windows 95/NT - 32 bit extensions and a graphical shell for a 16 bit 
patch to an 8 bit operating system originally coded for a 4 bit 
microprocessor, written by a 2 bit company that can't stand 1 bit of 
competition.

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


Re: Struts doesn't execute my ActionForm.

Posted by Thomas Miskiewicz <th...@web.de>.
> I am new to Struts and learning myself but from what I have read the
> input attribute is for validation if the form/Action fails it will
> send it back to the view.
My book states:
"input - Used to define where the user should be redirected, if a validation
error occurs. Usually, the user is redirected back to the JSP page where
the data was submitted."

And this is exactly what I'm doing. I want to send the user back to the
PostTest.jsp form to let him correct his entry and I want to tell him which
part is wrong showing error messages.

And know that you should never has .jsp
> pages located in your WEB-INF directory. Just an idea.

I'm new to Struts too. But this is what I got from the Professional
Struts Applications from WROX. They've placed the the jsp directory
containing all jsps unter WEB-INF. BTW I wouldn't know what's the
trouble with that would be?

Thanks
Tom


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


Re: Struts doesn't execute my ActionForm.

Posted by Sloan Bowman <sm...@nashlinux.com>.
I am new to Struts and learning myself but from what I have read the 
input attribute is for validation if the form/Action fails it will 
send it back to the view. And know that you should never has .jsp 
pages located in your WEB-INF directory. Just an idea.

--Sloan

>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
>* 141 FETCH (FLAGS (\Seen))



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


Re: Struts doesn't execute my ActionForm.

Posted by Thomas Miskiewicz <th...@web.de>.
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


Re: Struts doesn't execute my ActionForm.

Posted by Marco Tedone <mt...@jemos.org>.
I'm not sure, but it seems to me that in the following:


>       <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). It seems to me also that as type you specified a class
representing your Form more than the action to execute.

Hope it will help,

Marco
----- Original Message ----- 
From: "Thomas Miskiewicz" <th...@web.de>
To: <st...@jakarta.apache.org>
Sent: Sunday, June 08, 2003 1:32 PM
Subject: Struts doesn't execute my ActionForm.


> Hi!
>
> I have a small HTML-Form with 3 textfields. I've implemented the
validation
> rules in the validate() method of the ActionForm belonging to the html
form.
> Unfortunately Struts isn't using the ActionForm. Why?
>
> Here my struts-config.xml
>
> <?xml version="1.0" encoding="ISO-8859-1"?>
> <!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts
> Configuration 1.1//EN"
>
> "http://jakarta.apache.org/struts/dtds/struts-config_1_1.dtd">
>
> <struts-config>
>    <form-beans>
>      <form-bean name="postTestForm"
>                 type="com.mycompany.PostTestForm"/>
>    </form-beans>
>
>    <global-forwards type="org.apache.struts.action.ActionForward">
>       <forward name="system.error" path="/WEB-INF/jsp/systemError.jsp"/>
>       <forward name="default.action" path="/execute/homePageSetuo"/>
>    </global-forwards>
>
>    <action-mappings>
>
>       <action path="/homePageSetup"
>               type="com.mycompany.HomePageSetupAction"
>               unknown="true">
>               <forward name="homepage.success"
> path="/WEB-INF/jsp/homePage.jsp"/>
>       </action>
>
>       <action path="/postTestSetup"
>              type="com.mycompany.PostTestSetupAction"
>              name="postTestForm"
>              scope="request"
>              validate="false">
>              <forward name="posttest.success"
> path="/WEB-INF/jsp/postTest.jsp" />
>
>       </action>
>
>       <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>
>
>    </action-mappings>
> </struts-config>
>
> The validation checks, if the fields are not empty. Even through the
fields
> are
> being empty, when I press the Submit button the applications presents me
> the entryform of the whole application. Also the URL looks pretty strange
> http://localhost/myapp/execute/postTest%20name=
> What doesn the %20name= mean? I think this is part of the problem.
> Can someone please tell me what am I doing wrong here?
>
> Regards
> 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


Re: Validation Problem

Posted by Marco Tedone <mt...@jemos.org>.
Why don't you use <html:text>?

Marco
----- Original Message ----- 
From: "Thomas Miskiewicz" <th...@web.de>
To: "Struts Users Mailing List" <st...@jakarta.apache.org>
Sent: Sunday, June 08, 2003 9:47 PM
Subject: Validation Problem


> Hi!
>
> I now have a strange validation problem. I use this ActionForm class:
>
> 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(fieldName + value.trim().length());
>      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);
>      System.out.println(maxLength);
>      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);
>
>     checkForLength("field1", "error.field1.length", getField1(), 5,
errors);
>     checkForLength("field2", "error.field2.length", getField2(), 5,
errors);
>     checkForLength("field3", "error.field3.length", 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;
>    }
>
> }
>
> Everything works fine except the application always claims, that field1 is
> empty
> even if it's not. value.trim().length() always is = 0 with respect to the
> field1.
> The content of the HTML-Form looks like this:
>
> <%@ page language="java" %>
> <%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
> <%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
> <%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
> <%@ taglib uri="/WEB-INF/struts-template.tld" prefix="template" %>
> <html:form action="postTest">
> <table border="0" cellpadding="0" cellspacing="0"
> style="border-collapse:collapse" bgcolor="E7E7E7" width="100%"
> height="900px">
> <tr>
>   <td>
>     <html:errors/>
>   </td>
> </tr>
> <tr>
>   <td>
>     <input name="field1" type="text" size="17" maxlength="32">
>   </td>
> </tr>
> <tr>
>   <td>
>     <input name="field2" type="text" size="17" maxlength="32">
>   </td>
> </tr>
> <tr>
>   <td>
>     <input name="field3" type="text" size="17" maxlength="32">
>   </td>
> </tr>
> <tr>
>   <td>
>     <input name="submit" type="submit" value="Submit">
>   </td>
> </tr>
> </table>
> </html:form>
>
> What's wrong???
>
> Regards
> 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


Validation Problem

Posted by Thomas Miskiewicz <th...@web.de>.
Hi!

I now have a strange validation problem. I use this ActionForm class:

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(fieldName + value.trim().length());
     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);
     System.out.println(maxLength);
     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);

    checkForLength("field1", "error.field1.length", getField1(), 5, errors);
    checkForLength("field2", "error.field2.length", getField2(), 5, errors);
    checkForLength("field3", "error.field3.length", 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;
   }

}

Everything works fine except the application always claims, that field1 is
empty
even if it's not. value.trim().length() always is = 0 with respect to the
field1.
The content of the HTML-Form looks like this:

<%@ page language="java" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<%@ taglib uri="/WEB-INF/struts-template.tld" prefix="template" %>
<html:form action="postTest">
<table border="0" cellpadding="0" cellspacing="0"
style="border-collapse:collapse" bgcolor="E7E7E7" width="100%"
height="900px">
<tr>
  <td>
    <html:errors/>
  </td>
</tr>
<tr>
  <td>
    <input name="field1" type="text" size="17" maxlength="32">
  </td>
</tr>
<tr>
  <td>
    <input name="field2" type="text" size="17" maxlength="32">
  </td>
</tr>
<tr>
  <td>
    <input name="field3" type="text" size="17" maxlength="32">
  </td>
</tr>
<tr>
  <td>
    <input name="submit" type="submit" value="Submit">
  </td>
</tr>
</table>
</html:form>

What's wrong???

Regards
Tom


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


Re: Struts doesn't execute my ActionForm.

Posted by Thomas Miskiewicz <th...@web.de>.
Hello!

> public class PostTest extends Action
> {
>   public ActionForward perform(ActionMapping mapping,
>             ActionForm form,
>             HttpServletRequest request,
>             HttpServletResponse response)
>   {
>    return (mapping.findForward("posttest.success"));
>   }
> 
> }
> 
> What's wrong then? Especially where does the strange looking URL
> come from?

Something must have been wrong with the form definition in the JSP.
I've replaced it with <html:form action="postTest"> and now everything
is fine.

Thanks
Tom



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


Re: Struts doesn't execute my ActionForm.

Posted by Thomas Miskiewicz <th...@web.de>.
> >    <global-forwards type="org.apache.struts.action.ActionForward">
>
> <global-forwards> <!-- instead -->

Why? What's wrong with the type?

> >             name="postTestForm"
> >             scope="request"
> >             validate="true"
> >             type="com.mycompany.PostTestForm">

> You've definately gone wrong with the type here, the
> type="..." should specify an Action not a Form.
> Perhaps type="com.mycompany.PostTestAction" ?

I've changed that. Now I have:
<action path="/postTest"
       input="/WEB-INF/jsp/postTest.jsp"
       type="com.mycompany.PostTest"
       name="postTestForm"
       scope="request"
       validate="true">
       <forward name="posttest.success" path="/execute/homePageSetup"/>
</action>

However when I press the submit button I see no difference. In the url I see
the strange http://localhost/myapp/execute/postTest%20name= and the
application didn't even go into the PostTestForm. I also hasn't been send to
 input="/WEB-INF/jsp/postTest.jsp" as I should be...

Here how the PostTest.java look 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 javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import java.lang.String;

public class PostTest extends Action
{
  public ActionForward perform(ActionMapping mapping,
            ActionForm form,
            HttpServletRequest request,
            HttpServletResponse response)
  {
   return (mapping.findForward("posttest.success"));
  }

}

What's wrong then? Especially where does the strange looking URL
come from?

Regards
Tom


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


Re: Struts doesn't execute my ActionForm.

Posted by Rob <bs...@insightoutsight.com.au>.
Thomas Miskiewicz wrote:
> Hi!
> 
> I have a small HTML-Form with 3 textfields. I've implemented the validation
> rules in the validate() method of the ActionForm belonging to the html form.
> Unfortunately Struts isn't using the ActionForm. Why?
> 
> Here my struts-config.xml
> 
> <?xml version="1.0" encoding="ISO-8859-1"?>
> <!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts
> Configuration 1.1//EN"
> 
> "http://jakarta.apache.org/struts/dtds/struts-config_1_1.dtd">
> 
> <struts-config>
>    <form-beans>
>      <form-bean name="postTestForm"
>                 type="com.mycompany.PostTestForm"/>
>    </form-beans>

This looks ok.

> 
>    <global-forwards type="org.apache.struts.action.ActionForward">

<global-forwards> <!-- instead -->

>       <forward name="system.error" path="/WEB-INF/jsp/systemError.jsp"/>
>       <forward name="default.action" path="/execute/homePageSetuo"/>
>    </global-forwards>
> 
>    <action-mappings>
> 
>       <action path="/homePageSetup"
>               type="com.mycompany.HomePageSetupAction"
>               unknown="true">
>               <forward name="homepage.success"
> path="/WEB-INF/jsp/homePage.jsp"/>
>       </action>
> 
>       <action path="/postTestSetup"
>              type="com.mycompany.PostTestSetupAction"
>              name="postTestForm"
>              scope="request"
>              validate="false">
>              <forward name="posttest.success"
> path="/WEB-INF/jsp/postTest.jsp" />
> 
>       </action>
> 
>       <action path="/postTest"
>              input="/WEB-INF/jsp/postTest.jsp"

It _is_ ok to have input="/WEB-INF/..."

>             name="postTestForm"
>             scope="request"
>             validate="true"
>             type="com.mycompany.PostTestForm">

You've definately gone wrong with the type here, the
type="..." should specify an Action not a Form.
Perhaps type="com.mycompany.PostTestAction" ?

>             <forward name="posttest.success" path="/execute/homePageSetup"/>
>       </action>
> 
>    </action-mappings>
> </struts-config>
> 
> The validation checks, if the fields are not empty. Even through the fields
> are
> being empty, when I press the Submit button the applications presents me
> the entryform of the whole application. Also the URL looks pretty strange
> http://localhost/myapp/execute/postTest%20name=
> What doesn the %20name= mean? I think this is part of the problem.
> Can someone please tell me what am I doing wrong here?
> 
> Regards
> 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