我需要您的帮助,根据列表中的可用值更改boolean
变量的值。我定义了一个名为Student
的类:
public class Student {
private Integer id;//Getter and Setter
private String name;//Getter and Setter
private String location;//Getter and Setter
private String remarks;//Getter and Setter
private boolean disable;//Getter and Setter
public Student(Integer id, String name, String location, String remarks, boolean disable){
this.id = id;
this.name = name;
this.location = location;
this.remarks=remarks;
this.disable=disable;
}
默认情况下,bean中的disable值为true。在该计划中,我有两个列表employeeList
和selectedEmployees
。 employeeList
具有值,selectedEmployees
列表具有所选值:
private List<Student> employeeList = new ArrayList<Student>();
private List<Student> selectedEmployees;
private boolean disable;
@PostConstruct
public void init() {
//add Employees
disable=true;
Student w1 = new Student(111, "AAAA", "ZZZZ", "", disable);
Student w2 = new Student(222, "CCCCC", "ZZZZZ", "OUT", disable);
Student w3 = new Student(333, "BBBBBB", "YYYYYYY", "IN", disable);
employeeList.add(w1);
employeeList.add(w2);
employeeList.add(w3);
}
但是,我有一个名为EnableInputText
的方法,它将被调用以检查上述任何值是否在selectedEmployees
列表中,然后它应该更改{{1}的值1}}变量到disable
:
false
但是使用上面的代码,我收到了错误:
java.lang.IndexOutOfBoundsException:Index:3,Size:3 at java.util.ArrayList.RangeCheck(ArrayList.java:547)at java.util.ArrayList.get(ArrayList.java:322)
答案 0 :(得分:0)
selectedEmployees.get(j).setDisable(false);
我认为你的意思是用i而不是j代替那条线?
或反面可能:
employeeList.get(j).setDisable(false);