0

I have a grid which displays data on page load, and also a form that on submit gets the variables from datepicker and finally calls an action. I want the new json result to load on grid above but instead of that i get the json object elements on a blank page ({"JSON":"SUCCESS","endDate":"28/03/2012","listOfLogs":[{"date":"27-03-2012"... etc.)

This is my code:

<s:url id="getCurrentDateLogs" action="getCurrentDateLogs"/>

<sjg:grid
    id="getLogs"
    dataType="json"
    href="%{getCurrentDateLogs}"
    gridModel="listOfLogs"
    onSelectRowTopics="rowselect"
    loadonce="true"  
    >
    <sjg:gridColumn name="userid" index="userid" title="User ID" sortable="true" align="center"/>
    <sjg:gridColumn name="username" index="username" title="Username" sortable="true"/>
    <sjg:gridColumn name="logaction" index="logaction" width="600" title="Action" sortable="true"/>
    <sjg:gridColumn name="date" index="date" title="Date" sortable="true" sorttype="date" align="center"/>
    <sjg:gridColumn name="time" index="time" title="Time" sortable="true" sorttype="time" align="center"/>     
</sjg:grid>

<s:form action="getLogsByDates" id="form2"  theme="simple" cssClass="yform">
    <table class="">
        <tr><td>from:</td>
            <td><sj:datepicker value="yesterday" id="from" name="startDate" displayFormat="dd/mm/yy" label="from" /></td>
        </tr>
        <tr><td>to:</td> 
            <td><sj:datepicker value="today" id="to" name="endDate" displayFormat="dd/mm/yy" label="to" /></td>
        </tr>
        <tr><td colspan="2">
        <sj:submit
            value="Search" 
            button="true"
            indicator="indicator"
            />
        </td></tr>
    </table>
</s:form>

i am using the following libs: struts2 2.3.1.2 struts2-jquery 3.3.0 struts2-jquery-grid-plugin 3.3.0

Any suggestions? Thank you!

user1299029
  • 13
  • 1
  • 5

2 Answers2

0

First, you should specify the form id and a topic that reloads the grid values, on sjg:grid tag. If you do that, it submits the values inside the form and reloads the grid. Which means your execute() method on action getCurrentDateLogs should return JSON. Or you can just move execute() method on getLogsByDates action to another method on getCurrentDateLogs.

So it should be:

public class GetCurrentDateLogs extends ActionSupport
{

     public execute()
     {
         return INPUT;
     }

     public String getLogsByDates()
     {
        //Your code, sets listOfLogs, page, total etc...
        return JSON;
     }
}

And in your JSP:

<s:url id="getCurrentDateLogs" action=GetCurrentDateLogs" method="getLogsByDates"/>

    <sjg:grid
        id="getLogs"
        formIds="form2"
        reloadTopics="reloadMyGrid"

And you should change <sj:submit> to <sj:a> tag, and set button attribute to true. It might work with <sj:submit> tag, but I never tried.

Finally, the button should be changed to:

<sj:a button="true" buttonIcon="yourIcon" onClickTopics="reloadMyGrid">Search</sj:a>

Hope this helps.

batbaatar
  • 5,448
  • 2
  • 20
  • 26
  • I tried but still its not working, my code is at http://stackoverflow.com/questions/14466984/struts2-jquery-grid-ajax-data-reload-on-form-submit – Amol Ghotankar Jan 22 '13 at 22:05
  • Did you do exactly the same? As I can see in the other post, another person told you to use onClickTopics instead of onSuccessTopics which I told you to do so – batbaatar Jan 28 '13 at 22:00
0

At the very least, your sj:submit should set the attribute targets="getLogs". You may also be missing other things though.