如何从 JSON 响应填充 struts2 中的下拉列表(<s:select)



我无法在我的JSP页面中填充我的struts2选择下拉。注意:我的JSP页面通过JSON响应加载。我在表格中有一个选择框。但是我不知道当我的JSP页面加载时如何填充它。

在同一页面中,我的Struts2 jQuery Grid中有一个精选的下拉列表,我可以填充它,但我不知道如何填充网格侧面的表格。p>请帮助我解决这个问题。

我的JSP页面

       <s:url id="selecturl" action="selectaction"/>  

   <s:url id="bookediturl" action="bookeditt"/>
   <s:url  id="bookremoteurl" action="booksetups"/>      
        <sjg:grid
        id="bookgrid"
        formIds="form2"
        reloadTopics="reloadMyGrid"
        caption="List of Cover Details"
        dataType="json"
        href="%{bookremoteurl}"
        pager="true"
        gridModel="gridModel"
        rowList="50,100,5000"
        rowNum="20"
        filter="true"
        filterOptions="{stringResult :false,searchOnEnter : false,enableClear : true,gridModel : true}"   
        rownumbers="true"
        editurl="%{bookediturl}"
        navigator="true" 
        editinline="true" 
        navigatorSearch="false"
        autowidth="false"   
        width= "1550" 
        viewrecords="true"  
        navigatorRefresh="true"
        navigatorDelete="true">

             <sjg:gridColumn name="id" index="locationId" title="ID" formatter="integer" sortable="false" key="true" 
                       search="false"  editable="true"  hidden="true"   /> 
              <sjg:gridColumn name="authLastname" index="authLastname" title="AuthorLastname" sortable="true" search="true" editrules="{required: true}"
                        editable="true" edittype="text" />  
        <sjg:gridColumn name="subjectId" title="Subject Name" editable="true" sortable="false" align="center" search="false" searchtype="select" 
        searchoptions="{dataUrl:'%{selecturl}'}"  edittype="select"     editoptions="{dataUrl:'%{selecturl}'}"  />   
        </sjg:grid>
<div id="myDivBox" style="display:none; width :300px;position: relative;top: -30px;left: 299px;button:0px;">
    <s:form action="searchkeywordss" id="form2"  theme="simple" cssClass="yform">
             <sj:textfield  placeholder="Enter keyword to search" cssClass="txtbox" size="42" maxLength="255" name="keywordsearch"/> 
             <sj:select    href="%{selecturl}"   name="countryselect" list="%{lstsub}"  listKey="id" listValue="subjectName"  theme="jquery" cssStyle="margin-top:4px;"/>
             <sj:a button="true" id="btnid"  cssStyle="position: relative;top: 0px;left: 09px;" onClickTopics="reloadMyGrid">Find</sj:a> 
      </s:form> 
</div> 

struts.xml

 <action name="booksetups" class="v.esoft.actions.bookdetails.BookdetailsAction" >
      <result name="success" type="json"/>
      <result name="login" type="redirect"> /index.jsp </result>
 </action>   
     <action name="selectaction" class="v.esoft.actions.bookdetails.SelectAction">
     <result name="success">/select.jsp</result>
 </action>

您应该只使用sj:select如下

<sj:select    href="%{selecturl}"   name="countryselect" list="subjectList"  listKey="id" listValue="subjectName"  theme="jquery" cssStyle="margin-top:4px;"/>

其中 selecturl返回 json响应, subjectListjson lepons中列表的名称,其中包含选项

您的selectaction应该具有json响应,但是您现在拥有的是返回JSP的操作,以使其无法正常工作。如果您不能更改它,则应创建另一个返回json的操作。

最新更新