Jsp ActionErrors Struts

4.3k views Asked by At

Good Afternoon in my timezone.

I am finalizing a Java Web project to a company, and i need to write errors detected in the actionForm validation method. Inside the validate method i am adding errors that way (snippet of code):

ActionErrors ae = new ActionErrors();
ae.add("dummy",new ActionMessage("message"));
...java...code
 ae.add("dummy",new ActionMessage("message"));

In my jsp what i want to do is iterate over all the errors found it , and print them. i do not want to put all the errors by the following way :

<html:errors property="prop1"/>
<html...code/>
<html:errors property="prop2"/>

What i want to do is something like this (psedo-code):

if(there is errors)
   for(erros.hasNext)
      <td>errors.next()</td>

I can use normal scriplets if i have to. Can any body help me hear ?

Thanks in advance Best regards

2

There are 2 answers

3
JB Nizet On

Just use <html:errors/>. See http://struts.apache.org/1.2.x/userGuide/struts-html.html#errors for how the tag works:

property Name of the property for which error messages should be displayed. If not specified, all error messages (regardless of property) are displayed.

(emphasis mine)

0
Vadim Gulyakin On

I used following code to generate Javascript array of errors, your case should be very similar. Please note using html:messages instead of html:errors

<logic:messagesPresent>    
    ErrorMessages = new Array ();
     <html:messages id="message"> 
         ErrorMessages.push("<bean:write name='message' filter='false'/>");
    </html:messages>
</logic:messagesPresent>
<logic:messagesNotPresent>
//some logic here
</logic:messagesNotPresent>