-----------------------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;
}
I have enabled selection mode on the datatable id="rightPnlDataTable" to select a row.To perform validation i have a button which should check, if row is selected or not, for this purpose i have written isRowSelected() function which is called on click event of "check" button. In this function i am iterating through the all rows of the datatable, but i am not sure if it's the correct condition to check if row is seleted. The given "if" condition is not working and unable to test if the row is selected or not. What could be the correct condition to check if row is selected?. I am using icefaces 3.3