tags:

views:

179

answers:

1

In my TestClass action I am setting an action error using addActionError method. I have an action defined in the struts.xml as following

<action name="TestAction" class="TestClass">
    <result name="input">/jsp/test.jsp</result>
    <result name="error" type="httpheader">
       <param name="error">409</param>
       <param name="errorMessage">${SOME-EXPRESSION}</param>
    </result> 
</action>

The intent is to have the error message display whatever was added using addActionError. According to the org.apache.struts2.dispatcher.HttpHeaderResult documentation, I should be able to use Ognl expressions within errorMessage parameter.

So, is it possible to put something in place of ${SOME-EXPRESSION} that will reference actionerror in this scenario.(I tried ${actionerror} but it didn't work)

I know that I can have a workaround by declaring my own field (for example "errorText") in the action class and using that insteda of addActionError referencing it using ${errorText} inside the param tags. But before I go that route, want to make sure that's the only way.

A: 

Action errors are stored in a list, so you'll have to show something like ${actionErrors[0]}. But keep in mind this way it will only show your first added error, not all those you have included using addActionError.

pedromarce
Thanks! Exactly what I was looking for
IK