Odd behavior in Java EE Web App when using PrimeFaces Components - jsf

The issue:
I have two <p:selectOneMenu> and when I drop the first menu down, I can not select any items in the menu, and once I click out of the menu I can not open the menu again. Then, if I open the second <p:selectOneMenu> I can select an item in the second menu, but then I can't open either menu again.
Trying to use a <p:pickList> and none of the buttons to move items around work.
<p:growl> functionally is non-existent, as is the action method never gets called.
I'm sure I could keep listing stuff that isn't working for me, but that is the three major components I am trying to use.
The setup:
A Java EE Web Application using JSF 2.3, JDK 18, primefaces-8.0.jar, on a Payara Server v5.2022.2, the primefaces-8.0.jar was imported to the library, and the source was declared as primfaces-8.0-sources.jar. My faces-config only defines a messages resource bundle and some navigation cases. As far as the web.xml it is pretty basic, see below:
<?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>
<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>
<session-config>
<session-timeout>
1440
</session-timeout>
</session-config>
<welcome-file-list>
<welcome-file>/index.xhtml</welcome-file>
</welcome-file-list>
<filter>
<filter-name>MyFilter</filter-name>
<filter-class>Filters.AuthFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>AuthFilter</filter-name>
<url-pattern>*.xhtml</url-pattern>
</filter-mapping>
</web-app>
Libraries:
index.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:h="http://xmlns.jcp.org/jsf/html"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets">
<h:head>
<title>Title</title>
<h:outputStylesheet library="css" name="primeflex3.1.2.css"/>
<h:outputStylesheet library="css" name="styles.css"/>
<h:outputStylesheet library="css" name="datatables.css"/>
<h:outputScript library="js" name="datatables.min.js"/>
</h:head>
<h:body>
<h:form>
<ui:include src="edit.xhtml"/>
</h:form>
</h:body>
</html>
edit.xhtml Code:
<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"
xmlns:p="http://primefaces.org/ui">
<ui:composition>
<h:form rendered="#{navBean.currentTabIndexIsEdit}" >
<center>
<h:outputLabel for="#next" value="Assigned Shop"/>
<p:selectOneMenu id="shops_menu" value="#{edit_Bean.job.shop_id}" appendTo="#this" >
<f:selectItem itemLabel="Select Shop" itemValue="" />
<f:selectItem itemValue="1" itemLabel="Broussard, Louisiana" />
<f:selectItem itemValue="2" itemLabel="North Louisiana" />
<f:selectItem itemValue="3" itemLabel="South Texas" />
<f:selectItem itemValue="4" itemLabel="West Texas" />
</p:selectOneMenu>
<h:outputLabel>Rig Name </h:outputLabel>
<p:selectOneMenu id="rigs_menu" value="#{edit_Bean.job.rig_id}" appendTo="#this">
<f:selectItems value="#{edit_Bean.rigs}" var="rigs" itemLabel="#{rigs.rig_name}" itemValue="#{rigs.rig_id}" />
</p:selectOneMenu>
<!-- Other Items -->
</center>
</form>
</ui:composition>
</html>
edit_Bean.java Code:
No much to put here, its just a named bean with a session scope with a few supporting methods.
Thanks for any help in advance!

The solution
If you see in index.xhtml, I am including a javascript file from datatables. That particular version of the JS file from data tables included its own jQuery version, which was conflicting with primefaces. I re-downloaded the datatables java script with out jQuery selected and it is now working.

Related

JSF Bootsfaces components not showing

Today I was working on our application for a school project. We had no problems with the our Bootsfaces but suddenly I can't seem to get the components to show (see image). I don't know what's causing this unexpected behaviour because it worked before. Nothing has been changed to the .xhtml page. The error log in the Chrome console and the Payara console are both giving 0 errors.
I am using Payara 5.181 and Java EE 7.
Edit:
Removing the "generated" folder in the Payara server and restarting the PC seems to solve this problem, but after a while (can't reproduce exactly why) the page turns blank again.
.xhtml file
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:b="http://bootsfaces.net/ui"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:f="http://xmlns.jcp.org/jsf/core">
<h:head>
<title>Kies je cartracker</title>
<h:outputStylesheet name="default.css" library="css" />
</h:head>
<h:body>
<h1>Kies je cartracker:</h1>
<b:dataTable value="#{tourmanager.allCartrackers}"
var="tracker">
<b:dataTableColumn>
<f:facet name="header">
<h:outputText value="Vehicle" />
</f:facet>
<h:outputText value="#{tracker.vehicle.serieNr}" />
</b:dataTableColumn>
<b:dataTableColumn>
<f:facet name="header">
<h:outputText value="Kies cartracker" />
</f:facet>
<h:form>
<b:commandButton action="#{tourmanager.pickCartracker(tracker)}"
value="Pick car" >
</b:commandButton>
</h:form>
</b:dataTableColumn>
</b:dataTable>
</h:body>
</html>
pom.xml
<dependency>
<groupId>net.bootsfaces</groupId>
<artifactId>bootsfaces</artifactId>
<version>1.2.0</version>
<scope>compile</scope>
</dependency>
web.xml
<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>
curiously in my case I had a similar problem, and it turns out that so many modifications and tests prove that this dependency in my pom.xml generated that the bootsfaces components were not rendered. My solution was to eliminate this dependence.
org.glassfishjavax.faces2.2.7

Uncaught ReferenceError: $ is not defined JSF Primefaces (h:head included)

I have a simple JSF page displaying a text editor from primefaces (Showcase).
However, the text editor is not displayed. When I inspect it (F12 in chrome), I see multiple errors, the first one is:
core.js.xhtml:2 Uncaught ReferenceError: $ is not defined
at Object.resolveUserAgent (core.js.xhtml:2)
at Object.init (core.js.xhtml:2)
at core.js.xhtml:2
The others are Uncaught TypeError: Cannot read property 'Tag from Primefaces' of undefined.
I read those questions: 1 / 2, but I do have a <h:head>.
What am I missing?
My page (index.xhtml):
<h:html xmlns="http://www.w3.org/1999/xhtml"
xmlns:b="http://bootsfaces.net/ui"
xmlns:p="http://primefaces.org/ui"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html">
<h:head>
<h:outputStylesheet library="css" name="style.css" />
<h:outputScript library="js" name="script.js" />
</h:head>
<h:body>
<p:textEditor value="#{textEditorController.text}" height="300" style="margin-bottom:10px"/>
<p:commandButton value="Submit" action="#{textEditorController.submit}"/>
</h:body>
</h:html>
My web.xml:
<?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>MusiglabelWEB</display-name>
<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>
<context-param>
<param-name>javax.faces.PARTIAL_STATE_SAVING</param-name>
<param-value>false</param-value>
</context-param>
<context-param>
<param-name>facelets.SKIP_COMMENTS</param-name>
<param-value>true</param-value>
</context-param>
</web-app>
I use muliple projects (WEB, JPA, EJB, EAR), if that matters.
Included Libraries in WEB Project:
Primefaces 6.1 (Downloaded here)
Bootsfaces 1.1.1 (Downloaded here)
This is a bug in PrimeFaces, I registered it here. It manifests when a p:textEditor is the first of PrimeFaces components in the final view.
To work around the bug simply add some other component before it, you can make it not rendered, so it won't affect your page otherwise:
<p:inputText rendered="false" />
<p:textEditor />
I got the same problem.
solved with importing both jquery and jquery ui like following
...
<h:head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.10.3/jquery-ui.min.js"></script>
</h:head>
...

primefaces tag not working in xhtml page

I am developing a jsf web application using primefaces tool for the ui tags. i'm having one problem in primefaces tag which is not working it show an exception like this
/templates/leftmenu.xhtml at line 10 and column 28 <p:tabMenu> Tag Library supports namespace: http://primefaces.org/ui, but no tag was defined for name: tabMenu
my leftmenu xhtml page
<!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"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:p="http://primefaces.org/ui">
<h:head></h:head>
<body>
<h:form>
<p:tabMenu activeIndex="0">
<p:menuitem value="Home" url="Menu.jsf" icon="ui-icon-star" />
<p:menuitem value="Fabricants" url="/pagess/pagesFabricant/Fabricant.jsf" icon="ui-icon-wrench" />
<p:menuitem value="Composants" url="/pagess/pagesComposant/Composant.jsf" icon="ui-icon-search" />
<p:menuitem value="Dossier d'equivalence" url="DEQ.jsf" icon="ui-icon-document" />
</p:tabMenu>
</h:form>
</body>
</html>
my template xhtml file
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.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"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:p="http://primefaces.org/ui">
<f:view contentType="text/html">
<h:head>
<f:facet name="first">
<meta content='text/html; charset=UTF-8' http-equiv="Content-Type"/>
<link type="text/css" rel="stylesheet" href="theme.css.jsf.css"/>
<title>Cation</title>
</f:facet>
</h:head>
<h:body>
<p:layout fullPage="true">
<p:layoutUnit position="north" size="100" resizable="true" closable="true" collapsible="true">
<p:graphicImage value="/logo.gif" />
</p:layoutUnit>
<p:layoutUnit position="south" size="40" closable="true" collapsible="true">
<span style="padding-left: 500px;">Company Name, Copyright 2013</span>
</p:layoutUnit>
<p:layoutUnit position="west" size="180" header="Menu" collapsible="true">
<ui:insert name="leftmenu">
<div>
<ui:include src="leftmenu.xhtml" />
</div>
</ui:insert>
</p:layoutUnit>
<p:layoutUnit position="center">
<ui:insert name="content">
Select one of the links on the left to proceed.
</ui:insert>
</p:layoutUnit>
</p:layout>
</h:body>
</f:view>
</html>
my web.xml file
<?xml version="1.0" encoding="UTF-8"?>
<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_2_5.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">
<display-name>Cation</display-name>
<context-param>
<param-name>javax.faces.PROJECT_STAGE</param-name>
<param-value>Development</param-value>
</context-param>
<welcome-file-list>
<welcome-file>faces/login.xhtml</welcome-file>
</welcome-file-list>
<listener>
<listener-class>org.apache.myfaces.webapp.StartupServletContextListener</listener-class>
</listener>
<context-param>
<param-name>primefaces.THEME</param-name>
<param-value>glass-x</param-value>
</context-param>
<context-param>
<param-name>javax.servlet.jsp.jstl.fmt.localizationContext</param-name>
<param-value>resources.application</param-value>
</context-param>
<context-param>
<description>State saving method: 'client' or 'server' (=default). See JSF Specification 2.5.2</description>
<param-name>javax.faces.STATE_SAVING_METHOD</param-name>
<param-value>client</param-value>
</context-param>
<context-param>
<description>
This parameter tells MyFaces if javascript code should be allowed in
the rendered HTML output.
If javascript is allowed, command_link anchors will have javascript code
that submits the corresponding form.
If javascript is not allowed, the state saving info and nested parameters
will be added as url parameters.
Default is 'true'</description>
<param-name>org.apache.myfaces.ALLOW_JAVASCRIPT</param-name>
<param-value>true</param-value>
</context-param>
<context-param>
<description>
If true, rendered HTML code will be formatted, so that it is 'human-readable'
i.e. additional line separators and whitespace will be written, that do not
influence the HTML code.
Default is 'true'</description>
<param-name>org.apache.myfaces.PRETTY_HTML</param-name>
<param-value>true</param-value>
</context-param>
<context-param>
<param-name>org.apache.myfaces.DETECT_JAVASCRIPT</param-name>
<param-value>false</param-value>
</context-param>
<context-param>
<description>
If true, a javascript function will be rendered that is able to restore the
former vertical scroll on every request. Convenient feature if you have pages
with long lists and you do not want the browser page to always jump to the top
if you trigger a link or button action that stays on the same page.
Default is 'false'
</description>
<param-name>org.apache.myfaces.AUTO_SCROLL</param-name>
<param-value>true</param-value>
</context-param>
<filter>
<filter-name>PrimeFaces FileUpload Filter</filter-name>
<filter-class>org.primefaces.webapp.filter.FileUploadFilter</filter-class>
<init-param>
<param-name>uploadDirectory</param-name>
<param-value>C:\</param-value>
</init-param>
<init-param>
<param-name>thresholdSize</param-name>
<param-value>1000000</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>PrimeFaces FileUpload Filter</filter-name>
<servlet-name>Faces Servlet</servlet-name>
</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-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>/faces/*</url-pattern>
<url-pattern>*.jsf</url-pattern>
<url-pattern>*.xhtml</url-pattern>
</servlet-mapping>
</web-app>
and i'm using primefaces 3.2 jar file
Can any one help me to solve this problem plz...
tabMenu is not supported in primefaces 3.2 version. Its been supported for version 3.4 and more.

PrimeFaces components are not rendered

I've developed an application using JSF with PrimeFaces. I've a problem in the Facelets page where <p:xxx> tags are not displayed in the page. Here is my Facelets page to display label, textbox and button. Only label is displayed in the page:
<!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://primefaces.org/ui"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:i="http://primefaces.prime.com.tr/touch"
xmlns:p="http://primefaces.org/ui">
<h:head></h:head>
<body>
<ui:composition template="/templates/template.xhtml">
<ui:define name="content">
<h:form>
<h:outputLabel for="curator" value="Name:" style="font-weight:bold"/>
<p:inputText id="curator" value="#{user.curator}" />
<p:commandButton value="Submit" update="display"/>
</h:form>
</ui:define>
</ui:composition>
</body>
</html>
my web.xml file
<?xml version="1.0" encoding="UTF-8"?>
<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_2_5.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">
<display-name>Cation</display-name>
<context-param>
<param-name>javax.faces.PROJECT_STAGE</param-name>
<param-value>Development</param-value>
</context-param>
<welcome-file-list>
<welcome-file>faces/login.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>
<listener>
<listener-class>org.apache.myfaces.webapp.StartupServletContextListener</listener-class>
</listener>
</web-app>
How is this caused and how can I solve it?
It seems the label is displaying because it is an h-tag whereas the other tags are p, so first off check whether your primefaces jar is implemented by checking the Libraries on your project (if using Netbeans ) or Java Resources\Libraries if on eclipse. The xmlns:p="http://primefaces.org/ui" is not sufficient to make primefaces work, it only specifies the namespace.
Note : you're tagging primefaces-extensions where I think primefaces tag is more relevant in your case.

How to redirect on JSF using PrimeFaces?

I'm trying to do a basic security system on JSF where if the user is not logged in and try to access a restricted page he will be redirected to login.xhtml. This is done in a servlet filter.
My problem is that when using resp.sendRedirect("login.xhtml"); the login page loses all resources, css, scripts, etc. So the page is displayed without any style.
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<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_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0">
<context-param>
<param-name>javax.faces.PROJECT_STAGE</param-name>
<param-value>Development</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>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.xhtml</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>30</session-timeout>
</session-config>
<welcome-file-list>
<welcome-file>index.xhtml</welcome-file>
</welcome-file-list>
<filter>
<filter-name>restrict</filter-name>
<filter-class>br.com.jetcar.filter.RestrictionFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>restrict</filter-name>
<url-pattern>*.xhtml</url-pattern>
<servlet-name>Faces Servlet</servlet-name>
</filter-mapping>
</web-app>
template.xhtml
<!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:h="http://java.sun.com/jsf/html"
xmlns:p="http://primefaces.prime.com.tr/ui"
xmlns:f="http://java.sun.com/jsf/core">
<h:head>
<h:outputScript library="primefaces" name="jquery/jquery.js"/>
<h:outputStylesheet library="css" name="template.css" />
<h:outputScript name="clock.js" library="js"></h:outputScript>
<title><ui:insert name="title">Bem-Vindo</ui:insert></title>
</h:head>
<body>
<p:growl id="messages"/>
<div id="header">
<ui:insert name="header">
<div id="headerTitle">JetCar</div>
<div id="clock"></div>
</ui:insert>
</div>
<div id="menu">
<ui:insert name="menu">
<ui:include src="menu.xhtml" />
</ui:insert>
</div>
<div id="content">
<ui:insert name="content">
</ui:insert>
</div>
<div id="footer">
<ui:insert name="footer">
<p>Desenvolvido por</p>
<p>Rodrigo Cavalcante de Souza</p>
<p>Jorge Luis</p>
</ui:insert>
</div>
</body>
</html>
login.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">
<ui:composition template="resources/template/template.xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.org/ui">
<ui:define name="title">Login</ui:define>
<ui:define name="content">
</ui:define>
</ui:composition>
The index.xhtml looks the sames as the login, since I'm still testing, what could be the problem?
error from chrome console
GET http://localhost:8080/JetCar/javax.faces.resource/growl/assets/login.xhtml 404 (Not Found)
login.xhtml:3GET http://localhost:8080/JetCar/javax.faces.resource/themes/sam/login.xhtml 404 (Not Found)
login.xhtml:6GET http://localhost:8080/JetCar/javax.faces.resource/jquery/login.xhtml 404 (Not Found)
login.xhtml:6GET http://localhost:8080/JetCar/javax.faces.resource/login.xhtml 404 (Not Found)
login.xhtml:6GET http://localhost:8080/JetCar/javax.faces.resource/core/login.xhtml 404 (Not Found)
login.xhtml:4GET http://localhost:8080/JetCar/javax.faces.resource/login.xhtml 404 (Not Found)
login.xhtml:6GET http://localhost:8080/JetCar/javax.faces.resource/growl/login.xhtml 404 (Not Found)
login.xhtml:10Uncaught ReferenceError: jQuery is not defined
chrome-extension://ffdcfjdljhbehggjdkdioajnknjcpbjb/js/sbc_cookies_mon.js:1Uncaught TypeError: Cannot read property 'tagName' of null
I'm using primefaces 2.2.1, glassfish 3.1, JSF 2.0
EDIT: I just noticed that the resources use the .xhtml extension as well, so it was interfering with the filter.
FIX:if(req.getSession().getAttribute("func") == null && !pageRequested.contains("login.xhtml") && !pageRequested.contains("/javax.faces.resource"))
resp.sendRedirect("login.xhtml");
I often use this way to redirect it directly from Java Bean:
FacesContext.getCurrentInstance().getExternalContext().redirect(Url);
The proper way of redirecting pages on JSF specially in JSF 2 is returning the name of the view from the method call:
For example:
public String doLogin() {
//apply the login logic.
return "name/of/the/view?facesRedirect=true"
}
Your filter is redirecting HTTP requests to JSF resources as well. You need to change your filter logic to add a check if the current request isn't a JSF resource request. You can do that by checking if the request URI does not start with ResourceHandler.RESOURCE_IDENTIFIER after the context path.
if (request.getRequestURI().startsWith(request.getContextPath() + ResourceHandler.RESOURCE_IDENTIFIER)) {
chain.doFilter(request, response);
}
else {
response.sendRedirect(request.getContextPath() + "/login.xhtml");
}

Resources