-2

我已经阅读了所有遵循 jqgrid with struts2 展示中显示的示例。但是我的网格没有显示出来。请帮帮我。下面是我的代码片段。当我在 url 中输入动作名称时,它会显示 json。当我在 url 中键入 jsp 路径时,它不会向我显示 jqgrid。但是当我查看页面的源代码时,它会为 jqgrid 创建代码。

JSP 文件

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<%@ taglib prefix="s" uri="/struts-tags"%> 
<%@taglib  prefix="sj" uri="/struts-jquery-tags" %>
<%@taglib  prefix="sjg" uri="/struts-jquery-grid-tags" %>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>

<sj:head jqueryui="true" jquerytheme="redmond"></sj:head>
</head>
<body>

<s:url id="remoteurl" action="/SreebhogStore/incomingRawMaterial1" />


<sjg:grid id="gridtable" caption="Roles" dataType="json" href="%{remoteurl}" pager="true" gridModel="gridModel"  rowList="10,15,20" rowNum="5" rownumbers="true"
 width="800" navigator="true" navigatorView="false" navigatorDelete="false" 
 navigatorAdd="false" navigatorEdit="false" navigatorSearch="false">
<sjg:gridColumn name="lotNo" index="lotNo" title="Role Name"
 sortable="true" formatter="editrole" />
 </sjg:grid>

</body>
</html>

Struts 2 配置

<package name="incomingRawMaterialManagement" extends="struts-default, json-default"     namespace="/SreebhogStore">
<interceptors>
<interceptor name="login" class="com.sreebhog.interceptors.LoginInterceptor" />
<interceptor-stack name="loginStack">
<interceptor-ref name="login" ></interceptor-ref>
<interceptor-ref name="defaultStack" ></interceptor-ref>
</interceptor-stack>
</interceptors>
<default-interceptor-ref name="loginStack"></default-interceptor-ref>

<action name="incomingRawMaterial1" class="com.sreebhog.actions.IncomingRawMaterialAction">

<result name="success" type="json"></result>

</action> 
</package>

这是我的动作课

public class IncomingRawMaterialAction extends ActionSupport implements LoginRequired,SessionAware,ErrorSuccessMessages
    ,ServletRequestAware{

private static final long serialVersionUID = 1L;
private Map<String, Object> sessionMap;
HttpServletRequest request;

//For incoming raw material initialization
private List<Products> rawMaterials;
private List<Party> parties;

//For jqGrid
private List<IncomingRawMaterial> gridModel;
private Integer rows = 0; //Number of rows
private Integer page = 0; //Get the requested page. By default grid sets this to 1.
private String sort;  // sorting order - asc or desc
private String sidx;  // get index row - i.e. user click to sort.
private String searchString;    // The Search String
private String searchOper;  // The Search Operation ['eq','ne','lt','le','gt','ge','bw','bn','in','ni','ew','en','cn','nc']
private Integer total = 0;  // Your Total Pages
private Integer records = 0;    // All Record

public String execute()
{

rows=5;

gridModel = new ArrayList<IncomingRawMaterial>(); 
gridModel.add(new IncomingRawMaterial()); 
gridModel.add(new IncomingRawMaterial()); 
System.out.println("HERE--------------------------------------------------");
//calculate the total pages for the query
total =2;//(int) Math.ceil((double)records / (double)rows);

return SUCCESS;
}

public String getJSON()
{
System.out.println("JSON------------------------------------------------------");
return execute();
}

//Getters and setters and override methods

//JQGRID GETTERS AND SETTTERS

}

请注意,控制台消息也不会显示。所以我怀疑 jqgrid 没有要求我采取行动。

这是包含的 jar 列表 antlr-2.7.7.jar classmate-0.5.4.jar commons-collections-3.2.1.jar commons-fileupload-1.2.1.jar commons-io-1.3.2.jar commons- logging-1.0.4.jar dom4j-1.6.1.jar freemarker-2.3.15.jar hibernate-commons-annotations-4.0.1.Final.jar hibernate-core-4.0.0.Final.jar hibernate-jpa-2.0 -api-1.0.1.Final.jar javassist-3.12.1.GA.jar jandex-1.0.3.Final.jar jboss-logging-3.1.0.CR2.jar jboss-transaction-api_1.1_spec-1.0.0 .Final.jar log4j-1.2.14.jar mysql-connector-java-5.1.3-rc-bin.jar ognl-2.7.3.jar servlet-api.jar struts2-convention-plugin-2.1.8.1.jar xwork -core-2.1.6.jar

**Here are the important ones i guess.**

struts2-core-2.1.8.1.jar
struts2-jquery-grid-plugin-3.5.1.jar
struts2-jquery-plugin-3.5.1.jar
struts2-json-plugin-2.1.8.1.jar

编辑 1:我现在可以查看我的网格,但它仍然没有加载 json 数据。问题在于 sjg:column 标记之一中的格式化程序属性。

4

1 回答 1

2

已解决: 我自己解决了这个问题。问题出在 s:url 标签上。它没有定义命名空间。我正在通过.../JSP/index.jsp 访问该链接。所以它正在寻找 /JSP 本身的动作。如果有麻烦大家见谅。我希望我的发现可以帮助将来的人。

于 2013-03-26T09:20:14.070 回答