struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Matthias Wessendorf" <maili...@matthias-wessendorf.de>
Subject RE: ActionForm.validate() Help
Date Wed, 01 Sep 2004 17:27:52 GMT
hi, I use this in ActionForms:

<snip>
public ActionErrors validate(ActionMapping mapping, 
                         HttpServletRequest request) { 
		ActionErrors errors = new ActionErrors(); 
          
		if( (this.nachname==null) || (this.nachname.length()<1)
) 
		 errors.add( "nachname", new
ActionMessage("nachname.fehler")); 
          
		if( (this.vorname==null) || (this.vorname.length()<1) ) 
		 errors.add("vorname", new
ActionMessage("vorname.fehler")); 
          
		return errors; 
	} 
</snip>

and this in JSPs:

<snip>:
<html:form action="/ausfuehren"> 

    Vorname <html:text property="vorname"/> 
            <html:messages id="error" property="vorname"> 
      <bean:write name="error"/> 
    </html:messages> <br/> 


     Nachname <html:text property="nachname"/> 
    <html:messages id="error" property="nachname"> 
      <bean:write name="error"/> 
    </html:messages><br/>  



    <html:submit/>  
</html:form> 

</snip>

Hope it helps you!
Regards,
Matthias


> -----Original Message-----
> From: Matthew J. Vincent [mailto:vincent@cs.usm.maine.edu] 
> Sent: Wednesday, September 01, 2004 6:36 PM
> To: Struts Users Mailing List
> Subject: ActionForm.validate() Help
> 
> 
> Hello all,
> 
> I just downloaded the latest stable build of Struts 1.2.  What is a 
> "best practice" approach of handling validation in the ActionForm's 
> validate method since ActionError was deprecated? 
> Also, how should one display the messages in the JSP?  
> Currently I use:
> 
> <logic:messagesPresent message="true">
>     <html:messages id="message" message="true">
>         ${message}<br>
>     </html:messages>
> </logic:messagesPresent>
> 
> Howver this does not display anything when I use the 
> following code in 
> my ActionForm because errors is obviously not populated with any data:
> 
>     public ActionErrors validate(ActionMapping mapping,
>                                  HttpServletRequest request) {
> 
>         ActionErrors errors = new ActionErrors();
>        
>         if (/*some error occurs*/){
>             ActionMessages messages = new ActionMessages();
>             ActionMessage message = new 
> ActionMessage("errors.valueRequired");
>             messages.add(ActionMessages.GLOBAL_MESSAGE, message);
>             request.setAttribute("warnings", messages);
>         }
>         return errors;
>     }
> 
> 
> However in an Action the following code will work correctly 
> and display 
> in the HTML rendered by the JSP code from above:
> 
>             ActionMessages messages = new ActionMessages();
>             ActionMessage message = new 
> ActionMessage("errors.notfound");
>             messages.add(ActionMessages.GLOBAL_MESSAGE, message);
>             saveMessages(request, messages);
> 
> 
> Do I have to check for the existence of both messages and 
> errors in the JSP?
> 
> Thanks!
> 
> Matt
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
> 


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


Mime
View raw message