I have jsf datatable populated from backing bean ArrayList. Now I need to compare values with the values in one column of my table, how can i do this?
my datatable:
<t:dataTable var="tabl"
rowIndexVar="rownum"
id="data"
value="#{bean.sortedList}"
>
……….
the column i want to compare data:
<t:column>
<f:facet name="header">
<h:commandLink>
<h:outputText value="sortedList"/>
</h:commandLink>
</f:facet>
<f:verbatim> </f:verbatim>
<h:inputText value="#{tabl.numbers}"
id="numbers">
</h:inputText>
</t:column>
my table structure:
<tbody id="myForm:data:tbody_element">
<tr>
...
<td> <input id="myForm:data:0:workAreaNumberU" name="myForm:data:0:workAreaNumberU" type="text" value="0001" size="4" onkeyup="value_altered(0);"></td>
</tr>
....
<tr>
...
<td> <span id="_idJsp1:data:1:workAreaNumber">0104</span></td>
...
</tr>
</tbody>
finally solved in this way (base on my table structure)
var table = document.getElementById("myForm:data:tbody_element");
var new_wa;
for (var i = 0, row; row = table.rows[i]; i++) {
var new_wa_box = document.getElementById("myForm:data:" + i + ":workAreaNumberU");
if( new_wa_box != null ) {
new_wa = new_wa_box.value;
}else{
new_wa_box = document.getElementById("myForm:data:" + i + ":workAreaNumber");
new_wa = new_wa_box.innerHTML;
}
alert("row new_wa_box = "+new_wa);
}
This is not a JSF problem. It’s not different from when using plain HTML. JavaScript doesn’t work with the JSF source code, but with its generated HTML output only (as you can see by rightclick and View Source in browser). Your concrete mistake is that you used
element.innerHTMLwhich returns the entire HTML content of the<td>instead of getting the<input>element from the<td>first and then itsvalueattribute.This should give you the value of the first
<input>element of the<td>, prechecks omitted for brevity:I only wonder the usefulness of doing this all in JavaScript instead of in JSF.