Pessoal estou usando RichFaces com netbeans para montar uma dataTable , mas não estou conseguindo re-indexar os dados dessa tabela ordenando pela coluna que desejo, ou seja, quando clico no “cabeçalho” da coluna, quero que seja ordenado por ela, alguém pode me ajudar? Abaixo a minha classe bean:
<%@ taglib prefix="f" uri="http://java.sun.com/jsf/core" %>
<%@ taglib prefix="h" uri="http://java.sun.com/jsf/html" %>
<%@ taglib uri="http://richfaces.ajax4jsf.org/rich" prefix="rich"%>
<%@ taglib uri="http://richfaces.org/a4j" prefix="a4j"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<f:view>
<html>
<head>
<title>Campanha</title>
<style type="text/css">
<!--
body {
margin-left: 0px;
margin-top: 0px;
margin-right: 0px;
margin-bottom: 0px;
}
-->
</style>
<link href="../css/folha.css" rel="stylesheet" type="text/css" />
</head>
<body>
<h:form>
<table width="780" align="center" cellpadding="0" cellspacing="0" border="0">
<tr>
<th width="170" rowspan="2" valign="top" scope="col"><img src="../imagens/topo_logo.jpg" width="170" height="190" /></th>
<th width="610" height="57" colspan="2" valign="top" background="../imagens/topo.jpg" scope="col"><table width="100%" height="55" border="0" cellpadding="0" cellspacing="0">
<tr>
<th height="19" scope="col"> </th>
<th scope="col"> </th>
<th scope="col"> </th>
</tr>
<tr>
<th colspan="3" scope="row"> </th>
</tr>
</table>
</th>
</tr>
<tr>
<td colspan="2" valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="0" class="fonte">
<tr>
<td colspan="3" class="fonte_titulo"><div align="center">Detalhes da Obra</div></td>
</tr>
<tr>
<td colspan="3" class="fonte"> </td>
</tr>
<tr>
<td colspan="3" class="fonte"></td>
</tr>
<tr>
<td width="2%" height="25"> </td>
<td width="96%" height="19"><a4j:form id="form1"
reRender="list-body" ajaxSubmit="true" ignoreDupResponses="true"
requestDelay="500">
<a4j:region id="stat1">
<a4j:outputPanel id="list-body">
<rich:dataTable width="300" id="carList" rows="10"
value="#{detalhaVotacaoBean.votacao}" var="votacao">
<f:facet name="header">
<rich:columnGroup>
<h:column>
<a4j:commandLink actionListener="#{detalhaVotacaoBean.votacao}"
reRender="carList">
<h:outputText styleClass="headerText" value="#{detalhaVotacaoBean.ordenacao}" />
<f:attribute name="filterRule" value="showTable"/>
</a4j:commandLink>
</h:column>
<h:column>
<h:outputText styleClass="headerText" value="Candidato" />
</h:column>
<h:column>
<h:outputText styleClass="headerText" value="Zona" />
</h:column>
<h:column>
<h:outputText styleClass="headerText" value="Bairro" />
</h:column>
<h:column>
<h:outputText styleClass="headerText" value="Votos" />
</h:column>
</rich:columnGroup>
</f:facet>
<h:column>
<h:outputText value="#{votacao.nm_vila_jardim}" />
</h:column>
<h:column>
<h:outputText value="#{votacao.nm_pessoa}" />
</h:column>
<h:column>
<h:outputText value="#{votacao.nm_bairro}" />
</h:column>
<h:column>
<h:outputText value="#{votacao.nr_zona}" />
</h:column>
<h:column>
<h:outputText value="#{votacao.vl_votacao_candidato}" />
</h:column>
</rich:dataTable>
</a4j:outputPanel>
<rich:spacer height="15" />
</a4j:region>
</a4j:form>
</td>
<td width="2%"> </td>
</tr>
<tr>
<td height="19" colspan="3"> </td>
</tr>
<tr>
<td colspan="3" class="fonte"><div align="center"> <a href="../principal/principal.jsp"><img src="../imagens/seta_voltar.jpg" width="9" height="7" border="0" /></a> <a href="../principal/principal.jsp">Voltar</a></div></td>
</tr>
<tr>
<td colspan="3" class="fonte"> </td>
</tr>
</table>
</td>
</tr>
</table>
</h:form>
</body>
</html>
</f:view>
e aqui está o meu bean:
package br.com.dnasolution.bean;
import br.com.dnasolution.db.Conexao;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.Collection;
import javax.servlet.jsp.jstl.sql.Result;
import javax.servlet.jsp.jstl.sql.ResultSupport;
/**
*
* @author Administrador
*/
public class DetalhaVotacaoBean {
/** Creates a new instance of detalhaVotacaoBean */
public DetalhaVotacaoBean() {
ordenacao = "nm_pessoa";
}
private String ordenacao = null;
public Result getVotacao() {
Collection toReturn = new ArrayList();
ResultSet rs = null;
try {
Connection conexao = Conexao.getInstancia().conectarDb();
PreparedStatement st = conexao.prepareStatement("SELECT tb_pessoa.nm_pessoa, tb_bairro.nm_bairro, tb_zona.nr_zona, tb_vila_jardim_bairro.nm_vila_jardim, vl_votacao_candidato FROM tb_votacao JOIN tb_pessoa ON tb_pessoa.cd_pessoa = tb_votacao.cd_pessoa JOIN tb_vila_jardim_bairro ON tb_vila_jardim_bairro.cd_vila_jardim = tb_votacao.cd_vila_jardim JOIN tb_bairro ON tb_bairro.cd_bairro = tb_vila_jardim_bairro.cd_bairro JOIN tb_zona ON tb_zona.cd_zona = tb_bairro.cd_zona ORDER BY ?");
st.setString(1, ordenacao);
rs = st.executeQuery();
} catch (Exception e) {
System.out.println(e.getMessage());
}
return ResultSupport.toResult(rs);
}
public void setOrdenacao(String ordenacao) {
this.ordenacao = ordenacao;
}
public String getOrdenacao() {
return ordenacao;
}
}
Alguém tem alguma idéia?
Agradeço!