Tengo este codigo xhtml:
<div class="row">
<div class="col-lg-5 col-md-5 col-sm-12 col-xs-12">
<div class="input-group">
<h:inputText p:placeholder="Nro Documento" class="form-control" value="#{BeanPersonal.paramNroDocSearch}" id="paramNroDoc" type="text"/>
</div>
</div>
<div class="col-lg-1 col-md-1 col-sm-12 col-xs-12">
<div class="input-group">
<h:commandLink id="searchButton" value="" >
<f:ajax event="click" listener="#{BeanPersonal.buscarPersonasN()}" render="tablaDatos" execute="paramNroDoc"/>
<i class="fa fa-search fa-2x"></i>
</h:commandLink>
</div>
</div>
</div>
<h:panelGroup id="tablaDatos">
<div class="row">
<h:panelGroup rendered="#{BeanPersonal.personasN.isEmpty() eq false}">
<div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
<div class="table-responsive">
<h:dataTable id="personasN" styleClass="table table-bordered" value="#{BeanPersonal.personasN}" var="perN" >
<h:column>
<f:facet name="header">Apellido y Nombre</f:facet>
<h:outputText id="nombreCompleto" value="#{perN.nombreNCompleto}" />
</h:column>
<h:column>
<f:facet name="header">Nro. Documento</f:facet>
<h:outputText id="doc" value="#{perN.documentoNro}" />
</h:column>
<h:column>
<f:facet name="header">Sexo</f:facet>
<h:panelGroup rendered="#{perN.sexo eq 'M'}">
<h:outputText value="Masculino" />
</h:panelGroup>
<h:panelGroup rendered="#{perN.sexo eq 'F'}">
<h:outputText value="Femenino" />
</h:panelGroup>
</h:column>
<h:column>
<h:commandButton class="btn btn-info" value="Seleccionar" type="button" >
<f:ajax event="click" listener="#{BeanPersonal.seleccionPersonaN(perN)}" render="datos" onevent="defaultTab"></f:ajax>
</h:commandButton>
</h:column>
</h:dataTable>
</div>
</div>
</h:panelGroup>
<h:panelGroup >
<h:panelGroup layout="block" rendered="#{Bean.personasN.isEmpty() eq true}">
<div class="row">
<div class="col-lg-3 col-sm-3 col-lg-offset-3 col-sm-offset-3 col-xs-12">
<h2>
<span class="label label-danger">No se ha encontrado la persona</span>
</h2>
</div>
</div>
<div class="col-lg-3 col-md-3 col-sm-12 col-xs-12">
<div class="input-group">
<h:commandButton class="btn btn-info" value="Dar de Alta Nuevo" type="button" >
<f:ajax event="click" listener="#{Bean.nuevaPersona()}" render="datos" onevent="defaultTab"/>
</h:commandButton>
</div>
</div>
</h:panelGroup>
</h:panelGroup>
</div>
</h:panelGroup>
Y en el BeanPersonal el siguiente metodo:
public void buscarPersonasN()
{
personasN = new ArrayList<PersonasN>();
Session sessionN = null;
try{
paramNroDocSearch = paramNroDocSearch.trim();
sessionN = DBUtil.crearSesion();
personasN = sessionN.createQuery("select p from PersonasN as p where p.documentoNro = :documentoNro")
.setParameter("documentoNro", paramNroDocSearch)
.list();
if(personasN == null){
personasN = new ArrayList<PersonasN>();
}
}catch(Exception e){
e.printStackTrace();
}finally{
if(sessionN != null)
sessionN.close();
}
}
La idea básicamente es buscar una persona en una base de datos y agregarlas en una lista para poder mostrar en una h:datatable para que pueda ser seleccionada.
Cuando ejecuto el código, hay veces que funciona bien, pero otras en donde me larga el siguiente error:
Grave: java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
at java.util.ArrayList.rangeCheck(ArrayList.java:635)
at java.util.ArrayList.get(ArrayList.java:411)
at javax.faces.component.AttachedObjectListHolder.restoreState(AttachedObjectListHolder.java:166)
at javax.faces.component.UIComponentBase.restoreState(UIComponentBase.java:1604)
at com.sun.faces.application.view.FaceletPartialStateManagementStrategy$2.visit(FaceletPartialStateManagementStrategy.java:380)
at com.sun.faces.component.visit.FullVisitContext.invokeVisitCallback(FullVisitContext.java:151)
at javax.faces.component.UIComponent.visitTree(UIComponent.java:1689)
at javax.faces.component.UIComponent.visitTree(UIComponent.java:1700)
at com.sun.faces.application.view.FaceletPartialStateManagementStrategy.restoreView(FaceletPartialStateManagementStrategy.java:367)
at com.sun.faces.application.StateManagerImpl.restoreView(StateManagerImpl.java:138)
at com.sun.faces.application.view.ViewHandlingStrategy.restoreView(ViewHandlingStrategy.java:123)
at com.sun.faces.application.view.FaceletViewHandlingStrategy.restoreView(FaceletViewHandlingStrategy.java:585)
at com.sun.faces.application.view.MultiViewHandler.restoreView(MultiViewHandler.java:150)
at javax.faces.application.ViewHandlerWrapper.restoreView(ViewHandlerWrapper.java:353)
at com.sun.faces.lifecycle.RestoreViewPhase.execute(RestoreViewPhase.java:197)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
at com.sun.faces.lifecycle.RestoreViewPhase.doPhase(RestoreViewPhase.java:121)
at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:198)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:646)
at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1682)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:318)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:160)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:734)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:673)
at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:99)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:174)
at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:415)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:282)
at com.sun.enterprise.v3.services.impl.ContainerMapper$HttpHandlerCallable.call(ContainerMapper.java:459)
at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:167)
at org.glassfish.grizzly.http.server.HttpHandler.runService(HttpHandler.java:201)
at org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:175)
at org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.java:235)
at org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(ExecutorResolver.java:119)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:284)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:201)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:133)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:112)
at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:77)
at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:561)
at org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:112)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:117)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access$100(WorkerThreadIOStrategy.java:56)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$WorkerThreadRunnable.run(WorkerThreadIOStrategy.java:137)
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:565)
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:545)
at java.lang.Thread.run(Thread.java:745)
Me da el error y no puedo encontrarle una lógica de porque lo larga, y no me muestra alguna linea del codigo de arriba. El error lo genera cuando apreto el h:commandLink.
@ViewScoped
. Asimismo, incluye la versión de JSF y CDI (si es que utilizas).