我有一个网格,它在页面加载时显示数据,还有一个表单,它在提交时从datepicker获取变量,并最终调用一个操作。我希望在上面的网格中加载新的json结果,但我在空白页面上获得json对象元素({"JSON":"SUCCESS","endDate":"28/03/2012","listOfLogs":[{"date":"27-03-2012"…等)
这是我的代码:
<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>
我正在使用以下libs:支柱2 2.3.1.2struts2 jquery 3.3.0struts2 jquery网格插件3.3.0
有什么建议吗?非常感谢。
首先,您应该在sjg:grid标记上指定表单id和一个重新加载网格值的主题。如果您这样做,它会提交表单中的值并重新加载网格。这意味着操作getCurrentDateLogs的execute()方法应该返回JSON。或者,您可以将getLogsByDates操作上的execute()方法移动到getCurrentDateLogs上的另一个方法。
所以应该是:
public class GetCurrentDateLogs extends ActionSupport
{
public execute()
{
return INPUT;
}
public String getLogsByDates()
{
//Your code, sets listOfLogs, page, total etc...
return JSON;
}
}
在您的JSP中:
<s:url id="getCurrentDateLogs" action=GetCurrentDateLogs" method="getLogsByDates"/>
<sjg:grid
id="getLogs"
formIds="form2"
reloadTopics="reloadMyGrid"
您应该将<sj:submit>
更改为<sj:a>
标记,并将button属性设置为true。它可能与<sj:submit>
标签一起使用,但我从未尝试过。
最后,按钮应更改为:
<sj:a button="true" buttonIcon="yourIcon" onClickTopics="reloadMyGrid">Search</sj:a>
希望这能有所帮助。
至少,您的sj:submit应该设置属性targets="getLogs"。不过,你也可能会错过其他东西。