我有一个jsp页面(page1.jsp)。这个页面有一个网格,网格使用say动作类A加载,在其中一个网格列上我有一个onclick打开一个对话框。 open上的对话框调用一个不同的struts动作类,比如说B.这个动作类有一个结果页面,page2.jsp。此页面还有一个网格。我遇到的问题是数据以JSON格式而不是网格显示。
我不确定struts.xml是否存在问题或问题所在。我已经检查了firebug中的JSON数据,一切看起来都正确,gridModel有预期的数据,但数据没有显示在网格上,它在模态对话框中显示为JSON数据。
使用:Struts 2.2.3,Struts-jquery-plugin版本3.3.1
相关守则: 的Page1.jsp
<SCRIPT type="text/javascript">
function formatLink(cellvalue, options, rowObject) {
return "<a href='#' onClick='javascript:openDialog("+cellvalue+")'>" + cellvalue + "</a>";
}
function openDialog(fsNumber) {
$("#sqv").load("<s:property value="testurl"/>?number="+number);
$("#sqv").dialog('open');
}
</SCRIPT>
<sjg:grid
id="dataGrid"
caption="States"
hidegrid="false"
dataType="json"
href="%{remoteurl}"
pager="false"
altRows="true"
gridModel="gridModel"
rowNum="100000"
rowTotal="100000"
loadonce="true"
width="940"
tabindex="false"
onSelectRowTopics="rowselect">
<sjg:gridColumn name="st.fsNumber" index="st.fsNumber" title="FNS Number" formatter="formatfsNumberStars252Link" sortable="true" sorttype="integer" width="80"/>
<sjg:gridColumn name="st.stName" index="st.stName" title="Store Name" sortable="true" width="210"/>
<sjg:gridColumn name="st.stType.stTypeCode" index="st.stType.stTypeCode" title="Store Type" sortable="true" width="40"/>
<sjg:gridColumn
name="st.fsNumber"
index="st.fsNumber"
title="Action"
formatter="formatLink"
sortable="false"
width="80"
/>
</sjg:grid>
</div>
Page2.jsp
<div id="idTwo">
<s:url id="remoteurl" action="jsonSQV"/>
<sjg:grid
id="dataGrid"
caption="Activity"
hidegrid="false"
dataType="json"
href="%{remoteurl}"
pager="false"
altRows="true"
gridModel="gridModel"
loadonce="true"
rowNum="100000"
rowTotal="100000"
tabindex="true"
width="940">
<sjg:gridColumn name="reportTime" index="reportTime" title="Reporting Period" formatter="date" formatoptions="{srcformat: 'm/Y', newformat:'m/Y'}" sortable="true" sorttype="date" width="80"/>
<sjg:gridColumn name="volume" index="volume" title="Dollar Volume" formatter="currency" formatoptions="{prefix: '$', thousandsSeparator:','}" sortable="true" sorttype="currency" width="140"/>
<sjg:gridColumn name="summary" index="summary" title="ALERT Rank" formatter="number" sortable="true" sorttype="number" width="60"/>
</sjg:grid>
</div>
<script type="text/javascript">$(function() {$('#dataGrid').attr('tabindex','800');});</script>
对应的Struts.xml
<package name="blah" namespace="/" extends="struts-default,json-default">
<action name="*ClassA" class="com.ads.snf.trelang.action.ClassA" method="{1}">
<result name="input">/blah/page1.jsp</result>
<result name="success">/blah/page1.jsp</result>
<result name="json" type="json"><param name="target">gridModel</param></result>
</action>
<action name="*SQV" class="com.ads.snf.trelang.action.ClassB" method="{1}">
<result name="input" type="redirectAction">
<param name="actionName">executeStoreQuickView</param>
</result>
<result name="success" type="redirectAction">
<param name="actionName">jsonStoreQuickView</param>
</result>
<result name="json" type="json"><param name="target">gridModel</param></result>
</action>
</package>
B级动作类:
public class ClassB extends BaseAction {
@Autowired
MRservice service;
private SQVResponse response;
private Integer number;
private Integer fromYear;
private Integer toYear;
private Integer toMonth;
private Integer fromMonth;
@HoldDataInSession
private String dateRangeFrom;
@HoldDataInSession
private String dateRangeTo;
//STRUTS2 JQUERY GRID STUFF
//get how many rows we want to have into the grid - rowNum attribute in the grid
private Integer rows = 0;
//Get the requested page. By default grid sets this to 1.
private Integer page = 0;
// sorting order - asc or desc
private String sord;
// get index row - i.e. user click to sort.
private String sidx;
// Search Field
private String searchField;
// The Search String
private String searchString;
// he Search Operation ['eq','ne','lt','le','gt','ge','bw','bn','in','ni','ew','en','cn','nc']
private String searchOper;
// Your Total Pages
private Integer total = 0;
// All Record
private Integer records = 0;
@Override
public String input() {
LoggingUtility.info("inside input method.", this.getClass().getName());
String result = super.input();
getReport();
return result;
}
public String execute() {
//super.input();
LoggingUtility.info("inside execute method.", this.getClass().getName());
return getReport();
}
public String json() {
LoggingUtility.info("Entered json().", this.getClass().getName());
String result = ERROR;
//get response from session
if (this.getUserSessionDetails().getReportResponse() != null) {
this.response = (SQVResponse) this.getUserSessionDetails().getReportResponse();
}
result = JSON;
LoggingUtility.info("Exiting json().", this.getClass().getName());
return result;
}
private String getReport() {
HashMap<String, Object> map;
LoggingUtility.info("Entering getReport", this.getClass().getName());
String result = ERROR;
try {
if (response == null){
response = new SQVResponse();
}
//response has data, and hence the response.getResultList..this has been verified in debug mode
setGridModel(response.getResultList());
if (LoggingUtility.getLogger().isInfoEnabled() && response.getResultList() != null) {
int cnt = response.getResultList().size();
LoggingUtility.info("MRservice.getReport returned the following number of results: " + cnt, this.getClass().getName());
}
if (this.response.getResultList().size() == 0) {
addActionMessage(getText(UserInterfaceConstants.GENERAL_SEARCH_RESULT_MESSAGE_100));
}
this.getUserSessionDetails().setReportResponse(response);
result = SUCCESS;
//result = JSON;
} catch (BaseSystemException e) {
List<String> argList = new ArrayList<String>();
argList.add(e.getExceptionId());
addActionError(getText(e.getExceptionMessageCode(), argList));
LoggingUtility.error("Error .", e, this.getClass().getName());
}
catch (Exception e) {
List<String> argList = new ArrayList<String>();
UUID expId = UUID.randomUUID();
argList.add(expId.toString());
addActionError(getText(Constants.SYSTEM_EXCEPTION_200, argList));
LoggingUtility.error("Exception ID: " + expId.toString() + "Error in getting Report Data.", e, this.getClass().getName());
}
return result;
}
public Integer getnumber() {
return number;
}
public void setnumber(Integer number) {
this.number = number;
}
public Integer getFromYear() {
return fromYear;
}
public void setFromYear(Integer fromYear) {
this.fromYear = fromYear;
}
public Integer getToYear() {
return toYear;
}
public void setToYear(Integer toYear) {
this.toYear = toYear;
}
public Integer getToMonth() {
return toMonth;
}
public void setToMonth(Integer toMonth) {
this.toMonth = toMonth;
}
public Integer getFromMonth() {
return fromMonth;
}
public void setFromMonth(Integer fromMonth) {
this.fromMonth = fromMonth;
}
public String getDateRangeFrom() {
return dateRangeFrom;
}
public void setDateValueFrom(String dateValue) {
this.dateRangeFrom = dateValue;
if (!dateValue.isEmpty()) {
String[] dateFrom = dateValue.split("/");
this.fromMonth = Integer.parseInt(dateFrom[0]);
this.fromYear = Integer.parseInt(dateFrom[1]);
}
}
public void setDateValueTo(String dateValue) {
this.dateRangeTo = dateValue;
if (!dateValue.isEmpty()) {
String[] dateTo = dateValue.split("/");
toMonth = Integer.parseInt(dateTo[0]);
toYear = Integer.parseInt(dateTo[1]);
}
}
public void setDateRangeFrom(String dateRangeFrom) {
this.dateRangeFrom = dateRangeFrom;
}
public String getDateRangeTo() {
return dateRangeTo;
}
public void setDateRangeTo(String dateRangeTo) {
this.dateRangeTo = dateRangeTo;
}
public Integer getRows() {
return rows;
}
public void setRows(Integer rows) {
this.rows = rows;
}
public Integer getPage() {
return page;
}
public void setPage(Integer page) {
this.page = page;
}
public String getSord() {
return sord;
}
public void setSord(String sord) {
this.sord = sord;
}
public String getSidx() {
return sidx;
}
public void setSidx(String sidx) {
this.sidx = sidx;
}
public String getSearchField() {
return searchField;
}
public void setSearchField(String searchField) {
this.searchField = searchField;
}
public String getSearchString() {
return searchString;
}
public void setSearchString(String searchString) {
this.searchString = searchString;
}
public String getSearchOper() {
return searchOper;
}
public void setSearchOper(String searchOper) {
this.searchOper = searchOper;
}
public Integer getTotal() {
return total;
}
public void setTotal(Integer total) {
this.total = total;
}
public Integer getRecords() {
return records;
}
public void setRecords(Integer records) {
this.records = records;
}
public MRservice getService() {
return service;
}
public void setService(MRservice service) {
this.service = service;
}
public List<SQVBean> getGridModel() {
return response.getResultList();
}
public void setGridModel(List<SQVBean> gridModel) {
this.response.setResultList(gridModel);
}
public Integer getMenuIndex() {
return menuIndex;
}
public String getPageType() {
return getScreenId().substring(getScreenId().lastIndexOf("_") + 1);
}
public SQVResponse getResponse() {
return response;
}
public void setResponse(SQVResponse response) {
this.response = response;
}
}
此外,上面的大多数代码都与手头的问题相关。
请帮忙。希望我至少描述了这个问题。
谢谢你, 约翰
答案 0 :(得分:1)
你需要做两件事:
<action name="DisplayAction" class="com.ads.snf.trelang.action.ClassA" method="{1}">
<result name="input">/blah/page1.jsp</result>
<result name="success">/blah/page1.jsp</result></action>
<action name="JsonAction" class="com.ads.snf.trelang.action.ClassA" method="{1}">
<result type="json"></result></action>
当您像gridModel一样传递结果参数时,最好的方式是使用root。
gridModel
但是如果设置gridModel =“gridModel”,则不需要指定param,struts会读取你json并找到gridModel列表没有问题。
如果您需要有关Struts2-jquery的更多信息,我邀请您发帖:https://groups.google.com/forum/?hl=fr&fromgroups#!forum/struts2-jquery
Johannes将回答您的任何问题以及其他struts2-jquery用户。我希望这会有效,因为我没有查看所有代码,但似乎很好。