0

It seems that in order to define a json result for a struts 2 action, you have to define it seperately for each action, in the following way:

<action name="someJsonAction" class="com.something.Struts2Action">
    <result type="json">
        <param name="noCache">true</param>
        <param name="excludeNullProperties">true</param>
        <param name="root">jsonString</param>
    </result>
</action>

Is it possible to add this as a global result to a package, so that I won't have to include the 3 parameters (noCache, excludeNullProperties, and root) with each action, and instead I can just define a result named 'json' and it would know to inherit those 3 parameters which I described?

Thanks.

Ali
  • 261,656
  • 265
  • 575
  • 769
  • You should check the package if it supports a global result. –  Nov 03 '13 at 11:33
  • @nikpon Which package? – Ali Nov 03 '13 at 11:49
  • Any package, but it should be outpost to the default package. –  Nov 03 '13 at 12:17
  • @nikpon Well, in my package, I'm able to define global results, however they only seem to work if I don't add a `result type`, e.g `/foo.jsp` works, but ` – Ali Nov 03 '13 at 14:37
  • Sometimes it works, sometimes is not working, are you sure it works if you place it to the action? –  Nov 03 '13 at 18:15
  • @nikpon Are you able to help with this question? http://stackoverflow.com/questions/19755939/struts-2-resetting-action-instance-while-its-still-in-interceptor It might be why it sometimes works and other times, doesn't – Ali Nov 03 '13 at 18:16
  • You didn't answer my question. That link is a different question. Both answers are correct. What kind of help do you need? –  Nov 04 '13 at 08:45
  • See this question: http://stackoverflow.com/q/15521241/1700321. – Aleksandr M Nov 06 '13 at 08:26

1 Answers1

0

Yes of course, there's a way :

See the global results section in the Documentation

<global-results>
    <result name="success" type="json">
       <param name="noCache">true</param>
        <param name="excludeNullProperties">true</param>
        <param name="root">jsonString</param>
    </result>
</global-results>
coding_idiot
  • 13,526
  • 10
  • 65
  • 116