This looks wrong to me:

    > errors.add("invoerGetal1",new ActionError("inleg moet tussen de 0 en
1.000.000 zijn !"));

You shouldn't pass an error message in the constructor of ActionError, it
should be the key to a message in a resources file.

You obviously have a resources file because the following lines are what are
set up as default for the <form:errors/>
    > Validation Error
    > You must correct the following error(s) before proceeding:

The resources is specified in the Web.xml file under the "application" key.

  <!-- Action Servlet Configuration -->
  <servlet>
    <servlet-name>action</servlet-name>
    <servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
    <init-param>
      <param-name>application</param-name>

<param-value>org.apache.struts.example.ApplicationResources</param-value>
    </init-param>
    <init-param>
      <param-name>config</param-name>
      <param-value>/WEB-INF/struts-config.xml</param-value>
    </init-param>
    <load-on-startup>2</load-on-startup>
  </servlet>

So in the example it is: org.apache.struts.example.ApplicationResources

In your checkForm() method you should code something like this:

    errors.add("invoerGetal1",new ActionError("error.big.problem"));

Then in the resources file (in WEB-INF/classes/org.apache.struts.example):

error.big.problem=<li>inleg moet tussen de 0 en 1.000.000 zijn !</li>


Note you need the <li>...</li> round the message because the header/footer
entries in the example are set up with <ul>...</ul> tags. So if you don't
put the <li>...</li> round your message they don't appear.

Niall


> -----Original Message-----
> From: Eelco van Kuik [mailto:[EMAIL PROTECTED]]
> Sent: 15 May 2001 09:54
> To: Struts-User (E-mail)
> Subject: newbie: Problem with ActionErrors
>
>
> Dear colleague developers,
>
> We are struggling with a problem to get the struts-forms working. It might
> be a newbie problem, but it is still difficult to find out which newbie
> problem we made. ;-) I included the most important struts problems at the
> bottom.
> No FAQ/examples/etc. could solve our problem, so I think that it
> might have
> something to do with a more complicated issue.
>
> We want:
> Serverside form validation:
> 1. When an error is added to the ActionErrors we want to display it at the
> top (iterate over the list)
> 2. Show the same form again, and
> 3. WITH the input (even though it might not be right) shown in the input
> fields.
>
> We have:
> 1. Whenever we raise an error we get the message at the top of the page:
> Validation Error
> You must correct the following error(s) before proceeding:
>
> And no list of the errors.......
>
> 2. We get the same form allright, but with NO VALUES whatsoever.
>
>
> Guys, WE ARE STUCK.

> So any help would be greatly apreciated.
>
> Regards,
>
> Eelco & Angela
>
> ******************************************************************
> **********
> ***********************************************************
>
> here the (stripped) jsp code:
> <form:errors/>
> <form:form name="sparenform"
> type="nl.rabobank.www.rekenmodellen.sparen.SparenActionForm"
> action="/rekenmodellen/sparenresult" focus="invoerGetal1">
> <form:text property="invoerGetal1" size="10" maxlength="10"/>
>  </form:form>
>
> here the (stripped) actionclass code:
> ActionErrors errorsHTML = new ActionErrors();
> errorsHTML = sparenActionForm.checkForm();
>
> if (!errorsHTML.empty())
> {
>       cat.debug("!errorsHTML.empty()");
>       saveErrors(request, errorsHTML);        //request.setAttribute
> ("sparen.error", errorsHTML);
>       // return to the original form
>       return (new ActionForward(mapping.getInput()));
> }
>       else
> {
>       ..no errors
> }
>
> here the form validator function(in the ActionForm):
> public ActionErrors checkForm()
> {
>       ActionErrors errors = new ActionErrors();
>
> /**
> * error inleg: getal heeft verkeerde waarde
> */
>       if (!berekeningtype.equalsIgnoreCase("i") && (inleg <= 0 || inleg >=
> 1000000))
>       {
>               cat.debug("fout gemaakt in inleg");
>               errors.add("invoerGetal1",new ActionError("inleg moet tussen
> de 0 en 1.000.000 zijn !"));
>       }
>
>

Reply via email to