Olá Pessoal,
Na minha aplicação existem tabelas que são atualizadas por rotinas(store procedure do mysql e/ou sqlserver) externas de outro sistema. Essas rotinas atualizam os registros direto no banco de dados. Quando é efetuada essa atualização no banco de dados as informações demoram(as vezes até horas) para aparecer a informação atualizada no Datatable e em outras telas do sistema. Para atualizar rapidamente somente parando o glassfish e iniciando novamente. Segue abaixo meus códigos.
Meu controller
package br.com.faces.logistica;
import br.com.ejb.BaseCDIBean;
import br.com.entidades.logistica.Deposito;
import br.com.faces.comercial.ExcRepositorio;
import br.com.faces.seguranca.UsuarioFace;
import br.com.session.basico.EmpresaSession;
import br.com.session.logistica.DepositoSession;
import br.com.util.RelatorioUtil;
import br.com.util.ValidaAcesso;
import java.util.ArrayList;
import java.util.List;
import javax.enterprise.context.SessionScoped;
import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;
import javax.inject.Inject;
import javax.inject.Named;
import org.primefaces.model.StreamedContent;
@Named
@SessionScoped
public class DepositoFace extends BaseCDIBean<Deposito> {
private static final long serialVersionUID = 7L;
@Inject
private DepositoSession bean;
@Inject
private EmpresaSession empresaSession;
@Inject
private UsuarioFace usuarioFace;
@Inject
private ValidaAcesso validaAcesso;
private List<Deposito> list;
private Deposito deposito;
private Deposito novoRegistro = null;
private Deposito selectedLinha;
private String cFocus = "idCodigo";
private String cInativo = "N";
private Integer idUsrValido = null;
private List<Deposito> ls = new ArrayList<Deposito>();
public DepositoFace() {
setSelectedBean(new Deposito());
}
public void doValidaUsr() {
if (!idUsrValido.equals(usuarioFace.getLoggedUser().getId()) || idUsrValido == null) {
usuarioFace.doLogOut();
}
}
public String doCreate() {
setSelectedBean(new Deposito());
if (validaAcesso.validaUsrUrl("/views/logistica/cadastros/deposito/add.faces")) {
return "/views/logistica/cadastros/deposito/add.faces?faces-redirect=true";
} else {
return "/erro.faces";
}
}
public String doFinishCreate(String empresa) {
getSelectedBean().setEmpresa(empresaSession.getEmpresaByCodigo(empresa));
novoRegistro = null;
try {
novoRegistro = bean.getByCodigo(getSelectedBean().getEmpresa().getId(), getSelectedBean().getCodigo());
} catch (Exception e) {
bean.save(getSelectedBean());
setList(null);
return doList();
}
FacesMessage fm = new FacesMessage(FacesMessage.SEVERITY_ERROR,"Registro já existe.","Registro já existe.");
FacesContext.getCurrentInstance().addMessage("Registro já existe.", fm);
return null;
}
public String doEdit() {
doValidaUsr();
setSelectedBean(selectedLinha);
if (validaAcesso.validaUsrUrl("/views/logistica/cadastros/deposito/edit.faces")) {
return "/views/logistica/cadastros/deposito/edit.faces?faces-redirect=true";
} else {
return "/erro.faces";
}
}
public String doFinishEdit() {
bean.set(getSelectedBean());
setList(null);
return doList();
}
public String doRemove() {
try {
setSelectedBean(selectedLinha);
bean.remove(getSelectedBean());
setList(null);
return doList();
} catch (Exception e) {
FacesMessage fm = new FacesMessage(FacesMessage.SEVERITY_ERROR,"Registro possui relacionamentos ativo.","Registro possui relacionamentos ativo.");
FacesContext.getCurrentInstance().addMessage("Registro possui relacionamentos ativo.", fm);
return null;
}
}
public String doList() {
list = bean.getAll(usuarioFace.getLoggedUser().getEmpresa().getId());
return "/views/logistica/cadastros/deposito/list.faces?faces-redirect=true";
}
public void setDeposito(Deposito deposito) {
this.deposito = deposito;
}
public List<Deposito> getList() {
if (idUsrValido == null) {
idUsrValido = usuarioFace.getLoggedUser().getId();
list = bean.getAll(usuarioFace.getLoggedUser().getEmpresa().getId());
} else if (!idUsrValido.equals(usuarioFace.getLoggedUser().getId())) {
usuarioFace.doLogOut();
}
else if (list == null) {
list = bean.getAll(usuarioFace.getLoggedUser().getEmpresa().getId());
idUsrValido = usuarioFace.getLoggedUser().getId();
}
return list;
}
public void setList(List<Deposito> list) {
this.list = list;
}
public List<Deposito> completeDeposito(String prefix){
ls = bean.getAllDepositoComplete(usuarioFace.getLoggedUser().getEmpresa().getId(), prefix);
System.out.println(ls);
return ls;
}
public Deposito getNovoRegistro() {
doValidaUsr();
return novoRegistro;
}
public void setNovoRegistro(Deposito novoRegistro) {
this.novoRegistro = novoRegistro;
}
public Deposito getSelectedLinha() {
doValidaUsr();
return selectedLinha;
}
public void setSelectedLinha(Deposito selectedLinha) {
this.selectedLinha = selectedLinha;
}
public String getcCodIni() {
return cCodIni;
}
public void setcCodIni(String cCodIni) {
this.cCodIni = cCodIni;
}
public String getcCodFin() {
return cCodFin;
}
public void setcCodFin(String cCodFin) {
this.cCodFin = cCodFin;
}
}
Minha view
<?xml version='1.0' encoding='ISO-8859-1' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns:c="http://java.sun.com/jsp/jstl/core">
<ui:composition xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:p="http://primefaces.org/ui"
template="#{pageContext.servletContext.contextPath}/templates/padraoTemplate.xhtml"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html">
<ui:define name="conteudo">
<f:view contentType="text/html; charset=ISO-8859-1">
<h:body>
<h:panelGrid columns="1" style="width: 100%;" >
<p:ajaxStatus onstart="statusDialog.show();" onsuccess="statusDialog.hide();"/>
<p:dialog modal="true" widgetVar="statusDialog" header="Processando..." draggable="false" closable="false" resizable="false">
<p:graphicImage value="#{pageContext.servletContext.contextPath}/resources/imagens/bar180.gif" />
</p:dialog>
<script type="text/javascript">
function startMessage() {
statusDialog.show();
}
function finishMessage() {
statusDialog.hide();
}
</script>
<h:form>
<div class="left">
<table>
<tr>
<c:if test="#{validaAcesso.validaAcesso('/views/logistica/cadastros/deposito/list.faces', 'I')}">
<td width="40px">
<p:commandLink title="Incluir registro" action="#{depositoFace.doCreate()}" id="bt_nova" ajax="false" onclick="PrimeFaces.monitorDownload(startMessage, finishMessage)">
<p:graphicImage title="Novo registro" value="#{pageContext.servletContext.contextPath}/resources/imagens/incluir.png" width="25" height="25" alt="Novo registro"/>
</p:commandLink>
</td>
</c:if>
<c:if test="#{validaAcesso.validaAcesso('/views/logistica/cadastros/deposito/list.faces', 'C')}">
<td width="40px">
<p:commandLink title="Relatório" action="#{depositoFace.doFilter()}" id="bt_print" ajax="false" onclick="PrimeFaces.monitorDownload(startMessage, finishMessage)">
<p:graphicImage value="#{pageContext.servletContext.contextPath}/resources/imagens/print.png" width="25" height="25" alt="Relatório"/>
</p:commandLink>
</td>
</c:if>
<td width="400px">
<p:messages id="messages" autoUpdate="true" closable="true" />
</td>
</tr>
</table>
</div>
<div class="right">
<table>
<tr>
<td >
<h:outputLink id="idHelp" value="#{pageContext.servletContext.contextPath}/views/logistica/cadastros/deposito/help.html" target="_blank" title="Ajuda">
<p:graphicImage title="Ajuda" value="#{pageContext.servletContext.contextPath}/resources/imagens/help.png" width="25" height="25" alt="Ajuda"/>
</h:outputLink>
</td>
</tr>
</table>
</div>
<div class="home left">
<p:dataTable id="tbl" var="item" value="#{depositoFace.list}"
paginator="true" rows="10" paginatorPosition="top"
paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks}
{NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
currentPageReportTemplate="[ Exibindo registros de {startRecord} a {endRecord} no total de {totalRecords}
- Página: {currentPage}/{totalPages} ]"
emptyMessage="Não há registros a exibir"
rowStyleClass="#{empty rowIx or rowIx mod 2 ne 0 ? 'even-row' : 'odd-row'}"
rowIndexVar="rowIx"
style="font-size: 10px; background-color: lightblue">
<f:facet name="header">
Depósitos
</f:facet>
<p:column sortBy="#{item.codigo}" filterBy="#{item.codigo}" filterStyle="max-width: 70px; min-width: 70px; overflow:hidden" style="max-width: 60px; min-width: 60px; overflow:hidden">
<f:facet name="header">
<h:outputText value="Código"/>
</f:facet>
<h:outputText value="#{item.codigo}"/>
</p:column>
<p:column sortBy="#{item.descricao}" filterBy="#{item.descricao}">
<f:facet name="header">
<h:outputText value="Descrição"/>
</f:facet>
<h:outputText value="#{item.descricao}"/>
</p:column>
<p:column style="max-width: 110px; min-width: 40px; overflow: hidden; text-align: center">
<f:facet name="header">
<h:outputText value="Ação"/>
</f:facet>
<c:if test="#{validaAcesso.validaAcesso('/views/logistica/cadastros/deposito/list.faces', 'E')}">
<p:commandLink title="Editar registro" action="#{depositoFace.doEdit()}" id="bt_editar" ajax="false" onclick="PrimeFaces.monitorDownload(startMessage, finishMessage)">
<p:graphicImage title="Editar registro" value="#{pageContext.servletContext.contextPath}/resources/imagens/editar.png" width="20" height="20" alt="Editar registro" />
<f:setPropertyActionListener target="#{depositoFace.selectedLinha}" value="#{item}"/>
</p:commandLink>
</c:if>
<c:if test="#{validaAcesso.validaAcesso('/views/logistica/cadastros/deposito/list.faces', 'C')}">
<p:commandLink title="Consultar registro" action="#{depositoFace.doView()}" id="bt_view" ajax="false" onclick="PrimeFaces.monitorDownload(startMessage, finishMessage)">
<p:graphicImage title="Consultar registro" value="#{pageContext.servletContext.contextPath}/resources/imagens/detalhar.png" width="20" height="20" alt="Consultar registro" />
<f:setPropertyActionListener target="#{depositoFace.selectedLinha}" value="#{item}"/>
</p:commandLink>
</c:if>
<c:if test="#{validaAcesso.validaAcesso('/views/logistica/cadastros/deposito/list.faces', 'R')}">
<h:commandLink title="Remover registro" action="#{depositoFace.doRemove()}" id="bt_excluir" onclick="return confirm('Confirme eliminação ?');">
<p:graphicImage title="Remover registro" value="#{pageContext.servletContext.contextPath}/resources/imagens/excluir.png" width="20" height="20" alt="Remover registro" />
<f:setPropertyActionListener target="#{depositoFace.selectedLinha}" value="#{item}"/>
</h:commandLink>
</c:if>
</p:column>
</p:dataTable>
</div>
</h:form>
</h:panelGrid>
</h:body>
</f:view>
</ui:define>
</ui:composition>
</html>