gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-01 04:49:11 25 4
gpt4 key购买 nike

我正在使用struts 1.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);
    }
    }
  2. 在我的 ActionForm 类中

    private ArrayList<DataAccess> dataList;
    public void setDataList(ArrayList<DataAccess> dataList) {this.dataList = dataList;}
    public ArrayList<DataAccess> getDataList() {return dataList;}
  3. 在我的 Action 类中执行 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");
  4. 我的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

我还尝试将这些 getter 和 setter 放入 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);}

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

最佳答案

终于解决了这个问题。

以下是处理此问题的一些建议

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.

关于java - 如何使用struts更新和读取Arraylist对象中的单选按钮选择值(每行一个),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15265501/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com