So I have trouble trying to use any of these two elements for different reasons. First I’ll describe what happens with the s:checkboxlist.
When the value on the sj:select changes I want to populate a list on my controller to use on my s:checkboxlist, do I have to use javascript? My initial guess was to call a javascript function on the sj:select onchange="" parameter, then on the javascript function refresh the s:checkboxlist so it populates using the new list.
For example if I have something like on my sj:select:
<s:url id="urlGetNewList"
action="mycontroller!getNewList" />
<sj:select href="%{urlGetNewList}" id="myselect"
onChangeTopics="reloadList"
onCompleteTopics="reloadList"
name="model.idType" list="types"
listKey="idType" listValue="nameType"
emptyOption="false" headerKey="-1"
headerValue="select a value"
formIds="frmMyForm" />
and on my s:checkboxlist I have :
<s:checkboxlist name="arrayOfIds" list="idsType"
listKey="id" listValue="name"
theme="vertical-checkbox" />
So my s:select gets populated from a list called types, when the value on the sj:select changes I call a function on my controller named getNewList, that will change the list that uses my checkboxlist, but how can refresh the checkboxlist.
You can notice I could solve this by using a sj:checkboxlist, I know it works, but if I do that then when I try to load the checkbox that are checked through the Integer array idsType, the checkboxes won’t get checked. For example if I have an Integer array like this:
idsType = { 2, 3 }
and I have a list arrayOfIds with 5 elements, then when I use the s:checkboxlist, 5 checkboxes will be shown and the second and third checkbox will be checked.
But if I do this using sj:checkboxlist, then only the first checkbox will be checked and also the checkboxes will change dinamically according to the sj:select value, which won’t happen when I use a s:checkboxlist.
I’m really lost as to how can I solve this issue, if anybody can help it will be very much appreciated.
To answer the first question, of course you’d need to use JavaScript to update the checkbox list–the standard
<s:checkboxlist>is completely unaware of Ajax. You would need to do it manually by binding to the topic published by thesj:select.The plugin wiki (assuming this is the plugin you’re using, there are actually a few) has a page discussing how to handle JSON results in a topic.
The
<sj:checkboxlist>can reload by listening to topics; there should be no issue handling multiple items in the list; you may need to provide additional details regarding what you tried, and what went wrong (if anything, for example, check the JavaScript console).