简体   繁体   中英

JSF DataTable Select One Row Using Radio Button

I am using JSF 1.1 and I have a ice:datatable with rows getting fetched from backing bean. To select the row for editing I have a radio button for that row. When I select the row using the radio button I am getting the following error.

radio.name is undefined

In my page I am calling the javascript as follows

<h:selectOneRadio styleClass="none" valueChangeListener="#{bean.setSelectedItem}"
                onclick="dataTableSelectOneRadio(this);">
                <f:selectItem itemValue="null" />
            </h:selectOneRadio>

Any my javascript function

function dataTableSelectOneRadio(radio) {
    var id = radio.name.substring(radio.name.lastIndexOf(':'));
    var el = radio.form.elements;
    for (var i = 0; i < el.length; i++) {
        if (el[i].name.substring(el[i].name.lastIndexOf(':')) == id) {
            el[i].checked = false;
        }
    }
    radio.checked = true;
}

How can I resolve this error?

Thanks

Apparently IceFaces doesn't generate name attribute for the radio button or doesn't put onclick on the generated <input type="radio"> element. Try using id instead. Replace radio.name in JavaScript code by radio.id . If in vain, you need to check the generated HTML output (open page in browser, rightclick and View Source ) and alter the JS code accordingly.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM