如果选择了<ace:datatable>行,如何使用javascript或jquery进行检查

时间:2015-10-08 14:12:13

标签: javascript jquery icefaces-3

    -----------------------rowSelector.xhtml---------------------------------------
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

    <html xmlns="http://www.w3.org/1999/xhtml"
        xmlns:h="http://java.sun.com/jsf/html"
        xmlns:f="http://java.sun.com/jsf/core"
        xmlns:ui="http://java.sun.com/jsf/facelets"
        xmlns:mj="http://mojarra.dev.java.net/mojarra_ext"
        xmlns:ice="http://www.icesoft.com/icefaces/component"
        xmlns:ace="http://www.icefaces.org/icefaces/components"
        xmlns:icecore="http://www.icefaces.org/icefaces/core">

    <h:head>

        <h:outputScript library="js" name="validation.js" target="body" />

    </h:head>

    <h:body>

        <h1>IceFaces 3 </h1>

        <h:form id="docForm">

         <ace:dataTable id="rightPnlDataTable"
                                    styleClass="RightPanelDatatable"
                                    value="#{docMain.resultList}"
                                    emptyMessage="There are no search results" 
                                    var="doc" scrollable="true"
                                    selectionMode="single"
                                    rowSelectListener="#{docList.selectRowListener}">

                            <ace:column id="Num" headerText="Number">
                                <h:outputText value="#{doc.Num}" />
                            </ace:column>

                            <ace:column id="Dt" headerText="Date">
                                <h:outputText value="#{doc.Date}" />
                            </ace:column>

                            <ace:column id="origLoc" headerText="Origin Location">
                                <h:outputText value="#{doc.originStation}" />
                            </ace:column>

                            <ace:column id="destLoc" headerText="Destination Location" >
                                <h:outputText value="#{doc.destStation}" />
                            </ace:column>

                            <ace:column id="origCntry" headerText="Origin Country">
                                <h:outputText value="#{doc.originCountry}" />
                            </ace:column>

                            <ace:column id="destCntry" headerText="Destination Country">
                                <h:outputText value="#{doc.destCountry}" />
                            </ace:column>

                        </ace:dataTable>

            <br/><br/>
            <ice:commandButton value="Check" onclick="return isRowSelected();" action="#{orderBean.saveAction}" />

        </h:form>
    </h:body>
    </html>

----------------------------------validation.js------------------------------   

 function isRowSelected() { 

    var flag = true;

    ice.ace.jq('#docForm\\:rightPnlDataTable table tbody tr').each(function() {

        if (ice.ace.jq(this).hasClass('ui-state-active ui-selected')) {
            return false;
        } else {
            flag = false;
        }
    });

    if(flag==false){
        alert("Please select one row");
        return false;
    }

    return true;

 }

我已在数据表上启用了选择模式id =&#34; rightPnlDataTable&#34;为了执行验证我有一个应该检查的按钮,如果选择了行,为此目的,我已经编写了isRowSelected()函数,该函数在&#34; check&#34;的点击事件中被调用。按钮。在这个函数中,我遍历数据表的所有行,但我不确定它是否是检查行是否被选中的正确条件。给定的&#34; if&#34;条件不起作用,无法测试是否选择了行。检查行是否被选中的正确条件是什么?我正在使用icefaces 3.3

0 个答案:

没有答案