opensubscriber
   Find in this group all groups
 
Unknown more information…

d : dev@struts.apache.org 12 March 2009 • 1:50AM -0400

JSON plugin 0.33 and Struts 2.1.6 (integrated with Spring 2.5)
by Gregory Slonim

REPLY TO AUTHOR
 
REPLY TO GROUP




All,

I am having a problem returning collections (or arrays) from struts  
action as JSON. All collection-type data comes back empty (map, array,  
etc).

Setup:

struts.xml

<package name="json" extends="json-default">
<action name="getPayPlanGradesAjaxCall"
class="com.intellidyne.rms.action.accession.AccessionAction"
method="getPayPlanGradesAjaxCall">
<interceptor-ref name="json">
<param name="enableSMD">true</param>
</interceptor-ref>

<result type="json">
<param name="noCache">true</param>
<param name="includeProperties">
dutyHours,
payPlanTypes
</param>

</result>
</action>
</package

Action:

public class AccessionAction extends BaseAction implements  
ConversationScopeAware, ValidationAware
{
private static final long serialVersionUID = -1249579868850221888L;

private String dutyHours;
private List<String> payPlanTypes;

public String getDutyHours()
{
return dutyHours;
}

public void setDutyHours(String dutyHours)
{
this.dutyHours = dutyHours;
}

public final List<String> getPayPlanTypes()
{
return payPlanTypes;
}

public final void setPayPlanTypes(List<String> payPlanTypes)
{
this.payPlanTypes = payPlanTypes;
}

public String getPayPlanGradesAjaxCall()
{
dutyHours="12345";
payPlanTypes = new ArrayList<String>();
payPlanTypes.add("TEST1");
payPlanTypes.add("TEST2");
return SUCCESS;
}
}

JSP:

......

<button dojoType="dijit.form.Button"
label="TEST" value="Test">
<script type="dojo/method" event="onClick">
console.debug("Getting JSON DATA");
dojo.xhrGet ({
url: "getPayPlanGradesAjaxCall.html",
handleAs: "json",
load: function(response, ioArgs) {
console.debug("Returned from the call. Response is  
"+response.dutyHours);
console.debug("Returned content: "+response.payPlanTypes);
return response;
}
});
</script>
</button>

The button does not do anything besides making AJAX call. Here is the  
response in FF Fbug:

{"dutyHours":"12345","payPlanTypes":[]}

Even if I use various dojo methods (such as dojo.toJson, etc) on  
response object, the collection is still empty.
I used arrays, maps, whatever. It is still empty.

The main problem I am trying to solve is how to populate one select  
from something selected in another. (typical car makes/models scenario)

Please advise, your help is greatly appreciated.

Greg



Bookmark with:

Delicious   Digg   reddit   Facebook   StumbleUpon

Related Messages

opensubscriber is not affiliated with the authors of this message nor responsible for its content.