Bug using LazyDataModel

Post Reply
thiago.fukunaga
Posts: 5
Joined: 10 May 2017, 22:42

10 May 2017, 22:53

Hello,

I would like to know if there is some issue about the version that I am using the primefaces with this Layout (Verona), because I am trying to render my list of register from my database by LazyDataModel.
I verified the datasource returned from my LazyDataModel and my RowCount, and it seems to be they are been set correctly. We do have another Layout and it is working fine. Thanks before hand.

LazyDataModel

Code: Select all


public class LazyPosicaoDataModel extends LazyDataModel<Posicao> implements Serializable {

	private List<Posicao> dataSource;
	private ControleJornal controleJornal;
	private FiltroPosicao filtroPosicao;
	private int first, pageSize;
	private String sortField;
	private SortOrder sortOrder;
	private Map<String, Object> filters;
	private Boolean excluiuRegistro;

	public LazyPosicaoDataModel(ControleJornal controleJornal, FiltroPosicao filtroPosicao) throws Exception {
		this.controleJornal = controleJornal;
		this.filtroPosicao = filtroPosicao;
		this.excluiuRegistro = false;
	}

	@Override
	public Posicao getRowData(String rowKey) {
		for (Posicao posicao : dataSource) {
			if (posicao.getIdPosicao().equals(rowKey)) {
				return posicao;
			}
		}
		return null;
	}

	@Override
	public Object getRowKey(Posicao posicao) {
		return posicao.getIdPosicao();
	}

	@Override
	public List<Posicao> load(int first, int pageSize, String sortField, SortOrder sortOrder,
			Map<String, Object> filters) {

		setFirst(first);
		setSortField(sortField);
		setSortOrder(sortOrder);
		setFilters(filters);
		setPageSize(pageSize);
		Integer quantidade = 0;
		try {
			dataSource = (List<Posicao>) controleJornal.posicaoBuscarDetalhadoAtivos(
					filtroPosicao.getIdPosicao(),
					filtroPosicao.getDescricao(), 
					first, 
					pageSize, 
					sortField, 
					sortOrder);

			quantidade = controleJornal.posicaoQuantidadeRegistrosDetalhadoAtivos(
					filtroPosicao.getIdPosicao(),
					filtroPosicao.getDescricao()).intValue();

		} catch (ControleException e) {
			e.printStackTrace();
		}

		if (getRowCount() <= 0 || excluiuRegistro) {
			setRowCount(quantidade);
		}
		return dataSource;
	}

	public int getFirst() {
		return first;
	}

	public void setFirst(int first) {
		this.first = first;
	}

	public int getPageSize() {
		return pageSize;
	}

	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}

	public String getSortField() {
		return sortField;
	}

	public void setSortField(String sortField) {
		this.sortField = sortField;
	}

	public SortOrder getSortOrder() {
		return sortOrder;
	}

	public void setSortOrder(SortOrder sortOrder) {
		this.sortOrder = sortOrder;
	}

	public Map<String, Object> getFilters() {
		return filters;
	}

	public void setFilters(Map<String, Object> filters) {
		this.filters = filters;
	}

	public void setExcluiuRegistro(Boolean excluiuRegistro) {
		this.excluiuRegistro = excluiuRegistro;
	}
}

page .xhtml

Code: Select all

<ui:composition 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:p="http://primefaces.org/ui" template="/WEB-INF/template.xhtml">

	<ui:define name="content">
		<h:outputScript name="jquery/jquery.js" library="primefaces"
			target="head" />
		<h:outputStylesheet library="css" name="byter.css" />
		<h:outputScript target="head">
             function chamarConfirmacao(xhr, status, args){              		
	               var excluirPosicao = args.excluirPosicao;     
	               
	               if(excluirPosicao){  
	            	   PF('confirmation').show();           
	            	}      
       		 }	  
        </h:outputScript>


		<p:separator />
		<p:fieldset legend="Posição" toggleable="false" id="fieldPainel"
			style="margin-bottom:5px;">

			<h:form>
				<p:breadCrumb>
					<p:menuitem value="Posição" />
					<p:menuitem value="Posição" />
				</p:breadCrumb>
			</h:form>
			<p:separator />

			<p:growl id="mensagens" />
			<h:form id="form">
				<p:fieldset legend="Opções de Filtro" toggleable="true"
					toggleSpeed="500" id="fieldPainel" style="margin-bottom:5px;">
					<div style="width: 100%;">
						<div style="float: left;">
							<h:panelGrid columns="4" id="painelFiltro">

								<h:panelGrid columns="1">
									<h:outputLabel value="Código" for="inputIdPosicao"
										styleClass="hardblue" />
									<p:inputText id="inputIdPosicao"
										value="#{listagemPosicaoMB.filtroPosicao.idPosicao}"
										style="width:200px;" />
									<h:inputHidden />
								</h:panelGrid>

								<h:panelGrid columns="1">
									<h:outputLabel value="Descrição" for="inputDescricao"
										styleClass="hardblue" />
									<p:inputText id="inputDescricao"
										value="#{listagemPosicaoMB.filtroPosicao.descricao}"
										style="width:200px;" />
									<h:inputHidden />
								</h:panelGrid>

							</h:panelGrid>

							<h:panelGrid columns="1">
								<h:inputHidden />
								<p:commandButton value="Buscar"
									update=":mensagens,:form2:dataTable"
									actionListener="#{listagemPosicaoMB.buscar()}"
									style="top:8px;width:100px;" />
								<h:inputHidden />
							</h:panelGrid>

							<br />

						</div>
					</div>
				</p:fieldset>
			</h:form>


			<h:form id="form2">
				<p:separator />

				<h:panelGrid style="width:100%" columns="2">
					<p:menuButton value="Adicionar" iconPos="rigth" style="float:rigth"
						menuStyleClass="menuItem230">
						<p:menuitem value="Adicionar Posição" icon="fa fa-save"
							action="#{posicaoMB.prepararIncluirRegistro()}" />
					</p:menuButton>
				</h:panelGrid>

				<p:separator />

				<p:dataTable id="dataTable" var="posicao" lazy="true"
					value="#{listagemPosicaoMB.lazyPosicaoDataModel}" paginator="true"
					paginatorPosition="bottom"
					paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
					rows="15">

					<f:facet name="header">
						<h:outputText value="Posições" />
					</f:facet>

					<p:column style="text-align:center;width:20px;" toggleable="false">
						<p:commandLink id="alterar"
							actionListener="#{posicaoMB.alterar(posicao)}" title="Alterar">
							<i class="fa fa-edit" />
						</p:commandLink>
					</p:column>

					<p:column style="text-align:center;width:20px;">
						<p:commandLink id="btnExcluir"
							actionListener="#{listagemPosicaoMB.chamarConfirmacaoExclusao(posicao)}"
							oncomplete="chamarConfirmacao(xhr, status, args)" title="Excluir">
							<i class="fa fa-trash" />
						</p:commandLink>
					</p:column>

					<p:column sortBy="#{posicao.idPosicao}"
						style="text-align:center;width:80px">
						<f:facet name="header">
							<h:outputText value="Código" style="font-size:13px"
								title="Código" />
						</f:facet>
						<h:outputText value="#{posicao.idPosicao}" style="font-size:12px" />
					</p:column>

					<p:column sortBy="#{posicao.descricao}"
						style="text-align:center;width:200px">
						<f:facet name="header">
							<h:outputText value="Descrição" style="font-size:13px" />
						</f:facet>
						<h:outputText value="#{posicao.descricao}" style="font-size:12px" />
					</p:column>

				</p:dataTable>
			</h:form>
		</p:fieldset>

		<p:confirmDialog message="Deseja excluir o registro selecionado?"
			width="330" global="true" header="Exclusão" severity="alert"
			widgetVar="confirmation">
			<h:form id="form3">
				<p:commandButton value="Sim" oncomplete="PF('confirmation').hide()"
					actionListener="#{listagemPosicaoMB.excluirRegistro}"
					update=":mensagens,:form2:dataTable" />
				<p:commandButton value="Não" onclick="PF('confirmation').hide()"
					type="button" />
			</h:form>
		</p:confirmDialog>


	</ui:define>
</ui:composition>

User avatar
aragorn
Posts: 3081
Joined: 29 Jun 2013, 12:38

11 May 2017, 11:04

Hi @tiago.fukunaga
We do have another Layout and it is working fine. Thanks before hand.
- Which layout does your example work with?

Also, which PrimeFaces version are you using?

thiago.fukunaga
Posts: 5
Joined: 10 May 2017, 22:42

11 May 2017, 14:11

I am using primefaces 6.0, and the layout that is working fine it is Sentinel.

chambersq
Posts: 2
Joined: 30 Mar 2015, 21:46

11 May 2017, 15:25

Same problem here! Using primefaces 6 and Verona Layout!

chambersq
Posts: 2
Joined: 30 Mar 2015, 21:46

11 May 2017, 19:30

H there! Same problem here!

thiago.fukunaga
Posts: 5
Joined: 10 May 2017, 22:42

13 May 2017, 18:52

Hello, I solved it, It is not problem of layout, I created the pageSize variable and set the value of it in LazyPosicaoDataModel. However, the primefaces use the pageSize from LazyDataModel which I am extending. It was just a programming error. Sorry about that!

User avatar
aragorn
Posts: 3081
Joined: 29 Jun 2013, 12:38

14 May 2017, 17:13

No problem, Thanks a lot for the update!

Post Reply

Return to “Verona - PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 1 guest