开发者

Referencing actionerror from httpheader result in struts.xml

In my TestClass action I am setting an action error using addA开发者_如何学GoctionError 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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜