2

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>

动作类:

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();

我对该操作进行了 AJAX 调用,当我在 Firebug 中检查 JSON 响应时,它是:{}. 但是,如果我这样做<param name="root">tspNameIdMap</param>,它会起作用,但不会includeProperties

早些时候它正在工作,但我做了一些代码更改(与上述代码部分无关)并且它停止工作。代码更改包括实现ModelDrivenPOJO。

为什么不工作?有什么帮助吗?

4

2 回答 2

3

解决了:

struts.xml:

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

我添加<param name="root">action</param>到我的代码中,它解决了这个问题。

请参阅我解决的链接:http: //blog.mattsch.com/2011/04/14/things-discovered-in-struts-2/

从 Struts 2.2.3 开始,如果动作是模型驱动的,根对象总是被认为是模型。这意味着在创建 JSON 请求时,只有模型会被序列化。在>某些情况下,可能会使用模型驱动来接收请求并在>响应中发送其他内容。然后必须更改根对象。这可以通过设置根>参数来完成,如上所示。

于 2014-01-04T09:41:36.437 回答
0

利用

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

不需要以下参数,我发现有和没有这个的结果相同

<param name="root">action</param>   
于 2015-09-19T18:46:19.753 回答