I have designed the following method and using that within managed beans:
public static void redirectToPrevious() {
FacesContext context = FacesContext.getCurrentInstance();
XSPContext xContext=XSPContext.getXSPContext(context);
xContext.redirectToPrevious();
}
It works as expected. It redirects to the previous page (or home page if there is not any).
However, everytime it works, it throws RedirectSignal error:
com.ibm.xsp.FacesExceptionEx: javax.faces.el.EvaluationException: com.ibm.xsp.acl.RedirectSignal
at com.ibm.xsp.util.DataPublisher.publishControlData(DataPublisher.java:204)
at com.ibm.xsp.component.UIDataPanelBase.publishControlData(UIDataPanelBase.java:310)
at com.ibm.xsp.component.UIDataPanelBase.initBeforeContents(UIDataPanelBase.java:451)
at com.ibm.xsp.component.UIIncludeComposite.initBeforePageContents(UIIncludeComposite.java:668)
at com.ibm.xsp.page.compiled.AbstractCompiledPage.initComponent(AbstractCompiledPage.java:339)
at com.ibm.xsp.page.compiled.AbstractCompiledPage.createTree(AbstractCompiledPage.java:256)
at com.ibm.xsp.page.compiled.AbstractCompiledPage.addComponent(AbstractCompiledPage.java:389)
at com.ibm.xsp.component.UIIncludeComposite.buildContents(UIIncludeComposite.java:453)
at com.ibm.xsp.page.compiled.AbstractCompiledPage.initComponent(AbstractCompiledPage.java:334)
at com.ibm.xsp.page.compiled.CompiledComponentBuilder.buildFacet(CompiledComponentBuilder.java:205)
at com.ibm.xsp.component.UICallback.buildContents(UICallback.java:180)
at com.ibm.xsp.page.compiled.AbstractCompiledPage.initComponent(AbstractCompiledPage.java:334)
at com.ibm.xsp.page.compiled.CompiledComponentBuilder.buildChildren(CompiledComponentBuilder.java:123)
at com.ibm.xsp.page.compiled.CompiledComponentBuilder.buildAll(CompiledComponentBuilder.java:84)
at com.ibm.xsp.extlib.component.layout.UIVarPublisherBase.buildContents(UIVarPublisherBase.java:97)
at com.ibm.xsp.page.compiled.AbstractCompiledPage.initComponent(AbstractCompiledPage.java:334)
at com.ibm.xsp.page.compiled.CompiledComponentBuilder.buildChildren(CompiledComponentBuilder.java:123)
at com.ibm.xsp.page.compiled.CompiledComponentBuilder.buildAll(CompiledComponentBuilder.java:84)
at com.ibm.xsp.component.UIIncludeComposite.buildPageContents(UIIncludeComposite.java:692)
at com.ibm.xsp.page.compiled.AbstractCompiledPage.initComponent(AbstractCompiledPage.java:340)
at com.ibm.xsp.page.compiled.AbstractCompiledPage.createTree(AbstractCompiledPage.java:256)
at com.ibm.xsp.page.compiled.AbstractCompiledPage.addComponent(AbstractCompiledPage.java:389)
at com.ibm.xsp.component.UIIncludeComposite.buildContents(UIIncludeComposite.java:453)
at com.ibm.xsp.page.compiled.AbstractCompiledPage.initComponent(AbstractCompiledPage.java:334)
at com.ibm.xsp.page.compiled.CompiledComponentBuilder.buildChildren(CompiledComponentBuilder.java:123)
at com.ibm.xsp.page.compiled.CompiledComponentBuilder.buildAll(CompiledComponentBuilder.java:84)
at com.ibm.xsp.component.UIViewRootEx.buildContents(UIViewRootEx.java:1649)
at com.ibm.xsp.component.UIViewRootEx2.buildContents(UIViewRootEx2.java:247)
at com.ibm.xsp.page.compiled.AbstractCompiledPage.initComponent(AbstractCompiledPage.java:334)
at com.ibm.xsp.page.compiled.AbstractCompiledPage.createTree(AbstractCompiledPage.java:256)
at com.ibm.xsp.page.compiled.AbstractCompiledPage.createViewRoot(AbstractCompiledPage.java:167)
at com.ibm.xsp.application.ViewHandlerExImpl._createViewRoot(ViewHandlerExImpl.java:521)
at com.ibm.xsp.application.ViewHandlerExImpl.createViewRoot(ViewHandlerExImpl.java:567)
at com.ibm.xsp.application.ViewHandlerExImpl.doCreateView(ViewHandlerExImpl.java:142)
at com.ibm.xsp.application.ViewHandlerEx.createView(ViewHandlerEx.java:90)
at com.ibm.xsp.webapp.FacesServlet.serviceView(FacesServlet.java:251)
at com.ibm.xsp.webapp.FacesServletEx.serviceView(FacesServletEx.java:157)
at com.ibm.xsp.webapp.FacesServlet.service(FacesServlet.java:160)
at com.ibm.xsp.webapp.FacesServletEx.service(FacesServletEx.java:138)
at com.ibm.xsp.webapp.DesignerFacesServlet.service(DesignerFacesServlet.java:103)
at com.ibm.designer.runtime.domino.adapter.ComponentModule.invokeServlet(ComponentModule.java:576)
at com.ibm.domino.xsp.module.nsf.NSFComponentModule.invokeServlet(NSFComponentModule.java:1315)
at com.ibm.designer.runtime.domino.adapter.ComponentModule$AdapterInvoker.invokeServlet(ComponentModule.java:853)
at com.ibm.designer.runtime.domino.adapter.ComponentModule$ServletInvoker.doService(ComponentModule.java:796)
at com.ibm.designer.runtime.domino.adapter.ComponentModule.doService(ComponentModule.java:565)
at com.ibm.domino.xsp.module.nsf.NSFComponentModule.doService(NSFComponentModule.java:1299)
at com.ibm.domino.xsp.module.nsf.NSFService.doServiceInternal(NSFService.java:662)
at com.ibm.domino.xsp.module.nsf.NSFService.doService(NSFService.java:482)
at com.ibm.designer.runtime.domino.adapter.LCDEnvironment.doService(LCDEnvironment.java:350)
at com.ibm.designer.runtime.domino.adapter.LCDEnvironment.service(LCDEnvironment.java:306)
at com.ibm.domino.xsp.bridge.http.engine.XspCmdManager.service(XspCmdManager.java:272)
Caused by: javax.faces.el.EvaluationException: com.ibm.xsp.acl.RedirectSignal
at com.sun.faces.el.MethodBindingImpl.invoke(MethodBindingImpl.java:142)
at com.ibm.xsp.actions.ExecuteScriptAction.invoke(ExecuteScriptAction.java:78)
at com.ibm.xsp.actions.ActionGroup.invoke(ActionGroup.java:135)
at com.ibm.xsp.model.AbstractDocumentDataSource.invoke(AbstractDocumentDataSource.java:299)
at com.ibm.xsp.model.AbstractDocumentDataSource.newDocument(AbstractDocumentDataSource.java:126)
at com.ibm.xsp.model.AbstractDocumentDataSource.load(AbstractDocumentDataSource.java:97)
at com.ibm.xsp.model.AbstractDataSource.getDataContainer(AbstractDataSource.java:474)
at com.ibm.xsp.model.domino.DominoDocumentData.getDataObject(DominoDocumentData.java:145)
at com.ibm.xsp.model.AbstractDataSource.pushData(AbstractDataSource.java:576)
at com.ibm.xsp.util.DataPublisher.publishControlData(DataPublisher.java:181)
... 50 more
Caused by: com.ibm.xsp.acl.RedirectSignal
at com.ibm.xsp.designer.context.XSPContext.renderPage(XSPContext.java:194)
at com.ibm.xsp.designer.context.XSPContext.redirectToPage(XSPContext.java:917)
at com.ibm.xsp.designer.context.XSPContext.redirectToPage(XSPContext.java:929)
at com.ibm.xsp.designer.context.XSPContext.redirectToPrevious(XSPContext.java:939)
at com.developi.toolbox.BeanUtils.redirectToPrevious(BeanUtils.java:57)
at com.hillside.flowng.beans.JobManager.postNewJob(JobManager.java:141)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:60)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:37)
at java.lang.reflect.Method.invoke(Method.java:611)
at com.sun.faces.el.MethodBindingImpl.invoke(MethodBindingImpl.java:138)
... 59 more
I can use try-catch and ignore the error but I'm not sure why this is happenning inside a managed bean but not in SSJS.
Any idea?
The RedirectSignal is not a java.lang.Exception, it is a java.lang.Error. That's why it is not catched with a default try/catch block. There are some other signals f.e. the NoAccessSignal or the ResponseCompleteSignal which are handled internally to stop processing requests and/or code execution, but are not "real" errors for the XPages servlet.
When redirecting to another page, the RedirectSignal is required to stop processing "useless" code and is catched in SSJS Interpreter. A button with this code...
print("BEFORE!");
context.redirectToPrevious();
print("AFTER");
will just send the BEFORE! to the console, the rest of the SSJS will not be executed.
You have to handle the RedirectSignal by your own (in the method of your bean) to prevent the printing to the console / the log.
XSPContext.getXSPContext(FacesContext) just uses the variable resolver to resolve the context variable, so this method should return a handle on the same object that context evaluates to within SSJS. So I'm not sure why you would see different behavior in different languages.
However, a RedirectSignal is only shown when recursion has been detected during a redirect. If I'm interpreting your stack trace correctly, refreshMode is set to partial on your event. All redirects must be performed from within a full refresh event.
Related
I have logic in my backing bean that redirects if there is a session timeout.
FacesContext.getCurrentInstance().getExternalContext().setResponseStatus(responseCode);
FacesContext.getCurrentInstance().getExternalContext().setResponseHeader("Location", redirectURL);
FacesContext.getCurrentInstance().responseComplete();
However, the page that is being loaded still attempts to render, and throws this error:
2021-11-27 08:02:50,774 ERROR [io.undertow.request] (default task-2) UT005023: Exception handling request to /dashboard/mypage.htm: javax.servlet.ServletException
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:236)
at io.undertow.servlet.handlers.ServletHandler.handleRequest(ServletHandler.java:74)
at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:129)
at org.apache.myfaces.webapp.filter.ExtensionsFilter.doFilter(ExtensionsFilter.java:294)
at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:61)
at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:131)
at org.apache.myfaces.webapp.filter.ExtensionsFilter.doFilter(ExtensionsFilter.java:357)
at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:61)
at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:131)
Caused by: java.lang.NullPointerException
at javax.el.ELUtil.buildParameters(ELUtil.java:699)
at javax.el.ELUtil.invokeMethod(ELUtil.java:243)
at javax.el.BeanELResolver.invoke(BeanELResolver.java:338)
at javax.el.CompositeELResolver.invoke(CompositeELResolver.java:198)
at com.sun.el.parser.AstValue.getValue(AstValue.java:111)
at com.sun.el.parser.AstValue.getValue(AstValue.java:179)
at com.sun.el.parser.AstDeferredExpression.getValue(AstDeferredExpression.java:39)
at com.sun.el.parser.AstCompositeExpression.getValue(AstCompositeExpression.java:44)
at com.sun.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:202)
at org.apache.myfaces.view.facelets.el.ContextAwareTagValueExpression.getValue(ContextAwareTagValueExpression.java:93)
at javax.faces.component._DeltaStateHelper.eval(_DeltaStateHelper.java:372)
at org.primefaces.component.menuitem.UIMenuItemBase.getUrl(UIMenuItemBase.java:91)
at org.primefaces.renderkit.MenuItemAwareRenderer.encodeOnClick(MenuItemAwareRenderer.java:67)
at org.primefaces.component.menu.BaseMenuRenderer.encodeMenuItem(BaseMenuRenderer.java:111)
at org.primefaces.component.menu.BaseMenuRenderer.encodeMenuItem(BaseMenuRenderer.java:69)
at org.primefaces.component.tieredmenu.TieredMenuRenderer.encodeElements(TieredMenuRenderer.java:124)
at org.primefaces.component.menubutton.MenuButtonRenderer.encodeMenu(MenuButtonRenderer.java:147)
at org.primefaces.component.menubutton.MenuButtonRenderer.encodeMarkup(MenuButtonRenderer.java:68)
at org.primefaces.component.menu.BaseMenuRenderer.encodeEnd(BaseMenuRenderer.java:50)
How can I get the view to stop loading on this workflow? It's obvious that, since the redirect occurred, the backing bean hasn't loaded everything and therefore EL expressions that depend on such objects being loaded, are failing.
I don't want to generate the error because this causes my admins grief because of the error emails that get generated. They can't tell if it is a real error or not.
Looks like you should have put some value on attribute in the request and that page uses that attribute and displays the nullPointer Exception as an error try to HttpServletRequest.setAttribute("bla", bla) nad check it.
I'm having trouble localizing a composite component (Mojarra 2.2, Glassfish 4.0).
I tried BalusC's solution here to put the properties file in the same directory as the composite component with the same file name as the composite component and a .properties extension -- that works to externalize the strings from the composite component's definition.
But when I want to localize the strings (by adding _en suffix to the property file's filename) I get this error (only thing changed is the name of the properties file):
[2013-08-08T13:49:04.234-0500] [glassfish 4.0] [WARNING] [] [javax.enterprise.web] [tid: _ThreadID=24 _ThreadName=http-listener-1(5)] [timeMillis: 1375987744234] [levelValue: 900] [[
StandardWrapperValve[Faces Servlet]: Servlet.service() for servlet Faces Servlet threw exception
java.lang.NullPointerException
at javax.faces.component.UIComponent.findComponentResourceBundleLocaleMatch(UIComponent.java:1204)
at javax.faces.component.UIComponent.getResourceBundleMap(UIComponent.java:1007)
at sun.reflect.GeneratedMethodAccessor1226.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at javax.el.BeanELResolver.getValue(BeanELResolver.java:363)
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.AstValue.getValue(AstValue.java:140)
at com.sun.el.parser.AstValue.getValue(AstValue.java:204)
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.ELText$ELTextVariable.writeText(ELText.java:227)
at com.sun.faces.facelets.compiler.TextInstruction.write(TextInstruction.java:85)
at com.sun.faces.facelets.compiler.UIInstructions.encodeBegin(UIInstructions.java:82)
at com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.encodeRecursive(HtmlBasicRenderer.java:302)
at com.sun.faces.renderkit.html_basic.GroupRenderer.encodeChildren(GroupRenderer.java:115)
at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:894)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1856)
...
I read an article (post from 24/Aug/12 03:50 PM) that JSF localizes differently than standard Java and that the properties files would go in resources/en/<library>/<component>.properties, so I put mycomp.properties there and got the error again.
My default locale is actually "en_US" -- I tried that as well with the same results.
So, this works:
resources/lib/mycomp.xhtml, resources/lib/mycomp.properties
These don't work:
resources/lib/mycomp.xhtml, resources/lib/mycomp_en.properties
resources/lib/mycomp.xhtml, resources/en/lib/mycomp.properties
What am I doing wrong?
I can reproduce your problem. This is quite embarrassing. Apparently something changed related to this in a newer Mojarra version. I can't get both the old and new approach to work in 2.2.0.
I peeked in the Mojarra source code again, starting at UIComponent#getResourceBundleMap(), and I learned that the resource bundle is first searched based on the FQN of the component's class. We could easily make use of it.
If not already done, first create a backing component class:
package com.example.composite;
#FacesComponent("myComposite")
public class MyComposite extends UINamingContainer {
// Can be kept empty.
}
And declare it in the composite component definition:
<cc:interface componentType="myComposite">
Then, you can simply put the MyComposite.properties, MyComposite_en.properties, etc in the very same com.example.composite package. It worked for me.
I am getting a servlet Exception "Stream closed" !!. I am not able to identify which jsp page is the problematic one or which line has the issue. It's showing the pagedefinition page as well as included pages.
As it is not easy to show all the pages attaching as a zip file : InGoogleDocs
The structure is like
pageDef.jsp Contains : allThings.jsp design.jsp myFile.jsp
The exception I got is as follows:
javax.servlet.jsp.JspException: ServletException in
'/layout/global/allThings.jsp': ServletException in
'/layout/body/design.jsp': ServletException in
'/layout/sub/design.jsp': ServletException in
'/module/air/myFile.jsp': Stream closed
at org.apache.struts.taglib.tiles.InsertTag$InsertHandler.doEndTag(InsertTag.java:920)
at org.apache.struts.taglib.tiles.InsertTag.doEndTag(InsertTag.java:460)
at org.apache.jsp.pagedef.air.pageDef_jsp._jspx_meth_tiles_insert_0(pageDef_jsp.java:1693)
at org.apache.jsp.pagedef.air.pageDef_jsp._jspService(pageDef_jsp.java:146)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:386)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at sun.reflect.GeneratedMethodAccessor70.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.catalina.security.SecurityUtil$1.run(SecurityUtil.java:270)
at org.apache.catalina.security.SecurityUtil$1.run(SecurityUtil.java:269)
at java.security.AccessController.doPrivileged(Native Method)
at javax.security.auth.Subject.doAsPrivileged(Subject.java:517)
at org.apache.catalina.security.SecurityUtil.execute(SecurityUtil.java:302)
at org.apache.catalina.security.SecurityUtil.doAsPrivilege(SecurityUtil.java:163)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:283)
at org.apache.catalina.core.ApplicationFilterChain.access$000(ApplicationFilterChain.java:56)
Important Note:
I am not getting this exception all the time.
when I go to the page (sometimes i will get the exception). If not getting , if I click back button in the jsp and coming back to the page will make the exception.
This problem is solved.
The problem was in a JSTL custom tag library's for-loop !!
How I solved(debugging JSP):
I made different copies of problematic file and included each of them in definition JSP.
Each of those problematic JSP files are edited in different areas as follows. If we do so, the error will be in only one/some JSP and so it is easy to find out the exception.
Say:
problematic-ORIGINAL.jsp
<jsp:for...></jsp>
<c:...>..</c>
...
problematic-1.jsp
<c:...>..</c>
problematic-2.jsp
<jsp:for...></jsp>
problematic-3.jsp
...
And then include 1,2 and 3 in definition JSP. Thus I could find the prob was in 2nd one. Enjoy coding ..
I'm getting a Null Pointer Exception when using my web app.
This exception is thrown at the login page. I enter both username and pass but it seems that the value or the evaluation of the expression #{userBean.user} or #{userBean.pass} is returning null.
My configuration: Apache Tomcat 7.0.22, Mojarra 2.1.6, RichFaces 4.1
Here's the stacktrace
javax.faces.el.EvaluationException: java.lang.NullPointerException
at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:102)
at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:102)
at javax.faces.component.UICommand.broadcast(UICommand.java:315)
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 org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:304)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:224)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:169)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:929)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:405)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:964)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:515)
at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:1824)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
at java.lang.Thread.run(Thread.java:722)
Caused by: java.lang.NullPointerException
at mx.gob.sagarpa.utilidades.Database.checkUser(Database.java:61)
at mx.gob.sagarpa.beans.UserBean.doLogin(UserBean.java:70)
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 org.apache.el.parser.AstValue.invoke(AstValue.java:262)
at org.apache.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:278)
at com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:105)
at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:88)
... 24 more
What can I do?
You need to head to the bottomost "Caused by" part of the stacktrace for the real root cause. In your particular case that is the following:
Caused by: java.lang.NullPointerException
at mx.gob.sagarpa.utilidades.Database.checkUser(Database.java:61)
You see, at line 61 of Database class, inside the checkUser() method, some object reference is null while the code is accessing it by the period operator ..
someObject = null;
someObject.doSomething(); // NullPointerException!
To fix it, you'd need to either add a nullcheck
if (someObject != null) {
someObject.doSomething();
} else {
// Take alternate path?
}
or to make sure that it's never null
someObject = createItSomehow();
someObject.doSomething(); // Okay.
Which path to take depends on the concrete functional requirement which is not clear from the question. But you should now at least understand why a NullPointerException can occur. This is also explained in its javadoc (which should be the #1 source for finding information about classes, including exceptions):
Thrown when an application attempts to use null in a case where an object is required. These include:
Calling the instance method of a null object.
Accessing or modifying the field of a null object.
Taking the length of null as if it were an array.
Accessing or modifying the slots of null as if it were an array.
Throwing null as if it were a Throwable value.
Applications should throw instances of this class to indicate other illegal uses of the null object.
That said, this problem is not exactly related to JSF. It's just basic Java. I'd suggest to take some time to go through a decent basic Java book/tutorial.
I have a problem in JSF2 with client side state saving and serialization. I have created a page with a full description and a small class diagram: http://tinyurl.com/jsf2serial. For the client-side state saving I have to implement Serializable at the classes Search, BackingBean and Connection. The exception that was thrown is:
java.io.NotSerializableException: org.apache.commons.httpclient.HttpClient
at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1156)
at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1509)
at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1474)
at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1392)
at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1150)
at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1509)
at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1474)
at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1392)
at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1150)
at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1509)
at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1474)
at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1392)
at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1150)
at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:326)
at java.util.HashMap.writeObject(HashMap.java:1001)
at sun.reflect.GeneratedMethodAccessor80.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at java.io.ObjectStreamClass.invokeWriteObject(ObjectStreamClass.java:945)
at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1461)
at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1392)
at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1150)
at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1509)
at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1474)
at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1392)
at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1150)
at java.io.ObjectOutputStream.writeArray(ObjectOutputStream.java:1338)
at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1146)
at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:326)
at java.util.HashMap.writeObject(HashMap.java:1001)
at sun.reflect.GeneratedMethodAccessor80.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at java.io.ObjectStreamClass.invokeWriteObject(ObjectStreamClass.java:945)
at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1461)
at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1392)
at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1150)
at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:326)
at com.sun.faces.renderkit.ClientSideStateHelper.doWriteState(ClientSideStateHelper.java:293)
at com.sun.faces.renderkit.ClientSideStateHelper.writeState(ClientSideStateHelper.java:167)
at com.sun.faces.renderkit.ResponseStateManagerImpl.writeState(ResponseStateManagerImpl.java:123)
at com.sun.faces.application.StateManagerImpl.writeState(StateManagerImpl.java:155)
at com.sun.faces.application.view.WriteBehindStateWriter.flushToWriter(WriteBehindStateWriter.java:221)
at com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:397)
at com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:126)
at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:127)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:313)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
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:298)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:852)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
at java.lang.Thread.run(Thread.java:637)
Maybe this is a problem of my design, because I am new in developing Java webapps.
The exception basically tells that you cannot (and should not) not store HttpClient in HttpSession. Apparently you've assigned it as a property of some session scoped bean. You should not do that. Either declare it transient or keep it threadlocal (i.e. only declare and use it in local method block, so that you can get rid of the property). The latter approach has my recommendation since HttpClient maintains some internal state which might make your application to break when it all get deserialized. If you'd like to have a long-living instance of it because recreating it is expensive, then I recommend to store it in an application scoped bean instead.