Good afternoon, I have a question about listing data in a datatable, coming from DB. I do not know how to return the DB data to the view. Follow my code so far
package br.com.racionalgames.pta.mbean;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import br.com.racionalgames.pta.dao.ListPlanilhasDao;
import br.com.racionalgames.pta.model.UploadFiles;
@ManagedBean(name = "listPlanilhas")
public class ListPlanilhasMBean implements Serializable {
private static final long serialVersionUID = 1L;
private String checkOption;
private ArrayList<UploadFiles> uploadList = new ArrayList<UploadFiles>();
@ManagedProperty(value = "#{listPlanilhaDao}")
private List<ListPlanilhasDao> listPlanilha;
public List<ListPlanilhasDao> getListPlanilha() {
return listPlanilha;
}
public void setListPlanilha(List<ListPlanilhasDao> listPlanilha) {
this.listPlanilha = listPlanilha;
}
public ArrayList<UploadFiles> getUploadList() {
return uploadList;
}
public void setUploadList(ArrayList<UploadFiles> uploadList) {
this.uploadList = uploadList;
}
public ListPlanilhasMBean() {
}
public String getCheckOption() {
return checkOption;
}
public void setCheckOption(String checkOption) {
this.checkOption = checkOption;
}
public List<UploadFiles> getListPlanilha(UploadFiles upload) {
List<UploadFiles> list = null;
try {
list = ((ListPlanilhasDao) listPlanilha).getListPlanilha(upload);
} catch (Exception e) {
e.printStackTrace();
}
return list;
}
}
/ DAO /
package br.com.racionalgames.pta.dao;
import java.util.ArrayList;
import java.util.List;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import org.springframework.transaction.annotation.Transactional;
import br.com.racionalgames.pta.model.UploadFiles;
@Repository("ListPlanilhasDao")
@Transactional
@EnableTransactionManagement
public class ListPlanilhasDaoImpl implements ListPlanilhasDao {
private static final long serialVersionUID = 1L;
private UploadFiles listPlanilha = new UploadFiles();
public UploadFiles getUpload() {
return listPlanilha;
}
public void setUpload(UploadFiles listPlanilha) {
this.listPlanilha = listPlanilha;
}
@Override
public List<UploadFiles> getListPlanilha(UploadFiles a) throws Exception {
String sql = "SELECT * FROM pta.criterios_multiskill";
List<UploadFiles> list = new ArrayList<UploadFiles>();
list = (List<UploadFiles>) sessionFactory.getCurrentSession().createSQLQuery(sql).list();
return list;
}
@Autowired
private SessionFactory sessionFactory;
public SessionFactory getSessionFactory() {
return sessionFactory;
}
public void setSessionFactory(SessionFactory sessionFactory) {
this.sessionFactory = sessionFactory;
}
}
/ VIEW /
<!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:ui="http://java.sun.com/jsf/facelets"
xmlns:p="http://primefaces.org/ui"
xmlns:f="http://xmlns.jcp.org/jsf/core">
<ui:composition template="/WEB-INF/inc/template.xhtml">
<ui:define name="titulo">
<h:outputText value=" - Home" />
</ui:define>
<ui:define name="conteudo">
<div class='wrp-content'>
<h:form style="margin-top: 100px">
<p:selectOneMenu style="width: 30%" id="planilha" effect="fold"
editable="false" value="">
<f:selectItem id="multiSkill" value="#{listPlanilhas.checkOption}"
itemLabel="Critérios Cadastro MultiSkill" />
<f:selectItem id="compUsuario" value="#{listPlanilhas.checkOption}"
itemLabel="Publicação Complemento Usuário" />
</p:selectOneMenu>
<br />
<br />
<p:dataTable emptyMessage="Não existem valores para exibição"
var="lista" value="#{listPlanilhas.uploadList}" paginator="true"
rows="10" rowsPerPageTemplate="5, 10, 20">
<p:column headerText="ID">
<h:outputText value="#{listPlanilhas.listPlanilha.id}" />
</p:column>
<p:column headerText="Documento">
<h:outputText value="#{listPlanilhas.listPlanilha}" />
</p:column>
<p:column headerText="Nome">
<h:outputText value="#{listPlanilhas.listPlanilha}" />
</p:column>
<p:column headerText="Empresa Cliente">
<h:outputText value="#{listPlanilhas.listPlanilha}" />
</p:column>
<p:column headerText="Empresa Assessoria">
<h:outputText value="#{listPlanilhas.listPlanilha}" />
</p:column>
<p:column headerText="Carteira">
<h:outputText value="#{listPlanilhas.listPlanilha}" />
</p:column>
<p:column headerText="Produto">
<h:outputText value="#{listPlanilhas.listPlanilha}" />
</p:column>
<p:column headerText="Tipo Operação">
<h:outputText value="#{listPlanilhas.listPlanilha}" />
</p:column>
<p:column headerText="Grupo">
<h:outputText value="#{listPlanilhas.listPlanilha}" />
</p:column>
<p:column headerText="Ação">
<h:outputText value="#{listPlanilhas.listPlanilha}" />
</p:column>
<p:column headerText="Data Inclusão">
<h:outputText value="#{listPlanilhas.listPlanilha}" />
</p:column>
</p:dataTable>
</h:form>
</div>
</ui:define>
</ui:composition>
</html>