【问题标题】:Reloading a struts jqGrid with a form submission使用表单提交重新加载 struts jqGrid
【发布时间】:2019-07-11 15:32:06
【问题描述】:

我有一个 struts2 jgrid,我希望能够使用表单提交按钮刷新信息。我一直在尝试关注这个(SO 帖子)[dynamic data reload to struts2 jquery grid on form submit],但我对为什么我的流程没有按预期工作有点困惑。动作 updateRPJson 返回 json 类型作为响应,并且 gridmodel 具有工作所需的所有 getter/setter 和属性。

在第一次加载包含此网格的网页时,将调用 action 方法并正确检索信息。我期待表单内部的“刷新”按钮将信息从表单发送到操作类,然后用它收到的响应重新填充网格。我认为刷新按钮会发布“reloadMyGrid”主题,然后强制网格重新加载,从而导致从网格的 href 调用操作。我添加了 console.log 语句来确定什么被调用,什么没有被调用,并在我的动作类中添加断点来查看它何时被调用。

我发现单击刷新按钮后,控制台会收到“Test2”,表明 reloadMyGrid 已“发布”(我认为这不是正确的术语),但是我的操作类从未被调用。控制台中缺少“测试”表明表单本身也没有被提交。

如果我将表单按钮改回<sj:submit/> 并将表单onSubmit 更改为action=updateRPJson,页面将正确的信息显示为纯json(而不是在网格内)。这使我相信,如果在单击按钮后调用操作,这将起作用,并且不是操作本身的问题。

我意识到这是一个冗长的具体案例问题,但任何关于如何使用表单提交按钮更新 struts jqgrid 的过程的见解将不胜感激,因为我不完全理解我上面链接的帖子我'米假设。

标签:

<%@ page contentType="text/html; charset=UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%@ taglib prefix="sj" uri="/struts-jquery-tags"%>
<%@ taglib prefix="sjg" uri="/struts-jquery-grid-tags" %>

表格:

<s:form id="getRPInstance" name="getRPInstance"  onSubmit="return reloadGrid();" >
    <div class="type-text" align="center" style="width:50%;text-align:right;float:left">
                <s:select
                   name="location"
                   id="location"
                   list="#{'unit':'Unit', 'acceptance':'Acceptance', 'integration':'Integration','production':'Production'}"
                   value="%{#session.location}"
                   required="true"/>
                <s:select
                    name="realm"
                    id="realm"
                    list="#{'int':'Internal', 'ext':'External', 'cld':'Cloud' }"
                    value = "%{#session.realm}"
                    required = "true"/>
                <div id="buttonDiv" class="type-button" align="center">
                    <sj:a button="true" onClickTopics="reloadMyGrid">Refresh</sj:a>
                </div>
    </div>
</s:form>

脚本:


    <script>

    $.subscribe('reloadMyGrid',function()
    {
        console.log("Test2");
        $( '#gridError' ).html( "" );
    });

    function reloadGrid() {
         console.log("Test");
         $('#gridtable').trigger('reloadMyGrid');
         return false;
     }
    </script>

网格:


    <s:url var="remoteurl" action="updateRPJson"/>
    <sjg:grid
        id="gridtable"
        caption="Reverse Proxy"
        dataType="json"
        href="%{remoteurl}"
        pager="true"
        gridModel="proxies"
        rowList="10,15,20,50"
        rowNum="20"
        rownumbers="true"
        reloadTopics="reloadMyGrid"
        formIds="getRPInstance"
        height="600"
        width="650"
        loadonce="true"
    >
        <sjg:gridColumn name="name" index="name" title="Name" key="true" hidden="true" sortable="false"/>
        <sjg:gridColumn name="label" index="label" title="Label" sortable="true"/>
    </sjg:grid>

【问题讨论】:

    标签: java jquery struts struts2-jquery


    【解决方案1】:

    我已经弄清楚了,问题出在 struts 网格本身。这已通过将 loadonce 设置为 false 来解决。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-08-11
      • 2013-11-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多