struts 2 jqgrid自定义navigatorEdit

时间:2014-04-07 10:18:13

标签: struts2 jqgrid struts2-jquery-grid

我的项目需要自定义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)

我无法弄清楚这个错误的实际原因.... plz help。

1 个答案:

答案 0 :(得分: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生成Getters ALT SHIFT S 然后生成Getter和Setter ...

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

...
  navigatorEdit = "%{editPermission}"
navigatorDelete = "%{deletePermission}"
...