includeProperties not working?

1.9k views Asked by At

struts.xml:

<action name="findTspNameIdMap"
            class="cdot.oss.cmsat.gma.struts.ConfigureTspThresholdAction" method="findTspNameIdMap">

            <result name="success" type="json">
                <param name="includeProperties">result,tspNameIdMap.*</param>   
            </result> 

            <result name="error">pages/Error.jsp</result>

        </action>

Action class:

public class ConfigureTspThresholdAction extends ActionSupport implements SessionAware, ModelDriven<GmaThresholdParameter>{


    private Map<String,Object> session;
    private String operatorId;

    private Map<String,String> tspNameIdMap;
    private String result = "success";

    //private List<String> thresholdParameters;
    GmaThresholdParameter gmaThresholdParameters = new GmaThresholdParameter();

I do an AJAX call to the action, when I check in Firebug the JSON response it is: {} . However if I do <param name="root">tspNameIdMap</param> it works but not includeProperties.

Earlier it was working but I made some code changes(not related to this above part of the code) and it stopped working. Code changes included implementing ModelDriven for a POJO.

Why is not working? Any help?

2

There are 2 answers

5
Siddharth Trikha On BEST ANSWER

SOLVED:

struts.xml:

   <result name="success" type="json">
        <param name="root">action</param>         
        <param name="includeProperties">result,tspNameIdMap.*</param>   
    </result-type>

I added <param name="root">action</param> to my code and it solved the problem.

Refer to this link from where I solved: http://blog.mattsch.com/2011/04/14/things-discovered-in-struts-2/

Since Struts 2.2.3 the root object is always considered to be the model if the action is model >driven. This means that when creating the JSON request only the model will get serialized. In >some cases one might use model driven for receiving requests and send something else in the >response. Then the root object has to be changed. This can be done by setting the root >parameter as shown above.

0
Rajendra Thorat On

use

<result name="success" type="json">      
    <param name="includeProperties">result,tspNameIdMap*.*</param>   
</result-type> 

Following param is not required , I found same result with and without this

<param name="root">action</param>