Reputation: 1091
I have a jsp that contains a struts2-jquery-plugin select tag that loads its data dynamically by sending an ajax request as follows:
<s:url var="remoteurl" action="providerList"/>
<sj:select href="%{remoteurl}" id="provider" name="language"
list="pList"
listKey="myKey"
listValue="myValue"
emptyOption="true"
headerKey="-1"
headerValue="Select" label="Provider"/>
Now when ajax request is made, control goes to action codes as follows:
ArrayList<String> pList=new ArrayList<String>();
public ArrayList<String> getpList() {
return pList;
}
public void setpList(ArrayList<String> pList) {
this.pList = pList;
}
public String providerList() {
pList.add("ASC");
pList.add("asas");
pList.add("asasasas");
return "returnedList";
}
In my struts.xml, correponding to actiion providerList, if i specify the result type as dispatcher then it takes the control to a jsp. What i wish is to just make the list pList reach the dropdown list of select tag.
Now the problem is that i want my select tag to be populated with this pList values. How should i configure this providerList action in struts.xml file. or i do i also need to make any changes in my action method ,in return type or anything. As far as i know i can use return type as json . Is there any other solution except json.
Upvotes: 0
Views: 2265
Reputation: 13714
First, there is no other solution than JSON, if you're relying on that tag.
In order for the sj:select
tag to work, you have to remove the below from the sj:select
listKey="myKey"
listValue="myValue"
Since, what you're sending from action is a list of string, but in the JSP it's expecting a map or a bean because of the above two properties.
In struts.xml, you have to configure the result type to be json and in order to do that we have to include struts2-json-plugin in the project.
Upvotes: 1