Struts 2 includeProperties does not work, but root does for json result type
I am posting this because I have found by googling another person who had the same problem but no resolution was mentioned. It is on another help site, so i don't know what the policy is about posting such links is, but I have it available if need be.
So my problem is like this:
<action name="CountQuery" class="info.pureshasta.action.QueryAction" method="countQuery">
<result name="success" type="json">
<param name="root">
countResults
</param>
</result>
<result name="input">SetupQuery</result>
</开发者_开发技巧action>
does exactly what I want it to. Namely, it returns a JSON object containing ONLY the countResults
(which happens to be an Integer) attribute. Reading the plugin documentation I would think that includeProperties would be what i want, especially if I end up wanting two attributes instead of one attribute in my JSON object. My attempt at this is like so:
<action name="CountQuery" class="info.pureshasta.action.QueryAction" method="countQuery">
<result name="success" type="json">
<param name="includeProperties">
countResults
</param>
</result>
<result name="input">SetupQuery</result>
</action>
Anyone know of any circumstances where this would be the case? Am I missing a prefix for countResults
in the latter case? What happens when I run my app with the latter case is I get all the attributes which are associated with my Action instead of just the one I want.
So I turn on my computer this morning, restore root to includeProperties, and the darn thing works don't you know. My output in javascript land is
{"countResults", 10078467}
and I have double checked and triple checked and my struts.xml snippet above is exactly the same.
Just for any future readers, when I use root instead of includeProperties I get
10078467
and I guess that is the expected behavior in each case. Until I need more attributes, root actually works better for me because I can use the value directly instead of having to look it up in the json object (save 1 step, how lazy!)
So I guess it turns out to be a caching issue? I have noticed that the web app is sluggish to show the changes when I have been working with the jquery / struts2/ json combination over the past day.
精彩评论