Tomahawk JSCookMenu does not trigger any actions after upgrading to JSF2 - jsf-2

I've just migrated some medium-size web application from JSF 1.2/MyFaces to JSF 2.0/Mojarra. Apart from some custom components that I've implemented, everything seems to work, except for the JSCookMenu from Tomahawk (yes, I have Tomahawk which is a library from Apache, and still want to use Mojarra - but I understood there shouldn't be any big problem). I've replaced the myfaces-api.jar and myfaces-impl.jar with the corresponding jsf-api.jar and jsf-impl.jar, and took out from web.xml as many MyFaces parameters and filters as possible (some needed to remain because I still use Tomahawk). I have also upgraded Tomahawk to 1.1.11 for JSF2.
The application's JSCookMenu renders just fine, but doesn't trigger any action when clicking the menu items. I have some t:navigationMenuItem whose action attribute is bound to an outcome in faces-config.xml which should load a new view id, and yet some t:navigationMenuItem whose actionListener attribute is bound to a bean method (the Logout menu item, for example). Neither of them works, the actionListener code from my bean is not even called.
I'm not even sure how to investigate this, did anybody have a clue as to how can this be solved? I'm hoping something in web.xml can be of help.
The navigation cases are written correctly in the faces-config.xml, they used to work on JSF 1.2/MyFaces and also on JSF 2/MyFaces prior to the migration to Mojarra.
This is the relevant part of my web.xml file:
<servlet>
<servlet-name>faces</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>faces</servlet-name>
<url-pattern>*.xhtml</url-pattern>
</servlet-mapping>
<context-param>
<param-name>com.sun.faces.allowTextChildren</param-name>
<param-value>true</param-value>
</context-param>
<context-param>
<param-name>javax.faces.FACELETS_RESOURCE_RESOLVER</param-name>
<param-value>com.avalanche.jsf.MyResourceResolver</param-value>
</context-param>
<context-param>
<param-name>javax.faces.STATE_SAVING_METHOD</param-name>
<param-value>client</param-value>
</context-param>
<context-param>
<param-name>org.apache.myfaces.AUTO_SCROLL</param-name>
<param-value>true</param-value>
</context-param>
<context-param>
<param-name>facelets.DEVELOPMENT</param-name>
<param-value>true</param-value>
</context-param>
<context-param>
<param-name>facelets.RECREATE_VALUE_EXPRESSION_ON_BUILD_BEFORE_RESTORE</param-name>
<param-value>false</param-value>
</context-param>
<filter>
<filter-name>facesExtensionsFilter</filter-name>
<filter-class>org.apache.myfaces.webapp.filter.ExtensionsFilter</filter-class>
<init-param>
<param-name>uploadMaxFileSize</param-name>
<param-value>1g</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>facesExtensionsFilter</filter-name>
<servlet-name>faces</servlet-name>
</filter-mapping>
<filter-mapping>
<filter-name>facesExtensionsFilter</filter-name>
<url-pattern>/faces/myFacesExtensionResource/*</url-pattern>
</filter-mapping>

Related

index.html change to index.xhtml

When trying to logout my application I'm having the following error message :
com.sun.faces.context.FacesFileNotFoundException: /index.xhtml Not Found in ExternalContext as a Resource
To logout I'm going though the following steps inside PhaseListener.beforePhase(PhaseEvent phaseEvent) :
// Redirect to index.html
NavigationHandler nh = fctx.getApplication().getNavigationHandler();
String action_outcome = "/index.html";
nh.handleNavigation(fctx, null, action_outcome);
My web.xml is as follow :
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
id="WebApp_ID"
version="3.0">
<context-param>
<param-name>javax.faces.DEFAULT_SUFFIX</param-name>
<param-value>.xhtml</param-value>
</context-param>
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<filter-mapping>
<filter-name>Seam Filter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>trinidad</filter-name>
<servlet-name>Faces Servlet</servlet-name>
<dispatcher>FORWARD</dispatcher>
<dispatcher>REQUEST</dispatcher>
</filter-mapping>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.seam</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
<security-constraint>
<display-name>Restrict raw XHTML Documents</display-name>
<web-resource-collection>
<web-resource-name>XHTML</web-resource-name>
<url-pattern>*.xhtml</url-pattern>
</web-resource-collection>
<auth-constraint/>
</security-constraint>
<login-config>
<auth-method>BASIC</auth-method>
</login-config>
</web-app>
I do not have index.xhtml in my app, but I do have and want to keep it index.html file.
Why is my outcome_action given to NavigationHandler rename to index.xhtml ?
How could I avoid it ?
The NavigationHandler expects a JSF page, not a non-JSF page. Moreover, you're there actually not sending a real redirect at all, on the contrary to what the code comment says there. You're just performing a forward here.
Performing a real redirect would be the solution to your problem. It's to be done as below:
ExternalContext ec = FacesContext.getCurrentInstance().getExternalContext();
ec.redirect(ec.getRequestContextPath() + "/index.html");
See also:
What is the difference between redirect and navigation/forward and when to use what?
How to navigate in JSF? How to make URL reflect current page (and not previous one)
Unrelated to the concrete problem, doing authorization job in a phase listener stinks. Have you considered a servlet filter?
See also:
Limitations of using a PhaseListener instead of a Servlet Filter for authorization
Failing to redirect from JSF phaselistener
How to invalidate session in JSF 2.0?

JSF tags not rendered after filter implementation

I was working on a project that worked fine until I decided to implement filtering.
I followed BalusC's post on JSF HTTP Session Login .
Now, none of the jsf tags is rendered. Here is my web.xml file
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.1" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd">
<context-param>
<param-name>javax.faces.PROJECT_STAGE</param-name>
<param-value>Development</param-value>
</context-param>
<filter>
<filter-name>UserFilter</filter-name>
<filter-class>servlet.UserFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>UserFilter</filter-name>
<url-pattern>/faces/*</url-pattern>
</filter-mapping>
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet>
<servlet-name>ImageServlet</servlet-name>
<servlet-class>servlet.ImageServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>/faces/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>ImageServlet</servlet-name>
<url-pattern>/ImageServlet</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
<welcome-file-list>
<welcome-file>faces/admin/login.xhtml</welcome-file>
</welcome-file-list>
<context-param>
<param-name>primefaces.THEME</param-name>
<param-value>blitzer</param-value>
</context-param>
When I remove the filters everything works fine.
That answer was based on FacesServlet mapping of *.xhtml. However, you've there the old JSF 1.0/1.1 style mapping of /faces/*. In other words, the FacesServlet is never invoked and you was just seeing the consequences.
You've 2 options:
Fix the filter to redirect to an URL matching your FacesServlet mapping.
res.sendRedirect(req.getContextPath() + "/faces/login.xhtml");
Change the FacesServlet mapping to *.xhtml like every sane JSF 2.x developer would do. This saves you from fiddling with virtual URLs all time.
See also:
JSF Facelets: Sometimes I see the URL is .jsf and sometimes .xhtml. Why?
JSF returns blank/unparsed page with plain/raw XHTML/XML/EL source instead of rendered HTML output
Unrelated to the concrete problem, if you intend to let the filter hook on a specific servlet, you'd better not copy its URL pattern like below:
<filter-mapping>
<filter-name>UserFilter</filter-name>
<url-pattern>/faces/*</url-pattern>
</filter-mapping>
Instead, you'd better map to the servlet name directly:
<filter-mapping>
<filter-name>UserFilter</filter-name>
<servlet-name>Faces Servlet</servlet-name>
</filter-mapping>
And, it would also be nice if you followed Java variable naming conventions in filter and servlet names:
<filter-name>userFilter</filter-name>
...
<servlet-name>facesServlet</servlet-name>
Think of it as if you're doing like this:
UserFilter userFilter = new UserFilter();

jsf2 don't work ,url pattern

I created application with JSF2 Spring and Hibernate, but when I run it I obtain this error :
Tag Library supports namespace: http://primefaces.org/ui, but no tag was defined for name: clock javax.faces.webapp.FacesServlet.service(FacesServlet.java:606)
Take a look inside your web.xml and make sure you have :
<context-param>
<param-name>javax.faces.DEFAULT_SUFFIX</param-name>
<param-value>.xhtml</param-value>
</context-param>
Also that your view files are ending with .xhtml
Now you can change your default extension :
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.jsf</url-pattern>
</servlet-mapping>
Finally, make sure you changed your welcome file :
<welcome-file-list>
<welcome-file>index.jsf</welcome-file>
</welcome-file-list>
Hope this helps!

Faces Servlet not parsing .xhtml pages in jsf 2. running on tomcat 7

I am trying to create a JSF 2.0 application in eclipse with tomcat7. The project is running successfully but the jsf html and core components are not rendered in browser. I think Faces Servlet I have configured in web.xml.
Following is the web.xml file -
<welcome-file-list>
<welcome-file>faces/index.xhtml</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>/faces/*</url-pattern>
</servlet-mapping>
<context-param>
<description>State saving method: 'client' or 'server' (=default)</description>
<param-name>javax.faces.STATE_SAVING_METHOD</param-name>
<param-value>client</param-value>
</context-param>
<context-param>
<param-name>javax.servlet.jsp.jstl.fmt.localizationContext</param-name>
<param-value>resources.application</param-value>
</context-param>
<listener>
<listener-class>com.sun.faces.config.ConfigureListener</listener-class>
</listener>
I have my index.xhtml page outside WEB-INF. Its shown in browser but the jsf components are not see in browser. Can anyone please tell what is going wrong.
I have included following jars in WEB-INF/lib -
1. commons-annotations.jar
2. commons-beansutil.jar
3. commons-collection.jar
4. commons-digester.jar
5. commons-logging.jar
6. jsf-api.jar (from mojra 2.0)
7. jsf-impl.jar (from mojra 2.0)
8. jstl.jar
9. standard.jar
Thanks
Try these .. These were specified to me for my own question once..
You don't need and even should not include the JSF jars. Those are already part of Java EE.
Secondly, you definitely don't need and absolutely should not use the separate Facelets jar in combination with JSF 2.x. Facelets is already part of JSF 2.x.
You also should not include the JSTL jar. That one too is provided by Java EE. If u have commons jars by Apache commons, then those are fine but they are NOT needed for JSF. Include them only if you want to use them directly in your application code.
Try to get latest JSF (mojara 2.x).
Also you can modify your web.xml like this and try:
<welcome-file-list>
<welcome-file>index.xhtml</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.xhtml</url-pattern>
</servlet-mapping>
When I tried, I removed adding jsf jars separately. And it worked, displaying all the jsf tags. Also make sure you have all the required taglibs in your xhtml page, namely :
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:p="http://primefaces.org/ui"
xmlns:f="http://java.sun.com/jsf/core">
See if this works.
Please change your servlet mapping shown in your original question to
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.xhtml</url-pattern>
</servlet-mapping>
to make it work, i.e. to have your content (which is already happily served by Tomcat) rendered via JSF2.
I had this problem too, and as this question is the first result on google queries about JSF not parsing xhtml files, here is what I have done to solve:
In my case I had a dependency on weld-servlet, version 2.2.1, when I removed it from classpath the JSF started rendering.
Hope this help!

Stripes: all URLs resolved through StripesDispatcher and forwarded to pre-compiled JSPs

Is it possible to have the StripesDispatcher be the sole determiner of webserver urls by looking at the #UrlBinding annotations on action beans AND also having those action beans forward to pre-compiled JSPs / servlets WITHOUT needing to define and maintain <servlet> <servlet-mapping> pairs in web.xml? Basically, I just want to have to only maintain the #UrlBinding annotations as the sole determiners of available webapp paths.
Perhaps there is a way to point Jasper to where my servlets are and load them all up automatically without having to explicitly define each and every one?
The particular way in which this is achieved is not important, only that I leave the land of explicit servlet web.xml dependencies.
Maybe I don't understand your question, but I'll give it a go. AFAIK the only mapping you need in a Stripes app's web.xml to use #URLBinding as the 'source of truth' for URLs in your web-app:
<filter>
<filter-name>StripesFilter</filter-name>
<filter-class>net.sourceforge.stripes.controller.StripesFilter</filter-class>
<init-param>
<param-name>ActionResolver.Packages</param-name>
<param-value>com.your.action.beans.package</param-value>
</init-param>
<init-param>
<param-name>Extension.Packages</param-name>
<param-value>com.your.extension.packages</param-value>
</param-value>
</init-param>
</filter>
...
<servlet>
<servlet-name>DispatcherServlet</servlet-name>
<servlet-class>net.sourceforge.stripes.controller.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
...
<filter-mapping>
<filter-name>StripesFilter</filter-name>
<servlet-name>DispatcherServlet</servlet-name>
<dispatcher>REQUEST</dispatcher>
<dispatcher>FORWARD</dispatcher>
</filter-mapping>
<servlet-mapping>
<servlet-name>DispatcherServlet</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
With this, there is no need to change anything in web.xml when you add/remove action beans and/or JSPs.

Resources