Pages Navigation Menu

Coding is much easier than you think

Changing default style of s:actionerror / s:actionmessage tag

 
default style
 
In struts 2 when you use <s:actionerror /> tag, it displays the errors with bullets, On viewing the page source of the jsp page, we can see that error message is displayed using
 

<ul>
<li>error 1</li>
<li>error 2</li>
</ul>

 
But suppose if our requirement is to display the error message without bullet in the action errors or action messages
 
** UPDATE: Struts 2 Complete tutorial now available here.
 
There are 2 ways to solve this problem
 
1. Customized the code in jsp, such that you can specify your own css for displaying the message
 

<s:if test="hasActionErrors()">
<s:iterator value="actionErrors">
<span class="msg"><s:property escape="false" />
</span>
</s:iterator>
</s:if>

 
2. Change the file in the “/template/simple/actionerror.ftl” and put it in the /web-directory/struts/simple if you are using simple theme
 

Recommended reading

 
Similar kind of approach is followed for <s:actionmessage /> tag.
 

About Mohaideen Jamil