Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8455709
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T12:21:12+00:00 2026-06-10T12:21:12+00:00

I have some javascript code (that I borrowed from BalusC) that is used to

  • 0

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>      
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T12:21:14+00:00Added an answer on June 10, 2026 at 12:21 pm

    I’ve tried (and I’m using) the BalusC code in a <h:dataTable> and works neat. You have two problems:

    1. You’re not using the JavaScript function at all (or that looks in your code):

      <h:column headerText="Select">
          <f:facet name="header">
              <h:outputText value="Last Name" />
          </f:facet>
          <!-- you forgot to add the onclick -->
          <h:selectOneRadio valueChangeListener="#{clientSearchBean.setSelectedItem}"
              onclick="dataTableSelectOneRadio(this);">
              <f:selectItem itemValue="null" />
          </h:selectOneRadio>
      </h:column>
      
    2. 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:

      <script type="text/javascript">
      //the CDATA must be used with JavaScript comments
      //<![CDATA[
          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>
      
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some Javascript code that creates 2 arrays: One for Product Category and
I have some javascript and c# code inside one of my views that is
I have some code that dynamically creates a new button through JavaScript that when
I have some JavaScript code that is written in one line (no carriage returns),
I have some javascript code that is used in a few different pages in
I have written some JavaScript and jQuery code that accepts only numeric input in
I have some jQuery/JavaScript code that I want to run only when there is
I have written some JavaScript code that will read from the Google Maps API
I have some Javascript code that will programmatically register an COM interop assembly by
I have some JavaScript code that works in IE containing the following: myElement.innerText =

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.