Populate dropdown list inside Dialog using Struts2

2019-02-19 20:25发布

问题:

I have a Dialog in which I have to populate a dropdown list from database.I am using struts2-juery-plugins to implement Dialog.This Dialog is open on some event. This is how I create Dialog .

<sj:dialog 
     id="mybuttondialog"
     href="%{fillUser}"
     buttons="{
            'Assign':function() { approoveButton(); },
            'Deny':function() { denyButton(); }
            }"
     autoOpen="false"
     modal="true"
     title="Assign-Task"
     closeTopics="closeThisDialog">
<label>User</label>
  <select id="userCombo" name="userCombo">
    <s:iterator value="userList">
      <option><s:property value="helper_name" /></option>
    </s:iterator>
  </select>    
</sj:dialog>

I am calling an action to fill dropdown list using

<s:url var="fillUser" action="getAllUsers" />

But list is not populating and Dialog got filled with jsonData as following

{"helpDeskUsers":"success","userList":
[{"departments":null,"helper_name":"arvin","helper_value":null,"user_level":null},
{"departments":null,"helper_name":"anand","helper_value":null,"user_level":null},
{"departments":null,"helper_name":"Nehal","helper_value":null,"user_level":null},

Why list is not populating instead whole Dailog is filled with above data. Any help would be great.

回答1:

The <select tag will not work with json list, you should use something like

<s:url var="fillUser" action="getAllUsers" />
<sj:select
  id="userjson"
  name="users"
  href="%{fillUser}"
  list="userList"
  listValue="helper_name"
  listKey="helper_name"