0

我的项目需要自定义一个 jqgrid 编辑和删除选项,即具有编辑和删除前言的用户将可以编辑和删除网格数据。

我为此目的找到了一个代码

String edit_permission = util.getEdit_permission();
String delete_permission = util.getDelete_permission(); 
  // sets true or false to the strings and working fine

ValueStack stack = ActionContext.getContext().getValueStack();

stack.getContext().put("edit_permission", edit_permission);
stack.setValue("#attr['edit_permission']", edit_permission, false);

jqgrid 代码片段

<s:set id="edit_permission" value="#edit_permission"/>
<s:set id="delete_permission" value="#delete_permission"/> 

<sjg:grid
       id="gridtable"
       dataType="json"
       href="%{remoteurl}"
       pager="true"
       gridModel="gridModel"
       rowList="5,10,15,20"
       rowNum="5"

       navigator="true"
       navigatorAdd="false"
       navigatorEdit="#edit_permission"
       navigatorDelete="#delete_permission" >

Thw 代码在我获取它的地方运行良好,但在我的情况下,它抛出了一个错误。这是日志

WARNING: Error setting expression '#attr['edit_permission']' with value 'true'
ognl.OgnlException: target is null for setProperty(null, "edit_permission", true)
at ognl.OgnlRuntime.setProperty(OgnlRuntime.java:2219)
at ognl.ASTProperty.setValueBody(ASTProperty.java:127)
at ognl.SimpleNode.evaluateSetValueBody(SimpleNode.java:220)
at ognl.SimpleNode.setValue(SimpleNode.java:301)
at ognl.ASTChain.setValueBody(ASTChain.java:227)
at ognl.SimpleNode.evaluateSetValueBody(SimpleNode.java:220)
at ognl.SimpleNode.setValue(SimpleNode.java:301)
at ognl.Ognl.setValue(Ognl.java:737)......


WARNING: Error setting expression '#attr['delete_permission']' with value 'true'
ognl.OgnlException: target is null for setProperty(null, "delete_permission", true)
at ognl.OgnlRuntime.setProperty(OgnlRuntime.java:2219)
at ognl.ASTProperty.setValueBody(ASTProperty.java:127)
at ognl.SimpleNode.evaluateSetValueBody(SimpleNode.java:220)
at ognl.SimpleNode.setValue(SimpleNode.java:301)
at ognl.ASTChain.setValueBody(ASTChain.java:227)
at ognl.SimpleNode.evaluateSetValueBody(SimpleNode.java:220)
at ognl.SimpleNode.setValue(SimpleNode.java:301)
at ognl.Ognl.setValue(Ognl.java:737)
at com.opensymphony.xwork2.ognl.OgnlUtil.setValue(OgnlUtil.java:198)
at com.opensymphony.xwork2.ognl.OgnlValueStack.setValue(OgnlValueStack.java:161)
at org.apache.jsp.Production.projectIdCreation_jsp._jspService(projectIdCreation_jsp.java:306)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:388)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)

我无法弄清楚这个错误的实际原因......请帮助。

4

1 回答 1

0

行动:

private String editPermission;
private String deletePermission; 

public String execute() throws Exception{
    editPermission = util.getEdit_permission();
    deletePermission = util.getDelete_permission();
    return SUCCESS;
}

/* Getters */

public String getEditPermission(){
    return editPermission;
}

public String getDeletePermission(){
    return deletePermission;
}

使用 Eclipse 生成 Getter ALTSHIFTS,然后Generate Getters and Setters...

然后,在 JSP 中,在网格代码中:

...
  navigatorEdit = "%{editPermission}"
navigatorDelete = "%{deletePermission}"
...
于 2014-04-08T08:16:56.037 回答