In the current project, a developer defines a property of a string array type in action that needs to be returned to the page in JSON format ( regardless of whether the design is optimal ).
The result is that it is not always possible to get this property in the Ajax success method when doing page debugging. background action debugging found that the array has been correctly assigned, get
method is not a problem, the action-related code is as follows:
Private string[] tracelist;private String unitname; .... Public String Querytrace () { unitname = "testname"; tracelist=tranmanager.gettracelist (Traceno); return "Querytrace";} ... Public String Getunitname () { return unitname;} Public string[] Gettracelist () { return tracelist;}
The corresponding action configuration in the struts configuration file adds the following configuration:
<result name= "Querytrace" type= "JSON" > <param name= "includeproperties" >tracelist,unitname</param ></result>
The successful callback method in Ajax gets to the Tracelist object is always an empty array, viewing the STRUTS2 manual finds that
The includeproperties that is declared in the result of the Struts JSON plugin, for a string array or an array of primitive types, should be as follows:
<result name= "Querytrace" type= "JSON" > <param name= "includeproperties" >^tracelist\[\d+\],unitname</ Param></result>
It is also important to note that if excludeproperties and includeproperties are used at the same time, the precedence of the former is higher than the latter if there is a conflict.
Give us a link to the official struts file.
Record struts2 JSON plugin handling of string array types