Search code examples
javajquerystrutsstruts2-jquery

Reloading a struts jqGrid with a form submission


I have a struts2 jgrid that I wish to be able to refresh the information using a form submission button. I have been trying to follow this (SO post) [dynamic data reload to struts2 jquery grid on form submit ] but am a bit confused with why my process is not working as expected. The action updateRPJson returns json type as a response, and the gridmodel has all of the getters/setters and attributes needed to work.

Upon first loading the web-page containing this grid, the action method is invoked and the information is correctly retrieved. I am expecting the "Refresh" button present inside of the form to send the information from the form to the action class, and then repopulate the grid with the response it receives. I thought the refresh button would publish the "reloadMyGrid" topic, which would then force the grid to reload causing the action to be invoked from the href of the grid. I added console.log statements to determine what was being called and what was not, as well as added breakpoints inside of my action class to see when it was being invoked.

I discovered that upon clicking the refresh button, the console recieves "Test2" indicating that reloadMyGrid is "published" (I don't think that is the right term), however my action class is never being called. The lack of "Test" in the console indicates that the form itself is also not being submitted.

If I were to change the form button back to an <sj:submit/> and change the forms onSubmit to action=updateRPJson, the page displays the correct information as pure json (and not inside of the grid). This leads me to believe that should the action be invoked after clicking the button, this would work, and is not an issue with the action itself.

I realize this is a long-winded somewhat specific case question, but any insight on how the process of updating a struts jqgrid with a form submission button would be appreciated, as I am not fully understanding the post I linked above I'm assuming.

Tags:

<%@ 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" %>

Form:

<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>

Scripts:


    <script>

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

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

Grid:


    <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>


Solution

  • I have figured it out, the issue lies within the struts grid itself. This was fixed by setting loadonce to false.