PrimeFaces autocomplete 3.3.1 not working for me - jsf-2

I have set up a test page using the PrimeFaces showcase labs code to test out the component. When I start typing in the autocomplete box, I receive an exception. Note that depending on whether I have client or server state saving turned on, the exceptions are different. I am using WebLogic 11g, PrimeFaces 3.3.1, Apache Tomahawk 1.1.13 and Mojarra 2.1.8. Any ideas?
AutoCompleteBean.java
#ManagedBean
public class AutoCompleteBean {
private String txt1;
public List<String> complete(String query) {
List<String> results = new ArrayList<String>();
for (int i = 0; i < 10; i++) {
results.add(query + i);
}
return results;
}
public String getTxt1() {
return txt1;
}
public void setTxt1(String txt1) {
this.txt1 = txt1;
}
}
autocomplete.xhtml
<!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.org/ui">
<h:head></h:head>
<h:form id="form">
<p:panel header="AutoComplete" toggleable="true" id="panel">
<h:outputLabel value="Simple :" for="acSimple" />
<p:autoComplete id="acSimple" value="#{autoCompleteBean.txt1}"
completeMethod="#{autoCompleteBean.complete}"/>
</p:panel>
</h:form>
</html>
Exception when javax.faces.STATE_SAVING_METHOD = client
Jul 3, 2012 10:00:03 AM com.sun.faces.renderkit.ClientSideStateHelper doGetState
SEVERE: Not in GZIP format
java.io.IOException: Not in GZIP format
at java.util.zip.GZIPInputStream.readHeader(GZIPInputStream.java:137)
at java.util.zip.GZIPInputStream.<init>(GZIPInputStream.java:58)
at java.util.zip.GZIPInputStream.<init>(GZIPInputStream.java:68)
at com.sun.faces.renderkit.ClientSideStateHelper.doGetState(ClientSideStateHelper.java:244)
at com.sun.faces.renderkit.ClientSideStateHelper.getState(ClientSideStateHelper.java:211)
at com.sun.faces.renderkit.ResponseStateManagerImpl.getState(ResponseStateManagerImpl.java:100)
at com.sun.faces.application.view.FaceletPartialStateManagementStrategy.restoreView(FaceletPartialStateManagemen
tStrategy.java:331)
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:513)
at com.sun.faces.application.view.MultiViewHandler.restoreView(MultiViewHandler.java:142)
at javax.faces.application.ViewHandlerWrapper.restoreView(ViewHandlerWrapper.java:303)
at com.sun.faces.lifecycle.RestoreViewPhase.execute(RestoreViewPhase.java:192)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
at com.sun.faces.lifecycle.RestoreViewPhase.doPhase(RestoreViewPhase.java:116)
at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:593)
at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:227)
at weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:125)
at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:292)
at weblogic.servlet.internal.TailFilter.doFilter(TailFilter.java:26)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)
at weblogic.servlet.internal.RequestEventsFilter.doFilter(RequestEventsFilter.java:27)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)
at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:3592)
at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:121)
at weblogic.servlet.internal.WebAppServletContext.securedExecute(WebAppServletContext.java:2202)
at weblogic.servlet.internal.WebAppServletContext.execute(WebAppServletContext.java:2108)
at weblogic.servlet.internal.ServletRequestImpl.run(ServletRequestImpl.java:1432)
at weblogic.work.ExecuteThread.execute(ExecuteThread.java:201)
at weblogic.work.ExecuteThread.run(ExecuteThread.java:173)
Exception when javax.faces.STATE_SAVING_METHOD = server
java.lang.StringIndexOutOfBoundsException: String index out of range: -1
at java.lang.String.substring(String.java:1937)
at com.sun.faces.renderkit.ServerSideStateHelper.getState(ServerSideStateHelper.java:277)
at com.sun.faces.renderkit.ResponseStateManagerImpl.getState(ResponseStateManagerImpl.java:100)
at com.sun.faces.application.view.FaceletPartialStateManagementStrategy.restoreView(FaceletPartialStateManagementStrategy.java:331)
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:513)
at com.sun.faces.application.view.MultiViewHandler.restoreView(MultiViewHandler.java:142)
at javax.faces.application.ViewHandlerWrapper.restoreView(ViewHandlerWrapper.java:303)
at com.sun.faces.lifecycle.RestoreViewPhase.execute(RestoreViewPhase.java:192)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
at com.sun.faces.lifecycle.RestoreViewPhase.doPhase(RestoreViewPhase.java:116)
at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:593)
at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:227)
at weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:125)
at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:292)
at weblogic.servlet.internal.TailFilter.doFilter(TailFilter.java:26)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)
at weblogic.servlet.internal.RequestEventsFilter.doFilter(RequestEventsFilter.java:27)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)
at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:3592)
at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:121)
at weblogic.servlet.internal.WebAppServletContext.securedExecute(WebAppServletContext.java:2202)
at weblogic.servlet.internal.WebAppServletContext.execute(WebAppServletContext.java:2108)
at weblogic.servlet.internal.ServletRequestImpl.run(ServletRequestImpl.java:1432)
at weblogic.work.ExecuteThread.execute(ExecuteThread.java:201)
at weblogic.work.ExecuteThread.run(ExecuteThread.java:173)

The problem was caused by the Apache Tomahawk library. Once I removed the Tomahawk JAR (I luckily can do without it), the issue went away. It appears as though Tomahawk and PrimeFaces do not play nicely together, which is a shame. I was using the latest Tomahawk JAR as of today (1.1.13).

Related

javax.faces.el.EvaluationException: java.lang.NullPointerException in my jsf web App

I am working on a dynamic Web Application and as a first step i want to use my jsf page to save a new Group in the DataBase .I am connecting to an Oracle 10g DataBase, working on eclipse Kepler, with Glassfish4 and using primefaces 4.0.This the StackTrace
2013-12-07T00:38:34.028+0100|Avertissement: #{groupeBean.createGroupe}: java.lang.NullPointerException
javax.faces.FacesException: #{groupeBean.createGroupe}: java.lang.NullPointerException
at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:118)
at javax.faces.component.UICommand.broadcast(UICommand.java:315)
at javax.faces.component.UIData.broadcast(UIData.java:1108)
at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:790)
at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1282)
at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:81)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
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:357)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:260)
at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:188)
at org.glassfish.grizzly.http.server.HttpHandler.runService(HttpHandler.java:191)
at org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:168)
at org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.java:189)
at org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(ExecutorResolver.java:119)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:288)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:206)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:136)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:114)
at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:77)
at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:838)
at org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:113)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:115)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access$100(WorkerThreadIOStrategy.java:55)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$WorkerThreadRunnable.run(WorkerThreadIOStrategy.java:135)
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:564)
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:544)
at java.lang.Thread.run(Thread.java:724)
Caused by: javax.faces.el.EvaluationException: java.lang.NullPointerException
at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:101)
at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:102)
... 35 more
Caused by: java.lang.NullPointerException
at com.portail.dao.DaoGroupe.ajouter(DaoGroupe.java:21)
at com.portail.managedBeans.GroupeBean.createGroupe(GroupeBean.java:24)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at com.sun.el.parser.AstValue.invoke(AstValue.java:275)
at com.sun.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:304)
at org.jboss.weld.util.el.ForwardingMethodExpression.invoke(ForwardingMethodExpression.java:40)
at org.jboss.weld.el.WeldMethodExpression.invoke(WeldMethodExpression.java:50)
at com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:105)
at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:87)
... 36 more
This is the code of the managedBean
#ManagedBean
#ViewScoped
public class GroupeBean {
private Groupe newGroupe=new Groupe();
public Groupe getNewGroupe() {
return newGroupe;
}
public void setNewGroupe(Groupe newGroupe) {
this.newGroupe = newGroupe;
}
private DaoGroupe gdao= new DaoGroupe();
public void createGroupe()
{
gdao.ajouter(newGroupe);
}}
This is the code of the Dao Class
public class DaoGroupe {
private static final String JPA_UNIT_NAME="Portail";
private EntityManager entityManager;
protected EntityManager getEntityManager() {
if (entityManager == null) {
entityManager = Persistence.createEntityManagerFactory(
JPA_UNIT_NAME).createEntityManager();
}
return entityManager;
}
public void ajouter(Groupe g)
{
EntityTransaction tx = entityManager.getTransaction();
tx.begin();
entityManager.persist(g);
tx.commit();}}
And this is the insert tab in my jsf page
<p:tab title="Groupe">
<h:form>
<h:panelGrid columns="2">
<h:outputText value="Nom : *" />
<p:inputText value="#{groupeBean.newGroupe.nom}" required="true"
label="nomgrp" validatorMessage="Nom de Groupe Obligatoire" />
<h:outputText value="Numéro : *" />
<p:inputText value="#{groupeBean.newGroupe.idGroupe}" required="true"
label="numgrp" validatorMessage="Numéro de Groupe Obligatoire" />
</h:panelGrid>
<p:commandButton value="Ajouter"
style="width:205px;margin-left:10%"
action="#{groupeBean.createGroupe}" />
</h:form>
</p:tab>
You get a NullPointerException in your DaoGroupe-Class within the method ajouter.
I guess the entityManager.getTransaction() is the reason, because the entityManager is not filled anywhere. Replacing it with using your getEntityManager()-method might be a first point to start debugging from.
EntityTransaction tx = getEntityManager().getTransaction();
Hope it helps...

Deltaspikes #WindowScoped working with TomEE?

I'm struggeling how to get Deltaspikes #WindowScoped working with TomEE (did try 1.5.2, 1.5.3-SNAPSHOT and 1.6.0-SNAPSHOT)
Its a very minimal war, with deltaspike 0.4 core+jsf dependencies.
Now, i did create a HelloWorldBean like this:
#Named("HW")
#WindowScoped
public class HelloWorldBean implements PassivationCapable,Serializable{
private static final long serialVersionUID = 1L;
private String name;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
#PostConstruct
public void test() {
System.out.println("Bean did get constructed");
}
....
}
There's an empty beans.xml, empty faces-config.xml and a very minimal web.xml.
on a very simple page i have.
<h:form>
<h:inputText value="#{HW.name}"></h:inputText>
<h:commandButton value="Welcome Me" actionListener="#{HW.printIt}"></h:commandButton>
</h:form>
The page works fine, a windowId is added to the request and when i refresh the page i see that the bean is not instanciated (i.e. test() gets only called once).
But as soon i press the commandButton i get an ContextNotActiveException exception:
org.apache.myfaces.view.facelets.el.ContextAwareELException: javax.el.ELException: Error reading 'name' on type de.glauche.beans.HelloWorldBean$$OwbNormalScopeProxy0
at org.apache.myfaces.view.facelets.el.ContextAwareTagValueExpression.getValue(ContextAwareTagValueExpression.java:104)
at javax.faces.component._DeltaStateHelper.eval(_DeltaStateHelper.java:249)
at javax.faces.component.UIOutput.getValue(UIOutput.java:67)
at javax.faces.component.UIInput.getValue(UIInput.java:151)
at javax.faces.component.UIInput.validate(UIInput.java:618)
at javax.faces.component.UIInput.processValidators(UIInput.java:274)
at javax.faces.component.UIForm.processValidators(UIForm.java:213)
at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1427)
at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1427)
at javax.faces.component.UIViewRoot._processValidatorsDefault(UIViewRoot.java:1456)
at javax.faces.component.UIViewRoot.access$500(UIViewRoot.java:74)
at javax.faces.component.UIViewRoot$ProcessValidatorPhaseProcessor.process(UIViewRoot.java:1563)
at javax.faces.component.UIViewRoot._process(UIViewRoot.java:1412)
at javax.faces.component.UIViewRoot.processValidators(UIViewRoot.java:812)
at org.apache.myfaces.lifecycle.ProcessValidationsExecutor.execute(ProcessValidationsExecutor.java:38)
at org.apache.myfaces.lifecycle.LifecycleImpl.executePhase(LifecycleImpl.java:170)
at org.apache.myfaces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:117)
at org.apache.deltaspike.jsf.impl.listener.request.DeltaSpikeLifecycleWrapper.execute(DeltaSpikeLifecycleWrapper.java:75)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:197)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
at org.apache.tomee.catalina.OpenEJBValve.invoke(OpenEJBValve.java:45)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1023)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:724)
Caused by: javax.el.ELException: Error reading 'name' on type de.glauche.beans.HelloWorldBean$$OwbNormalScopeProxy0
at javax.el.BeanELResolver.getValue(BeanELResolver.java:68)
at javax.el.CompositeELResolver.getValue(CompositeELResolver.java:58)
at org.apache.myfaces.el.unified.resolver.FacesCompositeELResolver.getValue(FacesCompositeELResolver.java:179)
at org.apache.el.parser.AstValue.getValue(AstValue.java:183)
at org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:185)
at org.apache.webbeans.el22.WrappedValueExpression.getValue(WrappedValueExpression.java:70)
at org.apache.myfaces.view.facelets.el.ContextAwareTagValueExpression.getValue(ContextAwareTagValueExpression.java:96)
... 35 more
Caused by: javax.enterprise.context.ContextNotActiveException: WebBeans context with scope type annotation #WindowScoped does not exist within current thread
at org.apache.webbeans.container.BeanManagerImpl.getContext(BeanManagerImpl.java:299)
at org.apache.webbeans.intercept.NormalScopedBeanInterceptorHandler.getContextualInstance(NormalScopedBeanInterceptorHandler.java:88)
at org.apache.webbeans.intercept.NormalScopedBeanInterceptorHandler.get(NormalScopedBeanInterceptorHandler.java:70)
at de.glauche.beans.HelloWorldBean$$OwbNormalScopeProxy0.getName(de/glauche/beans/HelloWorldBean.java)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at javax.el.BeanELResolver.getValue(BeanELResolver.java:64)
... 41 more
Am i missing something obvious? Or is it a bug in DeltaSpike? (or TomEE?)
This Exception indicates that the windowId is not set in the WindowContext. Did you add the proper DeltaSpike tag into your fragment?
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html 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:c="http://java.sun.com/jsp/jstl/core"
xmlns:ds="http://deltaspike.apache.org/jsf">
<h:head></h:head>
<h:body>
<ds:windowId/>
...
The ds:windowId part is important.
You can debug into DeltaSpikeLifecycleWrapper#execute to see if the windowId gets detected properly.

PrimePush counter implementation

I am trying to implement prime push counter in my project. I am using PrimeFaces3.5, Jboss7.0 and Eclipse Indigo version.
I have added jars related to prime push:
atmosphere-annotations-1.0.1.jar
atmosphere-compat-jbossweb-1.0.1.jar
atmosphere-compat-tomcat-1.0.1.jar
atmosphere-compat-tomcat7-1.0.1.jar
atmosphere-runtime-1.0.1.jar
primefaces-3.5.jar and jsf and slf4j jars
My xhtml code:
<?xml version="1.0" encoding="UTF-8"?>
<!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:f="http://java.sun.com/jsf/core" xmlns:h="http://java.sun.com/jsf/html"
xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:p="http://primefaces.org/ui">
<h:head></h:head>
<h:body>
<h:form id="form">
<h:outputText id="out" value="#{pushBean.count}" />
<p:commandButton value="Click" actionListener="#{pushBean.increment}" />
</h:form>
<p:socket onMessage="handleMessage" channel="/counter" />
<script type="text/javascript">
function handleMessage(data) {
$('.display').html(data);
}
</script>
</h:body>
</html>
My managed bean:
#ManagedBean(name = "pushBean")
#ApplicationScoped
public class PushBean {
public PushBean() {
}
private int count;
public int getCount() {
return this.count;
}
public void setCount(final int count) {
this.count = count;
}
public synchronized void increment() {
this.count++;
PushContext pushContext = PushContextFactory.getDefault().getPushContext();
pushContext.push("/counter", String.valueOf(this.count));
}
}
When I click the button in UI, the count is incremented on the server, but it is not reflected in UI automatically, because it is not updated. But when I refresh the page, the count is incremented as expected.
Exception I am getting is:
13:00:02,298 ERROR [stderr] (http--0.0.0.0-8080-5) [http--0.0.0.0-8080-5] ERROR org.atmosphere.cpr.AtmosphereFramework - AtmosphereFramework exception
13:00:02,298 ERROR [stderr] (http--0.0.0.0-8080-5) java.lang.IllegalStateException: The servlet or filters that are being used by this request do not support async operation
This exception happens when your web app is run in Servlet 3 compliant containers. The correct web.xml must have the async-supported element set to true, for example:
<servlet>
<servlet-name>Push Servlet</servlet-name>
<servlet-class>org.primefaces.push.PushServlet</servlet-class>
<async-supported>true</async-supported>
</servlet>
Reference: Installing Atmosphere
I'm not very sure about push framework but i think the problem is with your javascript.
you are trying to refresh ".display" control but there is nothing like .display.
Try '.out' instead of .display

Primefaces datatable onRowSelect method causing nullpointer exception

I am using Hibernate 4, Spring 3 and JSF 2.0 with Weblogic 10.3.6 as server. I am loading my datatable using lazy loading.
JSF Page
<p:dataTable id="dataTable" var="req" lazy="true" value="#{emp.lazyModel}"
paginator="true" rows="10"
selection="#{emp.selectedRequest}"
selectionMode="single">
<p:ajax event="rowSelect" listener="#{emp.onRowSelect}" />
When I select a row in a datatable I am getting null pointer exception in onRowSelect method.
ManagedBean
public void onRowSelect(SelectEvent event) {
try {
this.setRequestNo(event.getObject().toString());
} catch (Exception e) {
e.printStackTrace();
}
}
In LazyEmpDataModel I have the following methods
#Override
public void setRowIndex(final int rowIndex) {
if (rowIndex == -1 || getPageSize() == 0) {
super.setRowIndex(-1);
} else {
super.setRowIndex(rowIndex % getPageSize());
}
}
#Override
public Object getRowKey(Employees emp) {
return request.getRequestNo();
}
#Override
public Employees getRowData(String rowKey) {
for (Employees emp : requestList) {
if (emp.getEmpNo().equals(rowKey))
return emp;
}
return null;
}
Full stackexception
java.lang.NullPointerException
at net.test.managed.bean.RequestManagedBean.onRowSelect(RequestManagedBean.java:134)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at com.sun.el.parser.AstValue.invoke(AstValue.java:187)
at com.sun.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:297)
at org.primefaces.component.behavior.ajax.AjaxBehaviorListenerImpl.processAjaxBehavior(AjaxBehaviorListenerImpl.java:52)
at org.primefaces.event.SelectEvent.processListener(SelectEvent.java:40)
at javax.faces.component.behavior.BehaviorBase.broadcast(BehaviorBase.java:106)
at javax.faces.component.UIComponentBase.broadcast(UIComponentBase.java:760)
at javax.faces.component.UIData.broadcast(UIData.java:1071)
at javax.faces.component.UIData.broadcast(UIData.java:1093)
at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:794)
at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1259)
at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:81)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:593)
at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:227)
at weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:125)
at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:301)
at weblogic.servlet.internal.TailFilter.doFilter(TailFilter.java:26)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)
at weblogic.servlet.internal.RequestEventsFilter.doFilter(RequestEventsFilter.java:27)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)
at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.wrapRun(WebAppServletContext.java:3730)
at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:3696)
at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:120)
at weblogic.servlet.internal.WebAppServletContext.securedExecute(WebAppServletContext.java:2273)
at weblogic.servlet.internal.WebAppServletContext.execute(WebAppServletContext.java:2179)
at weblogic.servlet.internal.ServletRequestImpl.run(ServletRequestImpl.java:1490)
at weblogic.work.ExecuteThread.execute(ExecuteThread.java:256)
at weblogic.work.ExecuteThread.run(ExecuteThread.java:221)
INMO its something with your view scope bean , try making it session... if session will help look for a way to work properly with CDI View bean
Maybe its being invalidated for some reason... Add a post constructor to your bean with print lines and see if its indeed being reconstructed upon pagination / row selection

IndexOutOfBoundsException after switching from myfaces to mojarra

I was forced to switch from myfaces (2.1.7) to mojarra (2.1.7). After this I'm getting exceptions like this one below all over the place.
I'm submitting a form, that gives me validation errors. This is correct so far. I submit the form again, that gives me validation errors. This is correct so far. Now I submit the form again and I get the IndexOutOfBoundsException.
javax.faces.FacesException: Unexpected error restoring state for component with id someForm:someField. Cause: java.lang.IndexOutOfBoundsException: Index: 1, Size: 1.
at com.sun.faces.application.view.StateManagementStrategyImpl$2.visit(StateManagementStrategyImpl.java:272)
at com.sun.faces.component.visit.FullVisitContext.invokeVisitCallback(FullVisitContext.java:151)
at javax.faces.component.UIComponent.visitTree(UIComponent.java:1612)
at javax.faces.component.UIComponent.visitTree(UIComponent.java:1623)
at javax.faces.component.UIComponent.visitTree(UIComponent.java:1623)
at javax.faces.component.UIForm.visitTree(UIForm.java:371)
at javax.faces.component.UIComponent.visitTree(UIComponent.java:1623)
at javax.faces.component.UIComponent.visitTree(UIComponent.java:1623)
at javax.faces.component.UIComponent.visitTree(UIComponent.java:1623)
at javax.faces.component.UIComponent.visitTree(UIComponent.java:1623)
at com.sun.faces.application.view.StateManagementStrategyImpl.restoreView(StateManagementStrategyImpl.java:251)
at com.sun.faces.application.StateManagerImpl.restoreView(StateManagerImpl.java:188)
at com.sun.faces.application.view.ViewHandlingStrategy.restoreView(ViewHandlingStrategy.java:123)
at com.sun.faces.application.view.FaceletViewHandlingStrategy.restoreView(FaceletViewHandlingStrategy.java:453)
at com.sun.faces.application.view.MultiViewHandler.restoreView(MultiViewHandler.java:142)
at javax.faces.application.ViewHandlerWrapper.restoreView(ViewHandlerWrapper.java:303)
at com.sun.faces.lifecycle.RestoreViewPhase.execute(RestoreViewPhase.java:192)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
at com.sun.faces.lifecycle.RestoreViewPhase.doPhase(RestoreViewPhase.java:116)
at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:593)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.primefaces.webapp.filter.FileUploadFilter.doFilter(FileUploadFilter.java:79)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:859)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:602)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
at java.lang.Thread.run(Thread.java:619)
Caused by: java.lang.IndexOutOfBoundsException: Index: 1, Size: 1
at java.util.ArrayList.RangeCheck(ArrayList.java:547)
at java.util.ArrayList.get(ArrayList.java:322)
at javax.faces.component.AttachedObjectListHolder.restoreState(AttachedObjectListHolder.java:165)
at javax.faces.component.UIInput.restoreState(UIInput.java:1411)
at com.sun.faces.application.view.StateManagementStrategyImpl$2.visit(StateManagementStrategyImpl.java:264)
... 35 more
I googled this, but haven't found any clue yet.
Jonny
The stacktrace hints that you're using PrimeFaces.
This problem is known in older versions of PrimeFaces and is actually a bug in PrimeFaces, not in Mojarra. Make sure that you're using the latest PrimeFaces version. As of now that's 2.2.1 when you're using PF2 or 3.2 when you're using PF3.
I have the exact same problem and it is easy to reproduce.
You can reproduce it with the following classes:
Validator:
#FacesValidator("testValidator")
public class TestValidator implements Validator {
#Override
public void validate(FacesContext fc, UIComponent uic, Object o) throws ValidatorException {
if (!(o instanceof Integer)) {
throw new ValidatorException(new FacesMessage("validation message!"));
}
}
}
FacesComponent:
#ListenerFor(systemEventClass = PreValidateEvent.class)
#FacesComponent("testField")
public class TestField extends UIComponentBase implements NamingContainer {
#Override
public String getFamily() {
return UINamingContainer.COMPONENT_FAMILY;
}
#Override
public void processEvent(ComponentSystemEvent event) throws AbortProcessingException {
super.processEvent(event);
UIComponent findComponent = findComponent("input");
if (findComponent instanceof UIInput) {
UIInput i = (UIInput) findComponent;
boolean notFound = true;
for (Validator v : i.getValidators()) {
if (v instanceof TestValidator) {
notFound = false;
}
}
if (notFound) {
i.addValidator(new TestValidator());
}
}
}
}
Custom Component:
<?xml version='1.0' encoding='UTF-8' ?>
<!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:cc="http://java.sun.com/jsf/composite">
<!-- INTERFACE -->
<cc:interface componentType="testField">
</cc:interface>
<!-- IMPLEMENTATION -->
<cc:implementation>
field: <h:inputText id="input" value="#{testController.inputText}" />
</cc:implementation>
</html>
ManagedBean:
#SessionScoped
#Named("testController")
public class TestController implements Serializable {
private static final long serialVersionUID = 1L;
private String inputText = "";
public TestController() {
}
public void actionListener(ActionEvent event) {
}
public String myAction() {
return "";
}
public String getInputText() {
return inputText;
}
public void setInputText(String inputText) {
this.inputText = inputText;
}
}
index.xhtml
<?xml version='1.0' encoding='UTF-8' ?>
<!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:t="http://java.sun.com/jsf/composite/test"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://xmlns.jcp.org/jsf/html">
<h:head>
<title>Jsf Problem</title>
</h:head>
<h:body>
<h:form>
<h:messages />
<t:field />
<h:commandButton value="Submit" action="#{testController.myAction()}" />
</h:form>
</h:body>
</html>
The inputText inside the custom component field gets an new Validator added at PreValidateEvent inside the processEvent() method.
If the submit button is now pressed three times in a row with an validation error the ArrayIndexOutOfBoundException will be thrown. I tried to debug and found out that the exception is throwed inside AttachedObjectListHolder#restoreState(FacesContext, Object), afterward my eclipse debugger got crazy...
I think this is a JSF Bug!
I wanted to leave a comment but I'am not allowed yet... :(

Resources