I have a JSF page in which I repeat the list in <h:dataTable> to display some lines containing a checkbox, text and text box.
I have to check <h:dataTable> so that when the user checks the checkbox, he must enter the text inside the text box.
This is my JSF page.
<h:form prependId="false" id="form"> <h:dataTable id="rm" width="100%" cellspacing="4" value="#{controller.alertTriggers}" var="alt" columnClasses="c1,c2,c3,c4"> <h:column> <h:selectBooleanCheckbox value="#{alt.checkValue}" id="checkbox"/> </h:column> <h:column> <h:outputText value="#{alt.id}" /> </h:column> <h:column> <h:outputFormat value="#{alt.msg1}" /> </h:column> <h:column> <h:message for="emailID" id="email" styleClass="validation-error"/> <h:inputText value="#{alt.mailId}" id="emailID" style="width: 87%;" /> </h:column> </h:dataTable> </h:form>
I specified the identifier of all the flags as checkbox and the id of all text fields as emailID . When the page is displayed, when checking the source of the page, I found that the identifiers of the flags are: "rm: 0: checkbox", "rm: 1: checkbox" ... and those of the text fields: "rm: 0: EMAILID", 'tm: 1: EMAILID '..
In the controller, I want to access these dynamic text fields and check boxes for which I use the following code:
FacesContext context = FacesContext. getCurrentInstance(); for (int i=0;i<9;i++){ UIInput u=(UIInput) FacesContext.getCurrentInstance().getViewRoot().findComponent( "form:rm:" +i+":checkbox" ); if ((Boolean) u.getValue()){ UIInput ui=(UIInput) FacesContext.getCurrentInstance().getViewRoot().findComponent( "form:rm:" +i+":emailID" );
But this gives java.lang.NullPointerException
Even using the code:
UIInput u=(UIInput) FacesContext.getCurrentInstance().getViewRoot(). findComponent( "form:rm:0:checkbox" ); gives the same exception.
But if I use
UIInput u=(UIInput) FacesContext.getCurrentInstance().getViewRoot(). findComponent( "form:rm:checkbox" );
it does not give a Null Pointer Exception, but I do not know if checkbox has a value.
So in general
JSF generates identifiers like rm: 1: checkbox, rm: 2: checkbox, etc., but when I try to access this component of the user interface on the JSF page, I cannot do this.
Am I missing something?