NullPointerException when using faces-config and PrimeFaces 4.0 - java

When using PrimeFaces and faces-config together, I get a NullPointerException. Before adding faces-config.xml, everything worked fine. After I added faces-config.xml for changing navigation, I got the following Error when calling every page:
java.lang.NullPointerException
org.primefaces.context.PrimeFacesContext.release(PrimeFacesContext.java:26)
javax.faces.webapp.FacesServlet.service(FacesServlet.java:612)
org.primefaces.webapp.filter.FileUploadFilter.doFilter(FileUploadFilter.java:98)
de.mypackage.CharacterEncodingFilter.doFilter(CharacterEncodingFilter.java:19)
The CharacterEncodingFilter just ensures usage of UTF-8:
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws ServletException, IOException {
request.setCharacterEncoding("UTF-8");
chain.doFilter(request, response);
}
So this can't be an error source. The faces-config.xml contains the following text:
<?xml version="1.0" encoding="UTF-8"?>
<faces-config xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_1_2.xsd"
version="1.2">
<navigation-rule>
<from-view-id>*</from-view-id>
<navigation-case>
<from-outcome>index</from-outcome>
<to-view-id>/index.jsf</to-view-id>
</navigation-case>
</navigation-rule>
This should direct every link to index to one index.jsf, not regarding in which folder the current site is. But if the faces-config.xml is just like this:
<?xml version="1.0" encoding="UTF-8"?>
<faces-config xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_1_2.xsd"
version="1.2">
the same error appears.
Everything is running on Tomcat 7.
The search for the error did not contain much results, in http://forum.primefaces.org/viewtopic.php?f=3&t=30109&start=10 someone seems to have the same problem with an old release of PrimeFaces 4.0, but as I'm getting it from maven, this can't be my error.
Has anybody an hint how to solve this problem?

The issue can be related to using JBoss Seam Mail and PrimeFaces 4.0:
http://forum.primefaces.org/viewtopic.php?f=3&t=34653
In my case, I used the PrimeFaces v3.4.2 and all worked perfectly.
After upgrade to official maven's PrimeFaces v4.0 the same NPE appears.
My faces-config.xml: <faces-config version="2.1">

Indeed, Primefaces 4 doesn't work with JSF 1.2 but it does work with JSF prior to 2.2.
From the Primefaces documentation:
PrimeFaces 4.0 supports JSF 2.0, 2.1 and 2.2 runtimes at the same time
using feature detection and by not having compile time dependency to a
specific version. As a result some features are only available
depending on the runtime.

Related

Web.xml not compiling correctly

I recently tried to convert an Eclipse, Google Appengine Project from java7-java8 since GAE has stopped supporting java7 (or will do in the near future).
The project was working fine before starting the conversion. I am now getting this error when trying to run the project locally:
java.lang.IllegalStateException: Multiple servlets map to path: /api/add-batch-shelfsurvey: ApiShelfSurveyBatchServlet,com.imobdev.figjam.ApiShelfSurveyBatchServlet
This is the entry in web.xml for that servlet:
<servlet>
<servlet-name>ApiShelfSurveyBatchServlet</servlet-name>
<servlet-class>com.imobdev.figjam.ApiShelfSurveyBatchServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>ApiShelfSurveyBatchServlet</servlet-name>
<url-pattern>/api/add-batch-shelfsurvey</url-pattern>
</servlet-mapping>
This is the start of the web.xml file:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
I've double and triple checked /api/add-batch-shelfsurvey path is unique in web.xml but I still get this error.
The servlet mentioned in the error message changes but none of them have multiple mappings to one path.
I've found these threads that seem similar but aren't actually related:
https://github.com/dropwizard/dropwizard/issues/2107
https://bugs.eclipse.org/bugs/show_bug.cgi?id=479865
I don't know if it's relevant but this is my appengine-web.xml file:
<appengine-web-app xmlns="http://appengine.google.com/ns/1.0">
<threadsafe>true</threadsafe>
<url-stream-handler>urlfetch</url-stream-handler>
<system-properties>
<property name="java.util.logging.config.file" value="WEB-INF/logging.properties"/>
<property name="appengine.file.encoding" value="US-ASCII"/>
</system-properties>
<sessions-enabled>true</sessions-enabled>
<runtime>java8</runtime>
</appengine-web-app>
It is because the path
/api/add-batch-shelfsurvey
might have been registered before try to check all
<servlet-mapping>
sections in web.xml and if you have any
#WebServlet annotations then check urlPatterns={"..."}
If you have two definitions at the same time app server will not know which is the right one.
I've managed to get the project to run on the localhost and upload and run on Google App Engine. Unfortunately I don't know exactly what the problem was.
These are the steps I took:
-Removed the /* from all in web.xml file.
-Changed between version 2.5 xsd and 3.1 xsd several times, running the project on localhost each time.
-Changed back to 2.5 xsd and changed all back to ending in /*
Project then compiled and ran fine on both localhost and appengine. If anyone knows anything more about why this might happen please let me know.

JasperException: Absolute uri cannot be resolved

I have been getting the following JasperException when trying to use an XML schema for my web.xml, instead of the deprecated DOCTYPE declaration:
HTTP Status 500 - The absolute uri: http://java.sun.com/jsp/jstl/core
cannot be resolved in either web.xml or the jar files deployed with this
application
If I use this web.xml, the application compiles:
<!DOCTYPE web-app PUBLIC
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd" >
<web-app>
<display-name>Archetype Created Web Application</display-name>
</web-app>
However, if I use this web.xml, I get the JasperException:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" version="3.1">
<display-name>CourseManagementJDBC</display-name>\
</web-app>
Any idea why only a deprecated format would work?
NOTE: This is for a Maven project, and the JSTL dependency has been correctly declared, as well as the tag library in the JSP:
pom.xml:
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
JSP:
<%# taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
They're all correct; what gives?
I finally came upon the solution. By default, for some reason (and I'd like to know why), Maven generates a Dynamic Web Module as version 2.3. DTD was of course the standard for Servlet 2.3 and was probably unable to parse or evaluate my XML-based web.xml file.
I'm still not 100% clear as to why changing web.xml to XSD caused the JasperException with respect to JSTL, though I think it has something to do with JSTL being integrated with JSP at some point after Servlet 2.3 - someone please correct or elaborate on this if possible.
See this: https://stackoverflow.com/a/4928309/2879303
Now for the solution:
Right-click on your Maven project and select Properties
Navigate to Project Facets and untick Dynamic Web Module. Apply
changes.
From the version drop-down box, select the latest version (as of
writing, this is 3.1). Re-select Dynamic Web Module. Apply changes.
Right-click on your Maven project and select Maven -> Update
Project.
Your project should now be able to correctly interpret a web.xml
with an XSD declaration.

JSTL Cannot be resolved error

I have seen similar questions and the answer suggested is place the JSTL jar in the classpath. I have tried both jstl.jar and jstl 1.1.jar bit My error is persistent. The Jars are coming in my web_inf/lib directory so I do not Understand what the problem is. I am using Tomcat 7
My Jsp:
<%#taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
.............
My Web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
<servlet>
......
My lib Directory After Deployment:
What Should I do I am running out of Options :P
Try using jstl-1.2.1 for Tomcat7
Download JSTL 1.2.1 jar
JSTL 1.1 also requires Standard.jar.
The standard.jar (taglib) library is used to enable the JSTL expression language in JSP page, and it’s always used together with the jstl.jar together.
Download and add it to your lib folder.
Or You can use JSTL 1.2 which does not require standard.jar and also provides performance improvements.

Duplicate fragment name ERROR Jetty Maven Plugin

I run the jetty-maven-plugin 8.0.0M2. Works fine after startup (mvn jetty:run) . If I change a source the plugin tries to hot deploy but gets stuck because of the following error
Duplicate fragment name: PrimeFaces for jar:file:/C:/path/to/project/webroot/WEB-INF/lib/primefaces-2.1.jar!/META-INF/web-fragment.xml and jar:file:/C:/path/to/project/webroot/WEB-INF/lib/primefaces-2.1.jar!/META-INF/web-fragment.xml
It worked fine with plugin version 7.2.0. I was upgrading because I needed el-api 2.2.
Any ideas? Thanks
Marcel
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<configuration>
...
<webAppConfig>
...
<allowDuplicateFragmentNames>true</allowDuplicateFragmentNames>
...
</webAppConfig>
...
</configuration>
</plugin>
I think we should fight the cause instead of hiding the problem. I.e. avoid duplicate fragments. In my case fragments with the same name came from different versions of Spring, so to solve the issue I had to manage my project's dependencies properly. Analyze by the error message where are the duplicates and think whether you really need both of them or is it a dependency conflict.
If you tried Stephen Connolly's fix and you are still are having issues, you may just need to modify a your web.xml slightly to get "allowDuplicateFragmentNames" to work.
In your WEB-INF/web.xml, look for the tag (should be at the top), and modify atributes to match these values:
<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/j2ee"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
metadata-complete="true"
..
>
<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" metadata-complete="true">
reference : http://forum.broadleafcommerce.org/viewtopic.php?f=13&t=2145
I had a hard time getting rid of the error. My mistake was that I used two different configuration tags with the same meaning:
<webApp>...</webApp> which I had already in my configuration and then copying <webAppConfig>...</webAppConfig> from the solution above. As I finally found out, webAppConfig is an alias for webApp. After getting rid of the alias and moving all configuration into the <webApp> section the error disappeared.
It looks to me as if one uses both, then the only the content from one section is used and the other one is ignored or reset.

JSP 2 and Servlet 2.4 broke my custom tags

We recently switched to Servlet 2.4 and JSP 2 on a project and our custom tags no longer work.
We have tags like:
<myTags:someTag value="${x}" />
and once in the tag we evaluated x bean and went from there. Now the evaluation happens directly in the JSP and we get a String (apparently x.toString()) set for the value attribute.
There are not a lot of tags and I could adapt them in a few days but how can I do that? I could not find anything on the web (or maybe I'm not looking where I should).
How do I pass the x bean to my tag and evaluate it there and not allow it to be evaluated in the JSP?
P.S. I do not want to deactivate the EL-engine
Thank you!
If you redeclare web.xml as Servlet 2.4 as follows
<web-app
xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
version="2.4">
and the tld file as JSP 2.0 taglib as follows:
<taglib
xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee/web-jsptaglibrary_2_0.xsd"
version="2.0">
Then you can add <rtexprvalue>true</rtexprvalue> entries to tag attributes in the TLD file which are expecting EL values. E.g.
<attribute>
<name>value</name>
<rtexprvalue>true</rtexprvalue>
</attribute>
It namely defaults to false.

Categories

Resources