Once again I'm stuck using the jqGrid
in Struts2
with struts2-jquery plugin
. This time I wanted to put a <select/>
field in the search dialog for a column, as done in this tutorial here.
I built and tested the action supposed to return JSP with the select and all populated values inside of it and it works fine, I think the issue relates fully to jqGrid
. Maybe I'm overlooking something here.
When I open the search popup and select the column I want to search for (the one with the select
set), it triggers the action which retrieves the data and then a select
input appears but with no data inside it, it appears to be null, so I have an empty select
.
Below I'm posting some of my code:
jqGrid global config:
<sjg:grid
id="resGrid"
altRows="false"
caption="%{getText('reservationTable.title')}"
dataType="json"
href="%{remoteurl}"
editurl="%{deleteUrl}"
pager="true"
gridModel="gridModel"
rowList="10,15,30"
rowNum="15"
navigator="true"
navigatorSearch="true"
autowidth="true"
navigatorAdd="false"
onDblClickRowTopics="rowSelect"
navigatorEdit="false"
navigatorDelete="false"
navigatorSearchOptions="{
multipleSearch: true,
closeAfterSearch: true,
afterRedraw: afterRedraw
}"
navigatorExtraButtons="{
photos : {
title : '%{getText('reservationTable.icon.photo')}',
icon: 'ui-icon-image',
onclick: showPhotos,
position: 'first'
}
}"
>
jqGrid column config:
<sjg:gridColumn name="execution"
index="execution"
title="%{getText('execution')}"
formatter="execution"
search="true"
searchtype="select"
searchoptions="{ sopt:['eq'],
dataUrl:'%{selecturl}',
value: ':All;'}"/>
Result from retrieving the data (copied from the tutorial I linked above, this works fine):
<%@ taglib prefix="s" uri="/struts-tags"%>
<%@ page contentType="text/html; charset=UTF-8" %>
<s:select list="executionStrValues" theme="simple" emptyOption="true"/>
I've been stuck with this for a couple of days and I made some research, I found that this script could be useful as in this link HERE this issue with jqGrid is discussed on Github. I used it like this:
<script type="text/javascript">
(function() {
$.jgrid = {
defaults : {
ajaxSelectOptions: 'GET',
async: false
}
}
})();
</script>
This other open issue relates to this topic aswell: LINK
I also saw some people suggest using the formatter="select"
for the row, but if I understood correctly I don't need it because I'm not inline editing this column as written in the documentation.
UPDATE: ACTION CONFIGURATION
Below my <s:url>
which triggers the action returning values and the action's configuration:
<s:url var="selecturl" action="getExecutionStatus" />
getExecutionStatus.action where ExecutionStatus
is an enum:
@ResultPath(value = "/")
public class UtilsAction extends ActionSupport {
private static final long serialVersionUID = 3672057774005126256L;
private List<String> executionStrValues;
@Action(value="getExecutionStatus", results={
@Result(name="success",location="jsp/selectExecution.jsp"),
@Result(name="input", location="jsp/error.jsp"),
@Result(name="login", location="index.jsp")
})
public String getExecutionValues(){
List<ExecutionStatus> executionValues = Arrays.asList(ExecutionStatus.values());
executionStrValues = new ArrayList<String>();
for(ExecutionStatus ex: executionValues)
executionStrValues.add(getText("executionStatus."+ex.toString()));
return SUCCESS;
}//getExecutionValues
public List<String> getExecutionStrValues() {
return executionStrValues;
}
public void setExecutionStrValues(List<String> executionStrValues) {
this.executionStrValues = executionStrValues;
}
public static long getSerialversionuid() {
return serialVersionUID;
}
}