I'm having trouble with AJAX prime, is as follows:
Every time we use a feature of prime it generates the following error:
Code: Select all
javax.faces.FacesException: Unexpected error restoring state for component with id j_idt3. Cause: java.lang.IndexOutOfBoundsException: Index: 0, Size: 0.
at com.sun.faces.application.view.StateManagementStrategyImpl$1.visit(StateManagementStrategyImpl.java:273)
at com.sun.faces.component.visit.FullVisitContext.invokeVisitCallback(FullVisitContext.java:151)
at javax.faces.component.UIComponent.visitTree(UIComponent.java:1485)
at javax.faces.component.UIComponent.visitTree(UIComponent.java:1496)
at com.sun.faces.component.visit.VisitUtils.doFullNonIteratingVisit(VisitUtils.java:75)
at com.sun.faces.application.view.StateManagementStrategyImpl.restoreView(StateManagementStrategyImpl.java:257)
at com.sun.faces.application.StateManagerImpl.restoreView(StateManagerImpl.java:181)
at com.sun.faces.application.view.ViewHandlingStrategy.restoreView(ViewHandlingStrategy.java:123)
at com.sun.faces.application.view.FaceletViewHandlingStrategy.restoreView(FaceletViewHandlingStrategy.java:448)
at com.sun.faces.application.view.MultiViewHandler.restoreView(MultiViewHandler.java:148)
at com.sun.faces.lifecycle.RestoreViewPhase.execute(RestoreViewPhase.java:187)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
at com.sun.faces.lifecycle.RestoreViewPhase.doPhase(RestoreViewPhase.java:111)
at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:312)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:306)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:240)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:161)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:164)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:541)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:383)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:243)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:188)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:288)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
at java.util.ArrayList.RangeCheck(Unknown Source)
at java.util.ArrayList.get(Unknown Source)
at javax.faces.component.AttachedObjectListHolder.restoreState(AttachedObjectListHolder.java:165)
at javax.faces.component.UIComponentBase.restoreState(UIComponentBase.java:1432)
at com.sun.faces.application.view.StateManagementStrategyImpl$1.visit(StateManagementStrategyImpl.java:265)
... 29 more
First example
When using op: commandLink (Prime) instead of h: commandLink (JSF) generates this error.
Second example
By clicking on the prime line of the DataTable and call a dialog also generates this error
my code
cadastroCliente.xhml
Code: Select all
<?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="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:p="http://primefaces.prime.com.tr/ui"
xmlns:f="http://java.sun.com/jsf/core">
<h:head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<title>Cadastro de Clientes</title>
</h:head>
<f:view>
<h:body>
<h:form id="frmGridCliente">
<p:growl id="menssagensCliente"
life="3000"/>
<p:dataTable widgetVar="dtClientes"
var="cliente"
value="#{mbCliente.clientes}"
paginator="true"
rows="5"
selection="#{mbCliente.cliente}"
selectionMode="single"
onselectComplete="dlgCliente.show();"
emptyMessage="Nao existe Cliente cadastrado"
style="width:70%"
update="frmCadastroCliente">
<p:column sortBy="#{cliente.id}"
filterBy="#{cliente.id}"
style="width:20%">
<f:facet name="header">
<h:outputText value="Id" />
</f:facet>
<h:outputText value="#{cliente.id}" />
</p:column>
<p:column sortBy="#{cliente.nome}"
filterBy="#{cliente.nome}">
<f:facet name="header">
<h:outputText value="Nome" />
</f:facet>
<h:outputText value="#{cliente.nome}" />
</p:column>
<p:column sortBy="#{cliente.cnpj}"
filterBy="#{cliente.cnpj}">
<f:facet name="header">
<h:outputText value="Cnpj" />
</f:facet>
<h:outputText value="#{cliente.cnpj}" />
</p:column>
</p:dataTable>
<p:panel style="width:69.2%">
<p:commandLink title="Novo"
oncomplete="dlgCliente.show();"
action="#{mbCliente.incluir}"
update="frmCadastroCliente">
<h:graphicImage url="/imagens/novo.jpg"
style="border:0"/>
</p:commandLink>
<h:commandLink title="Apagar"
actionListener="#{mbCliente.apagar}"
style="margin-left:20px"
update="frmGridCliente">
<p:graphicImage url="/imagens/apagar.jpg"
style="border:0"/>
</h:commandLink>
<h:commandLink title="Voltar"
action="#{mbCliente.voltar}"
ajax="false"
style="margin-left:20px">
<h:graphicImage url="/imagens/voltar.jpg"
style="border:0"/>
</h:commandLink>
</p:panel>
</h:form>
<h:form id="frmCadastroCliente">
<p:dialog id="dlgCliente"
widgetVar="dlgCliente"
header="Cliente"
width="500">
<h:panelGrid columns="2" id="pnl" >
<h:outputLabel value="Id"
for="itxId"
rendered="#{!empty mbCliente.cliente.id}"/>
<p:inputText id="itxId"
value="#{mbCliente.cliente.id}"
disabled="true"
rendered="#{!empty mbCliente.cliente.id}"/>
<h:outputLabel value="Nome"
for="itxNome" />
<p:inputText id="itxNome"
value="#{mbCliente.cliente.nome}"
size="35"
required="true"
requiredMessage="Informe o Nome"/>
<h:outputLabel value="CNPJ"
for="mskCnpj" />
<p:inputMask id="mskCnpj"
mask="99.999.999/9999-99"
value="#{mbCliente.cliente.cnpj}"
required="true"
requiredMessage="Informe o CNPJ"/>
</h:panelGrid>
<h:panelGrid columns="3">
<p:commandLink title="Gravar"
action="#{mbCliente.gravar}"
rendered="#{empty mbCliente.cliente.id}"
update="menssagensCliente, itxId, itxNome, mskCnpj, frmGridCliente">
<p:graphicImage url="/imagens/gravar.jpg"
style="border:0"/>
</p:commandLink>
<p:commandLink title="Alterar"
actionListener="#{mbCliente.alterar}"
rendered="#{!empty mbCliente.cliente.id}"
oncomplete="dlgCliente.hide();"
update="menssagensCliente, itxId, itxCnpj, itxNome, frmGridCliente">
<p:graphicImage url="/imagens/gravar.jpg"
style="border:0"/>
</p:commandLink>
</h:panelGrid>
</p:dialog>
</h:form>
</h:body>
</f:view>
</html>
Code: Select all
package controladores;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.faces.event.ActionEvent;
import org.primefaces.event.RowEditEvent;
import org.primefaces.event.SelectEvent;
import negocios.ClienteBO;
import entidades.Cliente;
@ViewScoped
@ManagedBean(name="mbCliente")
public class MBCliente implements Serializable {
private static final long serialVersionUID = 4718957167100835066L;
private ClienteBO clienteBO;
public Cliente cliente;
private List<Cliente> clientes;
public MBCliente(){
this.setClienteBO(new ClienteBO());
this.setCliente(new Cliente());
this.setClientes(this.listar());
}
public ClienteBO getClienteBO() {
return clienteBO;
}
public void setClienteBO(ClienteBO clienteBO) {
this.clienteBO = clienteBO;
}
public Cliente getCliente() {
return cliente;
}
public void setCliente(Cliente cliente) {
this.cliente = cliente;
}
public List<Cliente> getClientes() {
return clientes;
}
public void setClientes(List<Cliente> clientes) {
this.clientes = clientes;
}
public void incluir(){
this.setCliente(new Cliente());
}
public void gravar(){
try {
this.getClienteBO().gravar(this.getCliente());
this.getClientes().add(this.getCliente());
this.setCliente(new Cliente());
JSFUtil.enviarMenssagemSucesso("Cliente gravado com sucesso");
} catch (Exception e) {
JSFUtil.enviarMenssagemErro("Erro ao gravar"+" "+e.getMessage() );
}
}
public void alterar(ActionEvent evento) {
try {
Integer indice = this.getClientes().indexOf(this.getCliente());
this.getClienteBO().alterar(this.getCliente());
this.getClientes().remove(this.getCliente());
this.getClientes().add(indice, this.getCliente());
JSFUtil.enviarMenssagemSucesso("Cliente alterado com sucesso");
} catch (Exception e) {
JSFUtil.enviarMenssagemErro("Erro ao alterar"+" "+e.getMessage() );
}
}
public void apagar(ActionEvent evento) {
if(this.getCliente() == null || (this.getCliente() != null && this.getCliente().getId() == null) ) {
JSFUtil.enviarMenssagemAtencao("Selecione um cliente na grid");
}else {
try {
this.getClienteBO().apagar(this.getCliente());
this.getClientes().remove(this.getCliente());
JSFUtil.enviarMenssagemSucesso("Cliente apagado com sucesso");
} catch (Exception e) {
JSFUtil.enviarMenssagemErro("Erro ao apagar"+" "+e.getMessage() );
}
}
}
public List<Cliente> listar(){
List<Cliente> clientes = new ArrayList<Cliente>();
try {
clientes = this.getClienteBO().listar();
} catch (Exception e) {
JSFUtil.enviarMenssagemErro("Erro ao Listar"+" "+e.getMessage() );
}
return clientes;
}
public String voltar(){
return "index";
}
}
That is any prime AJAX request generates this error.
Have googled and no surface not find solution.
I hope to help the community.
Thanks