hi wolfgang,

you do not have to go this way.

1. in the struts-config.xml add in your appropriate <action> the attribute 
validate="true".
2. in your actionformbean there is (has to be ) a method called validate().
        inside this method you only add your ActionsErrors object.

        If there is not error you have to return null
        else you have to return your ActionErrors object.

i work this way and it works on my system.


 public ActionErrors validate(ActionMapping mapping,
                               HttpServletRequest request) {

      ActionErrors errors = new ActionErrors();
      if ((username == null) || (username.length() < 1))
          errors.add("username", new ActionError("login.error.username.required"));
      if ((password == null) || (password.length() < 1))
          errors.add("password", new ActionError("login.error.password.required"));
      if ((organization == null) || (organization.length() < 1))
          errors.add("organization", new 
ActionError("login.error.organization.required"));
      if ((language == null) || (language.length() < 1))
          errors.add("language", new ActionError("login.error.language.required"));

      return errors;

  }

hopefully i could help you

-----Original Message-----
From: wolfgang [mailto:wolfgang127jp@;ybb.ne.jp]
Sent: Dienstag, 12. November 2002 16:33
To: Struts Users Mailing List
Subject: about html:error ( error handling )


Hi there,

I'm trying to make an error handling in my web application with 
<logic:present> and <html:errors>.
but I'm stuck.

what I wanna do is that 
when struts catch the error (user didn't fill in the required textarea) ,
struts say there's an error.
And
even though there were no errors, strust says there was No error.

now I can do only former one with the code below...

In ApplicationResource.properties file ------
username.required=FF0000   (<-- red color in html)
---------------------------------------------

In ActionForm bean --------------------------
ActionErrors errors = new ActionErrors();
if(.....){
   errors.add("username", new ActionError("username.required"));
}
....
---------------------------------------------

In jsp --------------------------------------
<logic:present name="<%=Action.ERROR_KEY%>">
   <html:errors property="username">
</logic:present>
---------------------------------------------

when struts catches the error, the HTML( transformed from jsp ) write
out FF0000.

I want struts write a word I specified even though There's NO error.
Is it impossible ???

why I wanna do this is that I wanna change the font's color depending on
either error or not.

If there's error <font color="ff0000">foobar</font>
If there's NO error <font color="ffffff">foobar</font>

I tried coding in jsp.

<font color="
<logic:present name="<%=Action.ERROR_KEY%>">
   <html:errors property="username">
</logic:present>
<logic:notPresent name="<%=Action.ERROR_KEY%>">
   FFFFF
</logic:notPresent>
">foobar</font>

This does NOT work because if username property is okay , but other
properties got errors, <html:errors property="username"> will be
processed...

so I gotta do like below...(since I don't know how to code, I just write
words)

<font color="
<logic:present name="<%=Action.ERROR_KEY%>">
   if(this error is username property's one){
      <html:errors property="username">
   }else{
      write FFFFF
   }
</logic:present>
<logic:notPresent name="<%=Action.ERROR_KEY%>">
   FFFFF
</logic:notPresent>
">foobar</font>


I don't know how to code....

Please Please anyone helps me out...

Thanks in advance.
wolfgang



-- 
wolfgang <[EMAIL PROTECTED]>


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


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

Reply via email to