jsf - How to enable/disable inputText on rowSelectCheckbox and rowUnselectCheckbox -


i need in enabling , disabling inputtext based on rowselectcheckbox , rowunselectcheckbox if checkbox ticked or unticked. if ticked, need enable inputtext otherwise should disabled on page load , on untick. default inputtext disabled on page load. here code jsf:

  <h:form id="request">             <p:datatable value="#{datatableview.employeelist}" id="employee" var="emp"                          selection="#{datatableview.selectedemployees}" rowkey="#{emp.id}">             <p:ajax event="rowselectcheckbox" listener="#{datatableview.enableinputtext}" />         <p:ajax event="rowunselectcheckbox" listener="#{datatableview.enableinputtext}" />      <p:columngroup type="header">         <p:row>            <p:column/>            <p:column headertext="id"/>            <p:column headertext="name"/>            <p:column headertext="location"/>            <p:column headertext="remarks"/>         </p:row>     </p:columngroup>         <p:column selectionmode="multiple" style="width:2%;text-align:center"/>                 <p:column headertext="id">                     <h:outputtext value="#{emp.id}"/>                 </p:column>                 <p:column headertext="name">                     <h:outputtext value="#{emp.name}"/>                 </p:column>                 <p:column headertext="location">                     <h:outputtext value="#{emp.location}"/>                 </p:column>                 <p:column headertext="remarks">                     <h:inputtext id="inputt1" value="#{emp.remarks}" disabled="#{emp.disable}"/>                 </p:column>             </p:datatable>         </h:form> 

and here code in bean:

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 have declared 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;         }        }      } } 

the student 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;     } 

and in bean, facing difficulties in enabling inputtext entry if row ticked. please help. got error : java.lang.indexoutofboundsexception: index: 3, size: 3 if tick , checkbox

first thing using selectionmode="multiple" means there multiple rows textfield enabled next instead of :

 <h:inputtext value="#{emp.remarks}" disabled="#{empbean.enable}" /> 

write

 <h:inputtext value="#{emp.remarks}" disabled="#{emp.enable}" /> 

means declare 1 variable enable in bean after that:

    for(int i=0;i<=selectedemployees.size();i++){ //assuming have declared list      for(int j=0;j<=emplist.size();j++){                if(selectedemployees.get(i).getid().equals(emplist.get(j).getid()){         emplist.get(j).setenable(false);      }     }   } 

before can write 1 for loop , disable textfield list work rowunselect


Comments

Popular posts from this blog

Django REST Framework perform_create: You cannot call `.save()` after accessing `serializer.data` -

Why does Go error when trying to marshal this JSON? -