如果勾选或取消勾选复选框,我需要您在启用和禁用基于rowSelectCheckbox和rowUnselectCheckbox的inputText时的帮助。如果勾选了,那么我需要启用inputText,否则应该在页面加载和取消时禁用它。默认情况下,在页面加载时禁用inputText。这是jsf的代码:
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(222, "BBBBBB", "YYYYYYY", "IN", disable);
employeeList.add(w1);
employeeList.add(w2);
employeeList.add(w3);
}
public void EnableInputText(SelectEvent event) {
for(int i=0;i<=selectedEmployees.size();i++){ //Assuming you have declared as List
for(int j=0;j<=employeeList.size();j++){
if(selectedEmployees.get(i).getId().equals(employeeList.get(j).getId()))
{
employeeList.get(j).setDisable(false);
break;
}
}
}
}
以下是bean中的代码:
public class Student {
private Integer id;
private String name;
private String location;
private String remarks;
private boolean disable;
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;
}
public void setId(Integer id) {
this.id = id;
}
public Integer getId() {
return id;
}
public void setName(String name) {
this.name = name;
}
public String getName() {
return name;
}
public void setLocation(String location) {
this.location = location;
}
public String getLocation() {
return location;
}
public void setRemarks(String remarks) {
this.remarks = remarks;
}
public String getRemarks() {
return remarks;
}
public void setDisable(boolean disable) {
this.disable = disable;
}
public boolean isDisable() {
return disable;
}
学生豆:
cwd
在Bean中,如果勾选了行,我在启用inputText时遇到困难。你能帮忙吗? 现在我收到了错误: java.lang.IndexOutOfBoundsException:Index:3,Size:3 if if tick and checkbox
答案 0 :(得分:1)
首先使用selectionMode="multiple"
,这意味着接下来将启用textField的多行
而不是这个:
<h:inputText value="#{emp.remarks}" disabled="#{empBean.enable}" />
写
<h:inputText value="#{emp.remarks}" disabled="#{emp.enable}" />
表示在bean之后声明一个变量enable
:
for(int i=0;i<=selectedEmployees.size();i++){ //Assuming you have declared as List
for(int j=0;j<=empList.size();j++){
if(selectedEmployees.get(i).getId().equals(empList.get(j).getId()){
empList.get(j).setEnable(false);
}
}
}
在此之前,您可以编写一个for loop
并停用所有textField
列表,以便rowUnselect