tags:

views:

2581

answers:

3

Hi, I am using struts2 in my application and trying to diplay error message using "s:actionerror/". It diaplays fine but a dot(.) also appears with the error message which looks ugly and is displayed like list.

Is there any way to cuatomize the error message in struts2.

Thanks in advance.

A: 

Hi I found the solution for getting rid of the dot.

<table align="center" width="70%" class="stats">
                        <tr>
                        <s:if test="hasActionErrors()">
                            <s:iterator value="actionErrors">
                                <tr>
                                    <td class="error">
                                        <img alt="error message" src="./images/cross.gif" width="10" height="10"/>&nbsp;<s:property escape="false" />
                                    </td>
                                </tr>
                            </s:iterator>
               </s:if>

Try this out.

Sai Prasad
A: 

Another solution is to override the template for the default actionError output.

You can find the default templates in the struts2 core jar. If you pull out template.simple/actionerror.ftl, you can customize that. You can either come up with your own template and reference it in the s:actionerror tag with the template attribute, or you can keep the same name and put it in /template/simple and it will be used as the default.

Most of the templates are in freemarker, although there are still some of them in velocity depending on your struts2 version. Both are pretty easy to work with templating engines.

Brian Yarger
+1  A: 

Brian Yarger's answer is the most complete solution. The easiest solution on the other hand is to just use CSS and modify the li element.

JSP:

<s:if test="hasActionErrors()">
   <div class="errors">
      <s:actionErrors/>
   </div>
</s:if>

CSS:

li .errors { list-style: none; }
kozmic