【问题标题】:jqGrid select not populated with data from Struts2jqGrid 选择未填充来自 Struts2 的数据
【发布时间】:2014-12-11 11:05:24
【问题描述】:

我又一次被困在使用jqGridin Struts2struts2-jquery plugin。这次我想在列的搜索对话框中放置一个<select/>field,就像本教程中所做的那样here.

我构建并测试了应该返回 JSP 的操作,其中包含选择和所有填充的值,它工作正常,我认为这个问题与 jqGrid 完全相关。也许我在这里忽略了一些东西。

当我打开搜索弹出窗口并选择我要搜索的列(设置了select 的列)时,它会触发检索数据的操作,然后出现select 输入但里面没有数据它,它似乎是空的,所以我有一个空的select

下面我发布我的一些代码:

jqGrid 全局配置:

 <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 列配置:

<sjg:gridColumn name="execution" 
index="execution" 
title="%{getText('execution')}" 
formatter="execution" 
search="true" 
searchtype="select" 
searchoptions="{ sopt:['eq'], 
                 dataUrl:'%{selecturl}', 
                 value: ':All;'}"/>

检索数据的结果(复制自我上面链接的教程,效果很好):

<%@ taglib prefix="s" uri="/struts-tags"%>
<%@ page contentType="text/html; charset=UTF-8" %>
<s:select list="executionStrValues" theme="simple" emptyOption="true"/>

我已经被这个问题困扰了几天,我进行了一些研究,我发现这个脚本可能很有用,因为在这个链接HERE 这个关于 jqGrid 的问题在 Github 上进行了讨论。我是这样使用的:

 <script type="text/javascript">
(function() {
    $.jgrid = {
            defaults : {
                ajaxSelectOptions: 'GET',
                async: false
            }
        }
})();
</script> 

另一个未解决的问题也与此主题有关:LINK
我还看到有些人建议使用formatter="select"作为行,但如果我理解正确我不需要它,因为我没有将此列内联编辑为written in the documentation.


更新:操作配置 在我的&lt;s:url&gt; 下方触发动作返回值和动作的配置:

&lt;s:url var="selecturl" action="getExecutionStatus" /&gt;

getExecutionStatus.action 其中ExecutionStatus 是一个枚举:

@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;
    }
}

【问题讨论】:

  • 显示您的 selecturl 操作类和配置。
  • @AleksandrM 请查看更新后的问题。
  • @AleksandrM 有什么新想法吗?我仍然坚持这一点,不知道出了什么问题..
  • 如果你的ExecutionStatus 是一个枚举,为什么你需要一个动作来获取它?您可以在选择标签中使用它 - stackoverflow.com/q/16063819/1700321.
  • @AleksandrM 因为它是 jqgrid 插件在搜索字段中使用该枚举值填充选择的方式。我真的不知道另一种解决方法

标签: jquery struts2 jqgrid struts2-jquery


【解决方案1】:

把它放在你的jsp页面上。我认为它有效。 <%@taglib prefix="s" uri="/struts-tags"%> <%@taglib prefix="sj" uri="/struts-jquery-tags"%> <%@taglib prefix="sjg" uri="/struts-jquery-grid-tags" %>

【讨论】:

  • 您好,感谢您的回答,但它不起作用:(
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-12-14
  • 1970-01-01
  • 2014-11-18
相关资源
最近更新 更多