小编典典

如何使用Struts更新和读取Arraylist对象中的单选按钮选择值(每行一个)

jsp

我正在使用struts1.3开发一些员工注册应用程序。在一个jsp页面上,一张表显示了所有注册请求,包括该行特定员工的所有详细信息(每个员工注册请求一行)。每行包含两个批准和拒绝单选按钮。管理员必须选择任何一个,他可以跳过几行(以使其处于待处理状态)。按下提交按钮后,如何根据管理员的选择逐个读取所有单选按钮值以更新数据库。

我试过的

  1. DataAccess.java类(用于处理集合的Bean)
        public class DataAccess {

        private String regid,fname,lname,email,eid,contact,address,jdate,qualification,designation,adminchoice,imagepath;
        private String reqdate,approvedate,rejectdate,ipaddress;

        ArrayList<DataAccess> userList;

        //write the public constructors....        
        public DataAccess(){ }

        public DataAccess(String regid,String fname, String lname,String email,String eid,String contact,String address,String jdate,String qualification,String designation,String adminchoice,String imagepath,String reqdate,String approvedate,String rejectdate,String ipaddress)
        {
            this.regid=regid;
            this.fname=fname;
            this.lname=lname;
            this.email=email;
            this.eid=eid;
            this.contact=contact;
            this.address=address;
            this.jdate=jdate;
            this.qualification=qualification;
            this.designation=designation;
            this.adminchoice=adminchoice;
            this.imagepath=imagepath;
            this.reqdate=reqdate;
            this.approvedate=approvedate;
            this.rejectdate=rejectdate;
            this.ipaddress=ipaddress;
        }

        //Setter and getter methods for all properties...

        //for registration id....
        public void setRegid(String regid) { this.regid=regid;}
        public String getRegid(){ return regid;}

        // for first name....   
        public void setFname(String fname) { this.fname=fname;}
        public String getFname() { return fname;}

        //for last name....
        public void setLname(String lname) { this.lname=lname;}
        public String getLname(){ return lname;}

        //for email....
        public void setEmail(String email) { this.email=email;}
        public String getEmail(){ return email;}

        //for eid....
        public void setEid(String eid) { this.eid=eid;}
        public String getEid(){ return eid;}

        //for contact no....
        public void setContact(String contact) { this.contact=contact;}
        public String getContact() { return contact; }

        //for address....
        public void setAddress(String address){ this.address=address;}
        public String getAddress(){ return address;}

        //for joining date....
        public void setJdate(String jdate){ this.jdate=jdate;}
        public String getJdate(){ return jdate;}

        //for qualification....
        public void setQualification(String qualification) { this.qualification=qualification;}
        public String getQualification(){ return qualification; }

        //for experience....
        public void setDesignation(String designation) { this.designation=designation;}
        public String getDesignation() { return designation;}

        //for admin choice....
        public void setAdminchoice(String adminchoice){ this.adminchoice=adminchoice;}
        public String getAdminchoice(){ return adminchoice; }

        //for image path....
        public void setImagepath(String imagepath){ this.imagepath=imagepath;}
        public String getImagepath(){ return imagepath; }

        //for registration request date....
        public void setReqdate(String reqdate) { this.reqdate=reqdate;}
        public String getReqdate(){ return reqdate;}

        //for registration approval date....
        public void setApprovedate(String approvedate) { this.approvedate=approvedate;}
        public String getApprovedate(){ return approvedate;}

        //for registration rejection date....
        public void setRejectdate(String rejectdate) { this.rejectdate=rejectdate;}
        public String getRejectdate(){ return rejectdate;}

        //for ip address....
        public void setIpaddress(String ipaddress) { this.ipaddress=ipaddress;}
        public String getIpaddress(){ return ipaddress;}

        public ArrayList<DataAccess> createList()
        {
            userList=new ArrayList<DataAccess>();
            return userList;
        }

        public void addData(DataAccess da)
        {
            userList.add(da);
        }
    }
  1. 在我的ActionForm类中
        private ArrayList<DataAccess> dataList;
    public void setDataList(ArrayList<DataAccess> dataList) {this.dataList = dataList;}
    public ArrayList<DataAccess> getDataList() {return dataList;}
  1. 在我的Action类中,execute method():此方法将控件发送到一个jsp页面(Pending.jsp),在其中显示所有未决请求。在此页面控件之后,转到相同DispatchAction类的approveUsers(----)方法以更新数据库。
        DataAccess dtacs=new DataAccess();
    ArrayList<DataAccess> userList=dtacs.createList();

    do{
        if(rs3.next())
        {
            System.out.println("BBB.");
            jdate_string=new SimpleDateFormat("dd/MMM/YYYY").format(rs2.getDate(7));
            reqdate_string=new SimpleDateFormat("hh:mm:ss a
            dd/MMM/YYYY").format(rs2.getTimestamp(14)); 

            userList.add(new DataAccess(rs2.getString(1),rs2.getString(3),rs2.getString(4),
            rs3.getString(1),  rs2.getString(13),rs2.getString(5),rs2.getString(6),jdate_string,
            rs2.getString(8),rs2.getString(9),"no",rs2.getString(12),reqdate_string,"Not Approved",
            "Not Rejected",rs3.getString(2)));

            System.out.println(userList.size());
        }//if closing..

    } while(rs1.next());

    req.setAttribute("data", userList);
    return map.findForward("gopending");
  1. 我的Jsp页面代码(Pending.jsp)
        <logic:iterate id="item" name="data" indexId="idx">
        <tr>
            <td><bean:write name="idx"/></td>
            <td><bean:write name="item" property="regid"/></td>
            <td><bean:write name="item" property="eid"/></td>
            <td><bean:write name="item" property="fname"/></td>
            <td><bean:write name="item" property="lname"/></td>
            <td><bean:write name="item" property="designation"/></td>
            <td><bean:write name="item" property="email"/></td>
            <td><bean:write name="item" property="contact"/></td>
            <td><bean:write name="item" property="address"/></td>
            <td><bean:write name="item" property="qualification"/></td>
            <td><bean:write name="item" property="jdate"/></td>
            <td><bean:write name="item" property="reqdate"/></td>
            <td><bean:write name="item" property="ipaddress"/></td>
            <td><html:radio name="item" property="dataList"  indexed="true" value="approved"/></td>
            <td><html:radio name="item" property="dataList"  indexed="true" value="rejected"/></td> 
        </tr>
    </logic:iterate>

问题是,如果我没有按单选按钮,则它正在正确显示数据。当我尝试放置单选按钮(供管理员选择批准或拒绝)时,出现此错误:

    javax.servlet.jsp.JspException: No getter method available for property dataList for bean under name item

我还尝试将这些获取器和设置器放入DataAccess.java(用于收集的Bean类)和AppForm类(FormBean)中,但是没有运气。

    public void setItem(int index,DataAccess value){this.dataList.add(index,value);}
    public DataAccess getItem(int index){return this.dataList.get(index);}

任何帮助,建议将不胜感激。


阅读 384

收藏
2020-06-10

共1个答案

小编典典

最后我解决了这个问题。

以下是一些解决此问题的建议

1)Follow the above steps.
2)I did a silly mistake, while taking the radio buttons put property="adminchoice" (in my case).
3) Read the corresponding admin choice in the execute method of Action class where control goes after submitting form.
2020-06-10