Question

i am unable to populate my Struts2 select drop down in my jsp page. Note: My jsp page loads through json response. I have a select box inside a form. But i don't t know how to populate it when my jsp page loads.

And in the same page i have a select dropdown in my Struts2 jquery grid,which i am able to populage but i don't know how to populate a drop down for my form which are out side of the grid.

Please help me regarding this issue.

my jsp page

       <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>
Was it helpful?

Solution

You should only use the sj:select like below

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

where selecturl returns a json response, subjectList is name of list in the json reponse which contains the options

Your selectaction should have a json response, but what you have now is an action returning a jsp so it would not work. If you cannot change it, you should create another action which returns json.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top