当用户单击Struts2 jquery网格的删除按钮时,卡在获取特定行的id

时间:2012-10-08 16:44:07

标签: java struts2 jqgrid struts2-jquery

我正在使用Jquery Grid在struts 2中开发一个小应用程序来显示数据结果。

当我点击编辑按钮时,特定的行ID即将到来。 但是,当我单击删除按钮删除该行时,其ID不会到来。 使用所选行(Struts2 Jquery Grid)执行删除操作时如何获取行的id?

Plz帮助我。

myJspFile.jsp

            <%@ page contentType="text/html; charset=UTF-8"%>
            <%@ taglib prefix="s" uri="/struts-tags"%>
            <%@ taglib prefix="sj" uri="/struts-jquery-tags"%>

            <%@ taglib prefix="sjg" uri="/struts-jquery-grid-tags"%>
            <jsp:include page="../../loginCheck.jsp" />
            <html>
            <head>
            <title>Hello World</title> 
            <style type="text/css">
            @import
            url(<%=request.getContextPath()%>/css/style1.css);
            </style> 
             <sj:head jqueryui="true" jquerytheme="le-frog"/>
            </head>
            <body> 
                <div id="setpage"> <s:url id="editurl" action="nedit"/>
                    <s:url id="editurl" action="nedit"/>
                    <s:url  id="remoteurl" action="ntable"/> 
                  <sjg:grid
                    id="gridtable"
                    caption="Subject Setup Navigator"
                    dataType="json"
                    href="%{remoteurl}"
                    pager="true"
                    rowList="10,20,100"
                     rowNum="5"
                    navigator="true"
                    width="999"
                    navigatorSearchOptions="{sopt:['eq','ne','lt','gt']}"
                    navigatorAddOptions="{height:280,reloadAfterSubmit:true}"
                    navigatorEditOptions="{height:280,reloadAfterSubmit:false}"
                    navigatorEdit="false"
                    navigatorView="false"
                    navigatorDelete="true"
                    navigatorDeleteOptions="{height:280,reloadAfterSubmit:true}"
                    gridModel="gridModel" 
                    editurl="%{editurl}"
                    editinline="true"
                    onSelectRowTopics="rowselect"

                >
                       <sjg:gridColumn name="subjectId" index="subjectId" title="SubjectId" formatter="integer" sortable="false" key="true"    hidden="true"   />
                       <sjg:gridColumn name="subjectName" index="subjectName" title="Subject Name" sortable="true" search="true"
                                        editable="true"
                                        edittype="text" />
                    </sjg:grid> 
                <br/>

                </div>
            </body>
            </html>

MyActionClass.java

                /*
             * To change this template, choose Tools | Templates
             * and open the template in the editor.
             */
            package v.esoft.actions.subjectdetails; 
            import com.opensymphony.xwork2.ActionSupport; 
            import java.text.SimpleDateFormat; 
            import com.opensymphony.xwork2.ModelDriven; 
            import v.esoft.dao.SubjectdetailsDAO.SubjectdetailsDAO; 
            import v.esoft.pojos.Subjectdetails;

            public class SubjectdetailsEditAction   extends ActionSupport  implements ModelDriven<Subjectdetails>
            {
                private static final long serialVersionUID = -6659925652584240539L; 
               private String oper; 
                int subjectId;
                 Subjectdetails subject=new Subjectdetails();
               SimpleDateFormat formatter1 = new SimpleDateFormat("yyyy-MM-dd"); 
               SubjectdetailsDAO dao=new SubjectdetailsDAO();       


               @Override
               public Subjectdetails getModel()
            {   
                  return subject;
               }

              public String execute() throws Exception
                {    
                  System.out.println(subject.getSubjectId());
                  if(oper.equalsIgnoreCase("add"))
                    {
                      System.out.println ("inside action");
                      dao.saveOrUpdateSubject(subject);  
                    }
                    else if (oper.equalsIgnoreCase("edit"))
                    { 
                         dao.saveOrUpdateSubject(subject);  
                    }
                    else if (oper.equalsIgnoreCase("del"))
                    {
                        System.out.println("subjectId");
                        System.out.println(subject.getSubjectId());
                    //  dao.deleteSubject(subjectId);
                    }
                    return SUCCESS;
                } 
              //---------------
                public String getOper() {
                    return oper;
                }

                public void setOper(String oper) {
                    this.oper = oper;
                }


                public Subjectdetails getSubject() {
                    return subject;
                }


                public void setSubject(Subjectdetails subject) {
                    this.subject = subject;
                }
                public int getSubjectId() {
                    return subjectId;
                }
                public void setSubjectId(int subjectId) {
                    this.subjectId = subjectId;
                }


            }

Subjectdetails.java [My pojo]

                package v.esoft.pojos;

            // Generated Oct 6, 2012 1:58:21 PM by Hibernate Tools 3.4.0.CR1

            import java.util.Date;

            /**
             * Subjectdetails generated by hbm2java
             */
            public class Subjectdetails implements java.io.Serializable {

                private int subjectId;
                private String subjectName;
                private Integer createrId;
                private Date createdDate;
                private Integer updateId;
                private Date updatedDate;

                public Subjectdetails() {
                }

                public Subjectdetails(int subjectId) {
                    this.subjectId = subjectId;
                }


                public Subjectdetails(int subjectId, String subjectName, Integer createrId,
                        Date createdDate, Integer updateId, Date updatedDate) {
                    this.subjectId = subjectId;
                    this.subjectName = subjectName;
                    this.createrId = createrId;
                    this.createdDate = createdDate;
                    this.updateId = updateId;
                    this.updatedDate = updatedDate;
                } 

                public int getSubjectId() {
                    return this.subjectId;
                }

                public void setSubjectId(int subjectId) {
                    this.subjectId = subjectId;
                }

                public String getSubjectName() {
                    return this.subjectName;
                }

                public void setSubjectName(String subjectName) {
                    this.subjectName = subjectName;
                }

                public Integer getCreaterId() {
                    return this.createrId;
                }

                public void setCreaterId(Integer createrId) {
                    this.createrId = createrId;
                }

                public Date getCreatedDate() {
                    return this.createdDate;
                }

                public void setCreatedDate(Date createdDate) {
                    this.createdDate = createdDate;
                }

                public Integer getUpdateId() {
                    return this.updateId;
                }

                public void setUpdateId(Integer updateId) {
                    this.updateId = updateId;
                }

                public Date getUpdatedDate() {
                    return this.updatedDate;
                }

                public void setUpdatedDate(Date updatedDate) {
                    this.updatedDate = updatedDate;
                }

            }

1 个答案:

答案 0 :(得分:1)

使用id代替subjectId作为主键。 并再次创建您的SQL表和pojo。然后它会工作。