问题
I am developing some employee registration application using struts 1.3. On one jsp page a table shows all the registration requests, including all the details of that particular employee row-wise(One row for each employee registration request). Each row contains two radio buttons approved and reject. Admin has to select any one either he can skip for few rows(for making it pending). After pressing submit button how to read all radio buttons values one by one to update the database according to admin's selection.
What I tried:
DataAccess.java class(Bean for handling collection)
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); } }
In my ActionForm class
private ArrayList<DataAccess> dataList; public void setDataList(ArrayList<DataAccess> dataList) {this.dataList = dataList;} public ArrayList<DataAccess> getDataList() {return dataList;}
In my Action class execute method():this method sends the control to a jsp page(Pending.jsp) where I am displaying all pending requests. After this page control goes to approveUsers(----) method of same DispatchAction class to update the database.
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");
My Jsp page code(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>
problem is,if I am not putting radio buttons it is displaying data properly. while I am trying to put radio buttons(for admin choice of approv or reject) I am getting this error:
javax.servlet.jsp.JspException: No getter method available for property dataList for bean under name item
I also tried to put these getter and setter in DataAccess.java(Bean class for collection) and AppForm class (FormBean) but no luck..
public void setItem(int index,DataAccess value){this.dataList.add(index,value);}
public DataAccess getItem(int index){return this.dataList.get(index);}
Any Help, suggestion will be appreciated.
回答1:
Finally I solved this problem.
Here are some suggestions to handle this issue
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.
来源:https://stackoverflow.com/questions/15265501/how-to-update-and-read-radio-button-choice-valueone-for-each-row-in-arraylist