Olá, estou tentando utilizar o datatables do Primefaces, mas tenho dificuldades em entender porque ocorre várias chamadas no get que constrói a tabela e como corrigir isso.
view:
<h:form>
<p:panel>
<p:dataTable value="#{datasbean.todasasdatas}" var="d" editable="true" id="tabeladatas"
emptyMessage="Não há datas Cadastradas">
<f:facet name="header">
Lista de Datas
</f:facet>
<p:ajax event="rowEditInit" listener="#{datasbean.iniciaredicao}"/>
<p:ajax event="rowEdit" listener="#{datasbean.alterar}" update=":form1:messages" />
<p:ajax event="rowEditCancel" listener="#{datasbean.cancelar}" update=":form1:messages" />
<p:column>
<f:facet name="header">
<h:outputText value="Ano" />
</f:facet>
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{d.tbano.ano}" />
</f:facet>
<f:facet name="input">
<p:inputText value="#{datasbean.tbano.ano}" style="width:100%"/>
</f:facet>
</p:cellEditor>
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="Descrição" />
</f:facet>
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{d.descricao}" />
</f:facet>
<f:facet name="input">
<p:inputText value="#{datasbean.dtdescricao}" style="width:100%"/>
</f:facet>
</p:cellEditor>
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="Inicio" />
</f:facet>
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{d.datainicio.time}">
<f:convertDateTime pattern="dd/MM/yyyy HH:mm:ss" timeZone="GMT-03:00"/>
</h:outputText>
</f:facet>
<f:facet name="input">
<p:calendar id="datainicio" value="#{datasbean.datainicio}" pattern="dd/MM/yyyy HH:mm:ss" timeZone="GMT-03:00"/>
</f:facet>
</p:cellEditor>
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="Termino" />
</f:facet>
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{d.datafim.time}">
<f:convertDateTime pattern="dd/MM/yyyy HH:mm:ss" timeZone="GMT-03:00"/>
</h:outputText>
</f:facet>
<f:facet name="input">
<p:calendar id="datafim" value="#{datasbean.datafim}" pattern="dd/MM/yyyy HH:mm:ss" timeZone="GMT-03:00"/>
</f:facet>
</p:cellEditor>
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="Tipo" />
</f:facet>
<p:cellEditor>
<f:facet name="output"><h:outputText value="#{d.tbtipo.descricao}" /></f:facet>
<f:facet name="input">
<h:selectOneMenu value="#{datasbean.tbtipo.id}" style="width:100%">
<f:selectItems value="#{datasbean.listatipos}" var="tipo" itemLabel="#{tipo.descricao}" itemValue="#{tipo.id}" />
</h:selectOneMenu>
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="Editar" style="width:70px">
<p:rowEditor/>
</p:column>
<p:column headerText="Remover" style="width:70px">
<p:commandLink styleClass="ui-icon ui-icon-trash" action="#{datasbean.remover}" value="Remover" update="tabeladatas">
<f:setPropertyActionListener target="#{datasbean.tbdata}" value="#{d}" />
</p:commandLink>
</p:column>
</p:dataTable>
</p:panel>
</h:form>
MB:
@ManagedBean(name="datasbean")
@ViewScoped
public class CalendarioBean implements Serializable{
/** omitido **/
private List<Tbdata> todasasdatas;
/** omitido **/
public List<Tbdata> getTodasasdatas() {
return new TbdataDaoImpl().listarDatas();
}
public void setTodasasdatas(List<Tbdata> todasasdatas) {
this.todasasdatas = todasasdatas;
}
/** omitido **/
Quando aciono a edição de uma linha da tabela o método "getTodasasdatas "que constrói a tabela é chamado diversas vezes . Isso é normal ? Ou existe alguma configuração que falta adicionar?
Obrigado.