struts 2 jqGrid没有显示

时间:2013-03-24 13:50:24

标签: jqgrid struts2

我已经阅读了所有跟随在带有struts2的jqgrid展示中显示的示例。但是我的网格没有显示出来。请帮帮我。以下是我的代码片段。当我在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 config

<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没有调用我的动作。

这是包含的罐子列表     ANTLR-2.7.7.jar     同学-0.5.4.jar     公地集合-3.2.1.jar     公地文件上传-1.2.1.jar     公地IO-1.3.2.jar     共享记录-1.0.4.jar     dom4j的-1.6.1.jar     freemarker的-2.3.15.jar     休眠公地的注解,4.0.1.Final.jar     休眠核心,4.0.0.Final.jar     冬眠-JPA-2.0-API-1.0.1.Final.jar     Javassist进行-3.12.1.GA.jar     jandex-1.0.3.Final.jar     JBoss的日志记录,3.1.0.CR2.jar     JBoss的事务,api_1.1_spec-1.0.0.Final.jar     log4j的-1.2.14.jar     MySQL的连接器的Java-5.1.3-RC-bin.jar     OGNL-2.7.3.jar     servlet的api.jar文件     Struts2的会展-插件,2.1.8.1.jar     XWork的核 - 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标签中的formatter属性。

1 个答案:

答案 0 :(得分:2)

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