<f:view locale=""/> throws NullPointerException - jsf

I'm developing an web application using JSF and I need to make the web available in other languages. I haven't developed the app, I have to continue its development. In some views the following is used:
<f:view locale="#{nuevoProyectoBacking.locale}"/>
<f:loadBundle basename="com.company.resources.resdisenyo" var="rDisenyo"/>
So I've created a new JSF page and done the same:
<?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://xmlns.jcp.org/jsf/html"
xmlns:f="http://xmlns.jcp.org/jsf/core"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets">
<ui:composition template="/WEB-INF/templates/template.xhtml">
<f:event type="preRenderView"
listener="#{nuevoProyectoBacking.forwardIfIsNotAdmin}" />
<f:view locale="#{nuevoProyectoBacking.locale}"/>
<f:loadBundle basename="com.appglass.resources.resdisenyo" var="rDisenyo"/>
<ui:define name="top">
<ui:decorate template="/WEB-INF/templates/menuAdministrador.xhtml"></ui:decorate>
</ui:define>
etc
It only works if I remove f:view locale="#{nuevoProyectoBacking.locale}"
nuevoProyectoBacking.java
#ManagedBean
#ViewScoped
public class NuevoProyectoBacking implements Serializable{
definitions
/** Creates a new instance of NuevoProyectoBacking */
public NuevoProyectoBacking()
{
many assignments
locale = LocaleUtil.getIdioma(getCurrentUser().getIdioma());
}
public String getLocale() {
return locale;
}
public void setLocale(String locale) {
this.locale = locale;
}
public Usuarios getCurrentUser()
{
return (Usuarios) getSessionMap().get("currentUser");
}
public Map<String, Object> getSessionMap() {
FacesContext context = FacesContext.getCurrentInstance();
Map<String, Object> sessionMap = context.getExternalContext().getSessionMap();
return sessionMap;
}
}
LocaleUtil
public class LocaleUtil {
public static String getIdioma(Integer idioma){
if(idioma == 0){
return "es_ES";
} else if (idioma == 1) {
return "en_US";
} else if (idioma == 2) {
return "it_IT";
} else if (idioma == 3) {
return "fr_FR";
} else if (idioma == 4) {
return "pt_PT";
} else if (idioma == 5) {
return "ru_RU";
} else if (idioma == 6) {
return "pl_PL";
}else {
return "es_ES";
}
}
}
Error
Warning: StandardWrapperValve[Faces Servlet]: Servlet.service() for servlet Faces Servlet threw exception
java.lang.NullPointerException
at com.sun.faces.mgbean.BeanManager$ScopeManager$ViewScopeHandler.getFromScope(BeanManager.java:566)
at com.sun.faces.mgbean.BeanManager$ScopeManager.getFromScope(BeanManager.java:477)
at com.sun.faces.mgbean.BeanManager.getBeanFromScope(BeanManager.java:240)
at com.sun.faces.el.ManagedBeanELResolver.resolveBean(ManagedBeanELResolver.java:255)
at com.sun.faces.el.ManagedBeanELResolver.getValue(ManagedBeanELResolver.java:117)
at com.sun.faces.el.DemuxCompositeELResolver._getValue(DemuxCompositeELResolver.java:176)
at com.sun.faces.el.DemuxCompositeELResolver.getValue(DemuxCompositeELResolver.java:203)
at com.sun.el.parser.AstIdentifier.getValue(AstIdentifier.java:116)
at com.sun.el.parser.AstValue.getBase(AstValue.java:151)
at com.sun.el.parser.AstValue.getValue(AstValue.java:200)
at com.sun.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:226)
at org.jboss.weld.el.WeldValueExpression.getValue(WeldValueExpression.java:50)
at com.sun.faces.facelets.el.TagValueExpression.getValue(TagValueExpression.java:109)
at com.sun.faces.facelets.tag.TagAttributeImpl.getObject(TagAttributeImpl.java:356)
at com.sun.faces.facelets.tag.TagAttributeImpl.getObject(TagAttributeImpl.java:276)
at com.sun.faces.facelets.tag.jsf.core.ViewHandler.apply(ViewHandler.java:211)
at com.sun.faces.facelets.compiler.NamespaceHandler.apply(NamespaceHandler.java:93)
at com.sun.faces.facelets.compiler.EncodingHandler.apply(EncodingHandler.java:87)
at com.sun.faces.facelets.impl.DefaultFacelet.apply(DefaultFacelet.java:161)
at com.sun.faces.application.view.ViewMetadataImpl.createMetadataView(ViewMetadataImpl.java:140)
at com.sun.faces.lifecycle.RestoreViewPhase.execute(RestoreViewPhase.java:241)
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.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:344)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:214)
at org.primefaces.webapp.filter.FileUploadFilter.doFilter(FileUploadFilter.java:70)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:256)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:214)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:316)
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)
I don't think the problem is in nuevoProyectoBacking as it is used by another JSF Page and it works well, language too. I have to remove that one and create a new one with a new look and feel.

I've fixed it but I don't know why xDDDD
This is my new JSF page
<?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://xmlns.jcp.org/jsf/html"
xmlns:f="http://xmlns.jcp.org/jsf/core"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets">
<ui:composition template="/WEB-INF/templates/template.xhtml">
<f:event type="preRenderView"
listener="#{nuevoProyectoBacking.forwardIfIsNotAdmin}" />
<ui:define name="top">
<ui:decorate template="/WEB-INF/templates/menuAdministrador.xhtml"></ui:decorate>
</ui:define>
<ui:define name="content">
<ui:decorate template="/nuevoProyectoTemplate2.xhtml"></ui:decorate>
</ui:define>
</ui:composition>
</html>
I've written all the HTML code inside /nuevoProyectoTemplate2 and it works.

Related

NullPointerException using JSF 2.3 websocket using JSF navigation

I have some simple navigation using primefaces menu. However I have jsf websockets on both pages. This causes a NullPointerException when navigating between pages. When navigating to Portfolio if there are websockets present in the Portfolio page the NullPointerException is returned when attempting to navigate to it and back to the Stocks page. If I remove all of the websockets from the Portfolio page, then the navigation kind of works - the first click causes the below exception but the second works. If I remove all websockets from both pages the navigation works without issue, but obviously I need the websockets for the page functionality.
EDIT: I've now made a minimal reproducible example and have changed the code below. Note that h:commandLink are included and they also cause the same issue when selecting page2.
java.lang.NullPointerException
at com.sun.faces.push.WebsocketFacesListener.processEvent(WebsocketFacesListener.java:118)
at javax.faces.event.SystemEvent.processListener(SystemEvent.java:147)
at javax.faces.event.ComponentSystemEvent.processListener(ComponentSystemEvent.java:134)
at com.sun.faces.application.ApplicationImpl.processListenersAccountingForAdds(ApplicationImpl.java:2340)
at com.sun.faces.application.ApplicationImpl.invokeViewListenersFor(ApplicationImpl.java:2158)
at com.sun.faces.application.ApplicationImpl.publishEvent(ApplicationImpl.java:337)
at com.sun.faces.application.ApplicationImpl.publishEvent(ApplicationImpl.java:292)
at javax.faces.application.ApplicationWrapper.publishEvent(ApplicationWrapper.java:748)
at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:113)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:100)
at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:223)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:671)
at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1580)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:338)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.glassfish.tyrus.servlet.TyrusServletFilter.doFilter(TyrusServletFilter.java:305)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:250)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:256)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:160)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:652)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:591)
at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:99)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:155)
at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:371)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:238)
at com.sun.enterprise.v3.services.impl.ContainerMapper$HttpHandlerCallable.call(ContainerMapper.java:463)
at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:168)
at org.glassfish.grizzly.http.server.HttpHandler.runService(HttpHandler.java:206)
at org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:180)
at org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.java:242)
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:539)
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:593)
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:573)
at java.lang.Thread.run(Thread.java:748)
This is my menu page:
<?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://xmlns.jcp.org/jsf/html"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
xmlns:p="http://primefaces.org/ui"
xmlns:f="http://xmlns.jcp.org/jsf/core">
<f:view>
<h:head>
</h:head>
<h:body>
<div class="column side">
<h2>Side</h2>
<h:form>
<h:commandLink value="Page1" actionListener="#{menuViewTest.selectPageOne}" />
<h:commandLink value="Page2" actionListener="#{menuViewTest.selectPageTwo}" />
</h:form>
</div>
<div class="column middle">
<h2>Middle</h2>
<ui:include src="#{menuViewTest.view}">
</ui:include>
</div>
</h:body>
</f:view>
</html>
Backing bean for MenuTest:
#Named("menuViewTest")
#SessionScoped
public class MenuViewTest implements Serializable {
private static final long serialVersionUID = -1015364935820045523L;
private String view;
public void selectPageOne() {
setView("page1.xhtml");
}
public void selectPageTwo() {
setView("page2.xhtml");
}
public String getView() {
return view;
}
public void setView(String view) {
this.view = view;
}
public String getSelectPageOne(){
return "page1.xhtml";
}
public String getSelectPageTwo(){
return "page2.xhtml";
}
}
Page1:
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:f="http://xmlns.jcp.org/jsf/core"
xmlns:p="http://primefaces.org/ui"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets">
<script type="text/javascript">
function notifyListener(message, channel, event) {
console.log("notifyListener message: " + message);
console.log("notifyListener channel: " + channel);
console.log("notifyListener event: " + event);
}
</script>
<h2>Page 1</h2>
<f:websocket channel="notify" onmessage="notifyListener" />
</ui:composition>
Page 2:
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:f="http://xmlns.jcp.org/jsf/core"
xmlns:p="http://primefaces.org/ui"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets">
<script type="text/javascript">
function notifyListener(message, channel, event) {
console.log("notifyListener message: " + message);
console.log("notifyListener channel: " + channel);
console.log("notifyListener event: " + event);
}
</script>
<h2>Page 2</h2>
<f:websocket channel="notify2" onmessage="notifyListener" />
</ui:composition>
The websocket exception is fixed by upgrading to the latest stable release of Glassfish (5.1.0) JSF version 2.3 with mojarra 2.3.9.

Abstract subclass of FacesConverter leads to java.lang.InstantiationException

My Setup:
Mojarra 2.2.12
I have an abstractsubclass of a FacesConverter.
Sometimes JSF initializes the superclass and sometimes it fails on trying to instantiate the abstract subclass.
I allready found a workaround. I removed the abstract keyword and gave the AbstractTestConverter a FacesConverter annotation which isn't used then.
This is my reproduction of the problem:
TestBean.java
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
#ManagedBean
#ViewScoped
public class TestBean {
private boolean testProp;
public boolean getTestProp() {
return testProp;
}
public void setTestProp(boolean test) {
this.testProp = test;
}
}
TestConverter.java
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import javax.faces.convert.FacesConverter;
#FacesConverter("testConverter")
public class TestConverter implements Converter{
#Override
public Object getAsObject(FacesContext context, UIComponent component, String value) {
if (value.equals("Test")) {
return true;
}
return false;
}
#Override
public String getAsString(FacesContext context, UIComponent component, Object value) {
if (((boolean)value)) {
return "Test";
}
return null;
}
}
AbstractTestConverter.java
public abstract class AbstractTestConverter extends TestConverter{
}
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:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core">
<h:head>
<title>TestWebProject</title>
</h:head>
<h:body bgcolor="white">
<h:form>
<h:outputLabel value="Test Input: " for="testInput" />
<h:inputText value="#{testBean.testProp}" converter="testConverter" id="testInput" /><br />
<h:outputLabel value="Test Output: " for="testOutput" />
<h:outputText value=":)" rendered="#{testBean.testProp}" id="testOutput" />
</h:form>
</h:body>
</html>
I earn the following stacktrace:
java.lang.InstantiationException
at sun.reflect.InstantiationExceptionConstructorAccessorImpl.newInstance(InstantiationExceptionConstructorAccessorImpl.java:48)
at java.lang.reflect.Constructor.newInstance(Constructor.java:422)
at java.lang.Class.newInstance(Class.java:442)
at com.sun.faces.application.ApplicationImpl.newThing(ApplicationImpl.java:1729)
at com.sun.faces.application.ApplicationImpl.createConverter(ApplicationImpl.java:1332)
at com.sun.faces.facelets.tag.jsf.ValueHolderRule$LiteralConverterMetadata.applyMetadata(ValueHolderRule.java:85)
at com.sun.faces.facelets.tag.MetadataImpl.applyMetadata(MetadataImpl.java:81)
at javax.faces.view.facelets.MetaTagHandler.setAttributes(MetaTagHandler.java:129)
at javax.faces.view.facelets.DelegatingMetaTagHandler.setAttributes(DelegatingMetaTagHandler.java:102)
at com.sun.faces.facelets.tag.jsf.ComponentTagHandlerDelegateImpl.doNewComponentActions(ComponentTagHandlerDelegateImpl.java:491)
at com.sun.faces.facelets.tag.jsf.ComponentTagHandlerDelegateImpl.apply(ComponentTagHandlerDelegateImpl.java:178)
at javax.faces.view.facelets.DelegatingMetaTagHandler.apply(DelegatingMetaTagHandler.java:120)
at javax.faces.view.facelets.CompositeFaceletHandler.apply(CompositeFaceletHandler.java:95)
at javax.faces.view.facelets.DelegatingMetaTagHandler.applyNextHandler(DelegatingMetaTagHandler.java:137)
at com.sun.faces.facelets.tag.jsf.ComponentTagHandlerDelegateImpl.apply(ComponentTagHandlerDelegateImpl.java:202)
at javax.faces.view.facelets.DelegatingMetaTagHandler.apply(DelegatingMetaTagHandler.java:120)
at javax.faces.view.facelets.DelegatingMetaTagHandler.applyNextHandler(DelegatingMetaTagHandler.java:137)
at com.sun.faces.facelets.tag.jsf.ComponentTagHandlerDelegateImpl.apply(ComponentTagHandlerDelegateImpl.java:202)
at javax.faces.view.facelets.DelegatingMetaTagHandler.apply(DelegatingMetaTagHandler.java:120)
at javax.faces.view.facelets.CompositeFaceletHandler.apply(CompositeFaceletHandler.java:95)
at com.sun.faces.facelets.compiler.NamespaceHandler.apply(NamespaceHandler.java:93)
at com.sun.faces.facelets.compiler.EncodingHandler.apply(EncodingHandler.java:87)
at com.sun.faces.facelets.impl.DefaultFacelet.apply(DefaultFacelet.java:161)
at com.sun.faces.application.view.FaceletViewHandlingStrategy.buildView(FaceletViewHandlingStrategy.java:1006)
at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:99)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:219)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:659)
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:416)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:283)
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:206)
at org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:180)
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:283)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:200)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:132)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:111)
at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:77)
at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:536)
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:591)
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:571)
at java.lang.Thread.run(Thread.java:745)
Isn't it possible to use an abstract subclass of a FacesConverter?

/index.xhtml #10,68 value="#{testBean.testString}": Target Unreachable, identifier 'testBean' resolved to null [duplicate]

This question already has answers here:
Identifying and solving javax.el.PropertyNotFoundException: Target Unreachable
(18 answers)
Closed 6 years ago.
I write simple code but it don't work!
Here are index.xhtml file
<?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://xmlns.jcp.org/jsf/html">
<h:head>
<title>Проверка</title>
</h:head>
<h:body>
<h:form>
<h:inputText id="text" value="#{testBean.testString}"/>
<h:commandButton id="button" action="#{testBean.buttonClick()}" value="сохранить в БД"/>
</h:form>
</h:body>
</html>
Here are nextpage.xhtml file
<?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://xmlns.jcp.org/jsf/html">
<h:head>
<title>Facelet Title</title>
</h:head>
<h:body>
<h:outputText value="#{testBean.allTestItem}"/>
</h:body>
</html>
Here are TestBean.java file
#Stateful
#Named(value = "testBean")
#SessionScoped
public class TestBean implements Serializable {
#Inject
EntityManager em;
String testString = "test0";
public TestBean() {
}
public String getTestString() {
return testString;
}
public void setTestString(String testString) {
this.testString = testString;
}
public String allTestItem() {
String jpql = "SELECT te FROM " + TestEntity.class.getName() + " te";
Query query = em.createQuery(jpql);
return query.getResultList().toString();
}
public String buttonClick() {
TestEntity te = new TestEntity();
te.setTest(testString);
em.persist(te);
return "nextpage";
}
}
Here are EntityManagerAdapter.java file
#Stateful
#Named(value = "testBean")
#SessionScoped
public class TestBean implements Serializable {
#Inject
EntityManager em;
String testString = "test0";
public TestBean() {
}
public String getTestString() {
return testString;
}
public void setTestString(String testString) {
this.testString = testString;
}
public String allTestItem() {
String jpql = "SELECT te FROM " + TestEntity.class.getName() + " te";
Query query = em.createQuery(jpql);
return query.getResultList().toString();
}
public String buttonClick() {
TestEntity te = new TestEntity();
te.setTest(testString);
em.persist(te);
return "nextpage";
}
}
Exception I get
javax.el.PropertyNotFoundException: /index.xhtml #10,68 value="#{testBean.testString}": Target Unreachable, identifier 'testBean' resolved to null
at com.sun.faces.facelets.el.TagValueExpression.getType(TagValueExpression.java:100)
at com.sun.faces.renderkit.html_basic.HtmlBasicInputRenderer.getConvertedValue(HtmlBasicInputRenderer.java:95)
at javax.faces.component.UIInput.getConvertedValue(UIInput.java:1046)
at javax.faces.component.UIInput.validate(UIInput.java:976)
at javax.faces.component.UIInput.executeValidate(UIInput.java:1249)
at javax.faces.component.UIInput.processValidators(UIInput.java:712)
at javax.faces.component.UIForm.processValidators(UIForm.java:253)
at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1261)
at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1261)
at javax.faces.component.UIViewRoot.processValidators(UIViewRoot.java:1195)
at com.sun.faces.lifecycle.ProcessValidationsPhase.execute(ProcessValidationsPhase.java:76)
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:744)
Caused by: javax.el.PropertyNotFoundException: Target Unreachable, identifier 'testBean' resolved to null
at com.sun.el.parser.AstValue.getTarget(AstValue.java:174)
at com.sun.el.parser.AstValue.getType(AstValue.java:86)
at com.sun.el.ValueExpressionImpl.getType(ValueExpressionImpl.java:201)
at com.sun.faces.facelets.el.TagValueExpression.getType(TagValueExpression.java:98)
... 40 more
Explain me please what's the problem?
It means that CDI couldn't create an instance of TestBean class to satisfy the request. After reviewing your design, it is pretty unclear what you're trying to do. Usually, a CDI bean should not be an EJB. Remove the EJB #Stateful annotation from TestBean and it should work as expected.

After upgrading PrimeFaces 3.5 to 4.0, p:fileUpload throws exception

I have a code that make the upload perfectly using primefaces 3.5, but I update the primefaces lib in my project to 4.0 and it doesn´t work any more. Here is the code:
web.xml
<filter>
<filter-name>PrimeFaces FileUpload Filter</filter-name>
<filter-class> org.primefaces.webapp.filter.FileUploadFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>PrimeFaces FileUpload Filter</filter-name>
<servlet-name>Faces Servlet</servlet-name>
</filter-mapping>
xhtml page
<?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://xmlns.jcp.org/jsf/html"
xmlns:p="http://primefaces.org/ui">
<h:head>
<title>Facelet Title</title>
</h:head>
<h:body>
<h:form enctype="multipart/form-data">
<p:fileUpload fileUploadListener="#{siteBean.fileUploadAction}" />
</h:form>
</h:body>
</html>
SiteBean.java
#ManagedBean
#ViewScoped
public class SiteBean{
public void fileUploadAction(FileUploadEvent event) {
try {
ExternalContext externalContext = FacesContext.getCurrentInstance().getExternalContext();
HttpServletResponse response = (HttpServletResponse) externalContext.getResponse();
FacesContext aFacesContext = FacesContext.getCurrentInstance();
ServletContext context = (ServletContext) aFacesContext.getExternalContext().getContext();
String realPath = context.getRealPath("/");
File folder = new File(realPath + "/img/sites/");
folder.mkdirs();
byte[] file = event.getFile().getContents();
String path = realPath + "/img/sites/" + event.getFile().getFileName();
FileOutputStream fos = new FileOutputStream(path);
fos.write(file);
fos.close();
}
catch (Exception ex) {
System.out.println("Error: " + ex.getMessage());
}
}
}
When I try to upload a file it shows me exception message.
Here is the exception:
SEVERE: java.lang.NullPointerException
at java.io.FileOutputStream.write(FileOutputStream.java:305)
at managedBean.SiteBean.fileUploadAction(SiteBean.java:83)
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:275)
at com.sun.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:304)
at com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:105)
at org.primefaces.component.fileupload.FileUpload.broadcast(FileUpload.java:290)
at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:755)
at javax.faces.component.UIViewRoot.processDecodes(UIViewRoot.java:931)
at com.sun.faces.lifecycle.ApplyRequestValuesPhase.execute(ApplyRequestValuesPhase.java:78)
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.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:344)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:214)
at org.primefaces.webapp.filter.FileUploadFilter.doFilter(FileUploadFilter.java:70)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:256)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:214)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:316)
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)
I´m using Netbeans 7.4, primefaces 4.0, common io 2.4, common file upload 1.3 and jsf 2.2.
The datas are in the inputStream
Try something like this :
// write the inputStream to a FileOutputStream
OutputStream out = null;
InputStream in = event.getFile().getInputStream();
try
{
out = new FileOutputStream(new File(dirPath, fileName));
int read = 0;
byte[] bytes = new byte[1024];
while ((read = in.read(bytes)) != -1)
{
out.write(bytes, 0, read);
}
out.flush();
} catch (IOException e) {
}
finally
{
out.close();
}

Primefaces :radioButton inside a ui:repeat

This is 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:ui="http://java.sun.com/jsf/facelets"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:p="http://primefaces.org/ui">
<h:head>
<title>Custom Radio Test</title>
</h:head>
<h:body>
<h:form id="mF" >
<p:selectOneRadio id="ITRadioGrp" value="#{testBean.radioSelectedValue}" layout="custom">
<f:selectItems value="#{testBean.selectItems}" />
</p:selectOneRadio>
<h:panelGrid columns="1">
<ui:repeat id="vBGOF" value="#{testBean.groupOfFlights}" var="aFlight" varStatus="gofIndex">
<p:radioButton for="ITRadioGrp" itemIndex="#{gofIndex.index}"/> #{aFlight}
</ui:repeat>
</h:panelGrid>
</h:form>
</h:body>
</html>
and this is the managed bean :
package com.modern;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import javax.faces.model.SelectItem;
import java.util.*;
#ManagedBean
#RequestScoped
public class TestBean {
private String radioSelectedValue;
private String[] groupOfFlights;
private List selectItems;
public TestBean() {
groupOfFlights = new String[]{"FlightOne", "FlightTwo", "FlightThree"};
}
public String[] getGroupOfFlights() {
return groupOfFlights;
}
public void setGroupOfFlights(String[] groupOfFlights) {
this.groupOfFlights = groupOfFlights;
}
public String getRadioSelectedValue() {
return radioSelectedValue;
}
public void setRadioSelectedValue(String radioSelectedValue) {
this.radioSelectedValue = radioSelectedValue;
}
// modified
public List getSelectItems() {
try {
if (selectItems == null || selectItems.isEmpty()) {
selectItems = new ArrayList();
for (int g = 0; g < 3; g++) {
SelectItem option = new SelectItem(g, "flight" + (g + 1)); // value, label
selectItems.add(option);
}
}
} catch (Exception e) {
System.out.println(this.getClass().getName() + "] EXCEPTION " + e.toString());
}
return selectItems;
}
public void setSelectItems(List selectItems) {
this.selectItems = selectItems;
}
}
I always get the same error :
Cannot find component 'mF:ITRadioGrp' in view.
javax.faces.FacesException: Cannot find component 'mF:ITRadioGrp' in view.
at org.primefaces.component.radiobutton.RadioButtonRenderer.findSelectOneRadio(RadioButtonRenderer.java:144)
at org.primefaces.component.radiobutton.RadioButtonRenderer.encodeEnd(RadioButtonRenderer.java:35)
at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:875)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1763)
at com.sun.faces.facelets.component.RepeatRenderer.encodeChildren(RepeatRenderer.java:104)
at com.sun.faces.facelets.component.UIRepeat.process(UIRepeat.java:513)
at com.sun.faces.facelets.component.UIRepeat.encodeChildren(UIRepeat.java:974)
at com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.encodeRecursive(HtmlBasicRenderer.java:304)
at com.sun.faces.renderkit.html_basic.GridRenderer.renderRow(GridRenderer.java:185)
at com.sun.faces.renderkit.html_basic.GridRenderer.encodeChildren(GridRenderer.java:129)
at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:845)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1756)
at javax.faces.render.Renderer.encodeChildren(Renderer.java:168)
at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:845)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1756)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1759)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1759)
at com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:401)
at com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:131)
at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:121)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
I've tried to change the "for" attribute in
<p:radioButton for="mF:ITRadioGrp" itemIndex="#{gofIndex.index}"/> #{aFlight}
to (i checked the HTML source deleting the layout=custom" in p:selectOneRadio) :
mF:ITRadioGrp
ITRadioGrp
mF:ITRadioGrp:0
mF:ITRadioGrp:1 ...
but always same error!!
where i'm wrong???
Thanks!
Use a colon as prefix in order to address the p:selectOneRadio beginning from the view root:
<p:radioButton for=":mF:ITRadioGrp" itemIndex="#{gofIndex.index}"/>
If this does not work, look into the html source of your page in browser and find the correct client id for the p:selectOneRadio. Use this id in your for attribute.

Resources