I have some javascript code (that I borrowed from BalusC) that is used to make sure only one h:selectOneRadio button is selected in a table. Unfortunately I’m getting an malformed expression error from my glassfish server:
Error Parsing /ClientSearch.xhtml: Error Traced[line: 13] The content of elements must consist of well-formed character data or markup.
Note:
if (elements[i].name.substring(elements[i].name.lastIndexOf(':')) == id) {
seems to be the line with the problems
I also don’t fully understand the javascript (I’m a newbie at it) and I’m hoping someone could explain it to me.
Here is the full javascript:
function dataTableSelectOneRadio(radio) {
var id = radio.name.substring(radio.name.lastIndexOf(':'));
var elements = radio.form.elements;
for (var i = 0; i < elements.length; i++) {
if (elements[i].name.substring(elements[i].name.lastIndexOf(':')) == id) {
elements[i].checked = false;
}
}
radio.checked = true;
}
</script>
Why am I getting the error?
And, the script itself seems wrong. Shouldn’t the code be if NOT equal to id then false (as below).
if (elements[i].name.substring(elements[i].name.lastIndexOf(':')) != id) {
elements[i].checked = false;
}
Obviously I don’t understand.
And here is the facelets code for the table:
Clients
<h:column headerText="First Name" >
<f:facet name="header"><h:outputText value="First Name" /></f:facet>
#{client.firstName}
</h:column>
<h:column headerText="Last Name" >
<f:facet name="header"><h:outputText value="Last Name" /></f:facet>
#{client.lastName}
</h:column>
<h:column headerText="Select" >
<f:facet name="header"><h:outputText value="Last Name" /></f:facet>
<h:selectOneRadio valueChangeListener="#{clientSearchBean.setSelectedItem}" >
<f:selectItem itemValue="null" />
</h:selectOneRadio>
</h:column>
<h:column headerText="Address" >
<f:facet name="header"><h:outputText value="Address" /></f:facet>
#{client.address}
</h:column>
<h:column headerText="Cell" >
<f:facet name="header"><h:outputText value="Cell" /></f:facet>
#{client.cell}
</h:column>
<h:column headerText="Phone" >
<f:facet name="header"><h:outputText value="Phone" /></f:facet>
#{client.phone}
</h:column>
</h:dataTable>
I’ve tried (and I’m using) the BalusC code in a
<h:dataTable>and works neat. You have two problems:You’re not using the JavaScript function at all (or that looks in your code):
Your JavaScript code has the
<symbol. Facelets is very strict with this symbol usage. To make it work, you should use the XML CDATA usage in Script and Style elements: