Null Pointer Exception in render response phase, JSF/Primefaces - jsf

In server log multiple errors can be found like below
java.lang.NullPointerException at
com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:95)
What can be the possible reason for this? Though I tried to recreate in I am unable to recreate after several attempt. Any possible reason or any idea related to this issue?
I need to understand why can we get null pointer exception while rendering response in JSF/Primeface?
primefaces v.3.4.1
javax.faces v.2.1.18
if I check the source code of JSF issue is at this line of source code
ViewDeclarationLanguage vdl =
vh.getViewDeclarationLanguage(facesContext,
facesContext.getViewRoot().getViewId());
javax.faces.STATE_SAVING_METHOD is set to server.

Check you xhtml file for any not closed tags or other xml/html issues. For example divs. Id your IDE doesn't do that, then change IDE or use online XML validators.

Related

Untraceable errors in XHTML templates caused by a missing space between attributes among (X)HTML tags

Have a simple question. Let's consider the following tag.
<h:inputText id="text" value="#{bean.value}"/>
If it is mistakenly written as follows.
<h:inputText id="text"value="#{bean.value}"/>
Please notice that there is no space between the id and the value attributes in this case. This is expected to be a parse error that should occur during parsing of the XHTML file possibly throwing an appropriate exception.
If it were to happen, absolutely nothing exceptional would be reported. No errors/exceptions would be thrown on the server-side. The target web page on the browser would then merely be left blank (white) in its entirely which would also indicate no errors as obvious on the client-side, since parsing of the file happens on the server-side.
Additional Information :
This already happened to me several times on XHTML files having several lines of code even though extreme care is exercised/taken. Mostly happens during copy/pasting which is many a times essential.
If it were to happen, the only way to trace the error was scan the XHTML document manually starting from the first line, all the way down to the last line (or the trace line, if one is caught) possibly scrolling in the middle through a long, ugly horizontal scroll bar on the IDE's GUI too.
Fortunately, I duplicated the same application twice - once using Java EE and again using Spring hereby XHTML code was same in both of the projects. I had been solving this problem as of now, since I began those applications in parallel by copy/pasting the whole XHTML code from one project to another, when it happened and I was unable to trace the line by average attempts. This is not always an alternative.
Can it get to throw an exception, when an XHTML document is mal-formed in this way? Are there someways to make it debuggable/traceable so that one can get rid of manual/tedious/time-consuming/eye-stretching tracing of an XHTML document?

Using binding attribute causes javax.faces.FacesException: Cannot find component with identifier

I have a problem I can't quite get a handle on.
First the context: I am developing a web application using Primefaces 3.5 (yes, unfortunately I am stuck with this old version for now), running on JBoss 7.
There is a form with id "form" encompassing all following xhtml code.
I have a component in my view which is provided by usage of the binding attribute:
<p:dashboard id="dashboard" binding="#{myBackingBean.dashboard}" />
Then sometimes I would like to perform an ajax update on this component, this is done by using the RemoteCommand component of primefaces:
<p:remoteCommand
actionListener="#{myBackingBean.someActionListener()}"
process="#this" id="myRmtCmd" oncomplete="myJsFunction();"
update=":form:dashboard" name="myRemoteCommand" />
The RemoteCommand is triggered by a clicking on a Link:
Some Text
This works pretty well so far. However after deploying this code to production I sometimes get a FacesException:
javax.faces.FacesException: Cannot find component with identifier ":form:dashboard"
referenced from "form:myRmtCmd".
This is where my problem lies because I cannot reliably reproduce this exception. My question is this: What could lead to this exception being thrown? It seems to work 95 % of the time but being the perfectionist I am (and many of you reading this are as well, I'm sure ;) ) I would like this code to work 100 % of the time. What am I missing?
Before answering please consider these constraints:
yes, i have to use the binding attribute for providing the dashboard as I need a great deal of control over what gets added to the component
to avoid using IDs I also tried updating the dashboard by its css class via one of primefaces' advanced selectors: #(.ui-dashboard) - this also does not work!
yes, it would be possible to use a commandbutton/link instead of wiring up the remotecommand component to a simple html link but in this case the link is rendered by a JSF renderer component and I made some bad experiences with dynamically adding buttons etc (due to JSF Spec Issue 790)
Cheers,
p.s.
I also had this weird behavior.
There are probably more than one component bindded to #{myBackingBean.dashboard}, so the first one sets the id and there will be no one called "dashboard".

How to catch runtime exceptions in jspx pages

This is in continuation with my previous question. I couldn't find solution for that. Hence I am trying to debug my application view layer jspx.
I realized that jspx is quite different from jsp, like it doesn't allow scriptlets. I know, that usage of this(scriptlets) is not at all recommended.
I have a particular SAP Net weaver server where hot deployment of jspx/jsp/html is not working. I have checked other alternatives like remote debugging, break points in jspx. But, its SAP net weaver, have some configuration issues. I have one option atleast to put sysouts, to trace runtime exceptions. But as its jspx files sysouts in scriptlets are not working. If it was jsp instead of jspx there, I could have traced/debugged the issues quickly using scriptlets temporarily until the issue got resolved atleast by using Sysouts.
Is there any equivalent code to this scriptlet(used in jsp)which we use very rarely.
<% System.out.println("The line above the null pointer exception : "+object.getPropery());%
Any equivalent code in jspx or icefaces components.
How do we debug a jspx page or handle exceptions inside a jspx page and find out errors.
Any eclipse plugins or tools available?

Faces messages not shown until the page is refreshed

I'm using JSF1.2, Tomcat 6.0, RichFaces 3.3.3, and Java 6u31.
I do an action in the managed bean, and show a message to the user. That's OK.
After that, I do another action in managed, and then the messages doesn't work anymore until I refresh the page.
I can assure you that the problem isn't in the managed bean, because I just removed all the method impl, leaving it empty, and the bug still happens.
So, the problem is something in the xhtml pages. I tried to put an a4j:status, but it doenst show any error.
So, I see myself without hope. I will not post all the code here, because it's too big and complex.
I wonder if one of you ever seen something like this, or if you have one guess of whats happening. I can edit the question adding any info you want.
I solve this problem.
I has a onupload in the rich:fileupload.
I just remove it, and add a a4j:support, like this:
<a4j:support event="onupload" oncomplete="foo()" />
That's it. I just don't understand why it works that way, and doesnt in the old way.
BTW, thanks.

Core Java Faces - 3rd edition (Cay Horstmann) : Chapter 4 selection tags pg 165 example not working

I'm not sure how i should put this question cos' there are couple of files (.java, .xhtml, etc) involved. Anyway this programs involves couple of checkboxes (selectmanycheckbox) and others. There is a onchange=submit() on this selectmanycheckboxes.
Here's what i noticed:
The generated html for each of those checkboxes there is a onchange=submit(). Kind of funny that by checking a checkboxes, it is submitting the form everytime.
The real issue is when i check one of the checkboxes, there is an error exactly as printed.
======================================================================
java.lang.ClassCastException: [I cannot be cast to [Ljava.lang.Object;
Caused by:
java.lang.ClassCastException - [I cannot be cast to [Ljava.lang.Object;
I don't understand the [I here. Any idea?
What i did after that was to remove all the checkboxes and submit the form. Still getting the same error.
Any idea?
The source code is available on their site. Your particular code is provided in javaee/ch04/select folder.
The generated html for each of those checkboxes there is a onchange=submit(). Kind of funny that by checking a checkboxes, it is submitting the form everytime.
It's been set by the <h:selectManyCheckbox onchange="submit()" /> in the code example. The onchange attribute is indeed totally unnecessary. It's likely an oversight of the author.
The real issue is when i check one of the checkboxes, there is an error exactly as printed.
java.lang.ClassCastException: [I cannot be cast to [Ljava.lang.Object;
I don't understand the [I here. Any idea?
The [I is the signature of an int[] type. The exception is telling that an instance of int[] type cannot be cast to an instance of Object[]. This makes in turn no sense, it should work fine. This particular problem is caused by something else.
What i did after that was to remove all the checkboxes and submit the form. Still getting the same error.
The <h:selectManyMenu> in the code example is also bound to an int[] property.
However removing them is not the right solution. It should work fine. Your problem is caused by something else deeper under the hoods. It's likely a bug in the EL implementation used. What servletcontainer make/version are you using? What servlet API version is your web.xml declared to? Did you try upgrading the servletcontainer?
I assume you are trying to run the example on Tomcat 6
Your WEB-INF/lib folder should have only these files: jsf-api.jar, jsf-impl.jar. You can download them from http://javaserverfaces.dev.java.net/
On your Tomcat/lib folder, you should replace the file el-api.jar by the file el-api2.2.jar. You can download it from http://download.java.net/maven/2/javax/el/el-api/2.2/

Resources