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");
}
Related
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.
I tried to make a hello world program in jsf. I want to run xhtml file in eclipse (I still haven't used Java), but I can't start it. I get only general error
HTTP Status 404 – Not Found: Description The origin server did not find a current representation for the target resource or is not willing to disclose that one exists.
My other .jsp files run without problem. When I run the xhtml file, this is exact link showing in a browser: http://localhost:8080/JSFProjectHello/faces/hello-world.xhtml There are files of the jsf project:
/JSFProjectHello/WebContent/hello-world.xhtml
<!DOCTYPE html>
<html lang="en"
xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:a="http://xmlns.jcp.org/jsf/passthrough">
<h:head>
<title>Hello World - Input Form</title>
</h:head>
<h:body>
<h:form>
<h:inputText id="name" value="#{theUserName}"
a:placeholder="What's your name?" />
<h:commandButton value="Submit" action="myresponse" />
</h:form>
</h:body>
</html>
.
/JSFProjectHello/WebContent/hello-world.xhtml
<!DOCTYPE html>
<html lang="en"
xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html">
<h:head>
<title>Hello World - Response</title>
</h:head>
<h:body>
Hello, #{theUserName}
</h:body>
</html>
.
/JSFProjectHello/WebContent/WEB-INF/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_4_0.xsd" id="WebApp_ID" version="4.0">
<display-name>JSFProjectHello</display-name>
<welcome-file-list>
<welcome-file>hello-world.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>
</web-app>
.
Finally, I should add I use Java8 and as a server Tomcat9. And I've imported this library into the project:
/JSFProjectHello/WebContent/WEB-INF/lib/javax.faces-2.2.8-sources.jar
So I found an error finally. I downloaded incorrect library javax.faces-2.2.8-sources.jar, the correct one should be javax.faces-2.2.8.jar
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>
...
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.
This is my first attempt at using JSCookMenu and its homepage (http://jscook.yuanheng.org/JSCookMenu/) has been down for more than a week, so forgive me if the answer to my question should appear on there.
I have a simple web app, stripped down in order to test JSCookMenu's action forwarding to a new JSF page.
I have an admin page with a JSCookMenu (Apache MyFaces Tomahawk tags) with 2 menu items, 'Home Without AL' and 'Home With AL'. I expect that when I click on these menu items that I will navigate to the 'home' page which will just display a 'Hello World' message for now. This navigation is not happening, however. A push in the right direction would be greatly appreciated :-)
Here's my faces-config, my admin page (which uses layout page), my home page, my web.xml (with filter mapped) and a description of what happens when I click on the menu item.
faces-config.xml:
<!-- Copyright 2004-2006 Sun Microsystems, Inc. All rights reserved.
SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. -->
<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">
<!-- from project setup -->
<application>
<view-handler>com.sun.facelets.FaceletViewHandler</view-handler>
</application>
<navigation-rule>
<navigation-case>
<from-outcome>go_home</from-outcome>
<to-view-id>/home.jsp</to-view-id>
</navigation-case>
</navigation-rule>
</faces-config>
layout.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:m="http://code.google.com/p/gmaps4jsf/">
<head>
<title>
<ui:insert name="title">Beach Water Quality</ui:insert>
</title>
<!-- JSCook Menu -->
<script language="JavaScript" src="jscookmenu/JSCookMenu.js" type="text/javascript" />
<script language="JavaScript" src="jscookmenu/ThemeOffice/theme.js" />
<link rel="stylesheet" href="jscookmenu/ThemeOffice/theme.css" type="text/css" />
<script language="JavaScript" src="jscookmenu/ThemeMiniBlack/theme.js" />
<link rel="stylesheet" href="jscookmenu/ThemeMiniBlack/theme.css" type="text/css" />
<script language="JavaScript" src="jscookmenu/ThemeIE/theme.js" />
<link rel="stylesheet" href="jscookmenu/ThemeIE/theme.css" type="text/css" />
<script language="JavaScript" src="jscookmenu/ThemePanel/theme.js" />
<link rel="stylesheet" href="jscookmenu/ThemePanel/theme.css" type="text/css" />
<script language="JavaScript" src="jscookmenu/ThemeGray/theme.js" />
<link rel="stylesheet" href="jscookmenu/ThemeGray/theme.css" type="text/css" />
<script language="JavaScript" src="jscookmenu/ThemeOffice2003/theme.js" />
<link rel="stylesheet" href="jscookmenu/ThemeOffice2003/theme.css" type="text/css" />
</head>
<body onLoad="#{onload}">
<h:panelGrid id="container_div" forceId="true" >
<ui:insert name="header">
<ui:include src="header.xhtml"/>
</ui:insert>
<ui:insert name="content">
<!-- include default content in here -->
</ui:insert>
<ui:insert name="footer">
<ui:include src="footer.xhtml"/>
</ui:insert>
</h:panelGrid>
</body>
</html>
admin.jsp:
<jsp:forward page="admin.jsf"/>
admin.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:f="http://java.sun.com/jsf/core"
xmlns:m="http://code.google.com/p/gmaps4jsf/"
xmlns:c="http://java.sun.com/jstl/core"
xmlns:t="http://myfaces.apache.org/tomahawk" >
<ui:composition template="/WEB-INF/layout/layout.xhtml">
<ui:define name="content">
<f:view contentType="text/html">
<h:form id="form" >
<t:jscookMenu layout="vbr" theme="ThemeIE">
<t:navigationMenuItem itemLabel="Home" itemValue="go_home" action="go_home"/>
</t:jscookMenu>
</h:form>
</f:view>
</ui:define>
</ui:composition>
</html>
home.jsp:
<jsp:forward page="/home.jsf"/>
home.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:f="http://java.sun.com/jsf/core"
xmlns:m="http://code.google.com/p/gmaps4jsf/"
xmlns:c="http://java.sun.com/jstl/core" >
<ui:composition template="/WEB-INF/layout/layout.xhtml">
<ui:define name="content">
<f:view contentType="text/html">
<h:form id="form" >
<h:outputText value="Hello World"/>
</h:form>
</f:view>
</ui:define>
</ui:composition>
</html>
web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<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">
<description>Beachwater web.xml</description>
<!-- Use Documents Saved as *.xhtml -->
<context-param>
<param-name>javax.faces.DEFAULT_SUFFIX</param-name>
<param-value>.xhtml</param-value>
</context-param>
<!-- Special Debug Output for Development -->
<context-param>
<param-name>facelets.DEVELOPMENT</param-name>
<param-value>true</param-value>
</context-param>
<!-- Optional JSF-RI Parameters to Help Debug -->
<context-param>
<param-name>com.sun.faces.validateXml</param-name>
<param-value>true</param-value>
</context-param>
<context-param>
<param-name>com.sun.faces.verifyObjects</param-name>
<param-value>true</param-value>
</context-param>
<!-- Faces Servlet -->
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<!-- Faces Servlet Mapping -->
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.jsf</url-pattern>
</servlet-mapping>
<!-- This is for File Upload -->
<filter>
<filter-name>MyFacesExtensionsFilter</filter-name>
<filter-class>org.apache.myfaces.webapp.filter.ExtensionsFilter</filter-class>
<init-param>
<description>Set the size limit for uploaded files.
Format: 10 - 10 bytes
10k - 10 KB
10m - 10 MB
1g - 1 GB
</description>
<param-name>uploadMaxFileSize</param-name>
<param-value>20m</param-value>
</init-param>
<init-param>
<description>
Set the threshold size - files below this limit are stored
in memory, files above this limit are stored on disk.
Format: 10 - 10 bytes
10k - 10 KB
10m - 10 MB
1g - 1 GB
</description>
<param-name>uploadThresholdSize</param-name>
<param-value>100k</param-value>
</init-param>
<init-param>
<description>
Set the path where the intermediary files will be stored.
</description>
<param-name>uploadRepositoryPath</param-name>
<param-value>/temp</param-value>
</init-param>
</filter>
<!-- extension mapping for adding <script/>, <link/>, and other resource tags to JSF-pages -->
<filter-mapping>
<filter-name>MyFacesExtensionsFilter</filter-name>
<!-- servlet-name must match the name of your javax.faces.webapp.FacesServlet entry -->
<servlet-name>Faces Servlet</servlet-name>
</filter-mapping>
<!-- extension mapping for serving page-independent resources (javascript, stylesheets, images, etc.) -->
<filter-mapping>
<filter-name>MyFacesExtensionsFilter</filter-name>
<url-pattern>/faces/myFacesExtensionResource/*</url-pattern>
</filter-mapping>
</web-app>
I have tomahawk12-1.1.9.jar in my classpath (also tried tomahawk-1.1.9.jar), which I downloaded from http://myfaces.apache.org/tomahawk/download.html.
I have a jscookmenu folder at the root of my webapp, containing a folder for each theme (each with theme.css and theme.js), effect.js and the JSCookMenu.js from jscookmenu-2.0.4.zip, all of which I downloaded from http://sourceforge.net/projects/jscook/files/. Latest release was 2009-05-25.
The web app is deployed on Sun GlassFish Enterprise Server v2.1 on localhost.
I browse to http://localhost:8080/beachwater/admin.jsp and click on the Home menu item.
New window is opened with address bar, "http://localhost:8080/beachwater/form_j_id7_menu:A%5Dgo_home" and content, "Glassfish error page, HTTP Status 404: The requested resource () is not available."
Nothing gets written to the server.log
The window is being opened by the cmItemMouseUp function in JSCookMenu.js. Do I have the wrong version of the javascript? Any ideas why the filter isn't invoking the action specified in faces-config?
It turns out that the 'Instructions' section on http://myfaces.apache.org/tomahawk-project/tomahawk12/tagdoc/t_jscookMenu.html is out of date. It is no longer necessary to...
Add jscookmenu directory containing css and scripting code to your web directory (you can find it in the examples application).
Add scripts and stylesheets for the theme you would like to use to html-header (see also inc/header.inc in the examples application)
... as these are now contained in the tomahawk jar. So I removed the aforementioned jscookmenu folder from the root of my webapp, as well as these from the head of layout.xhtml:
<!-- JSCook Menu -->
<script language="JavaScript" src="jscookmenu/JSCookMenu.js" type="text/javascript" />
<script language="JavaScript" src="jscookmenu/ThemeOffice/theme.js" />
<link rel="stylesheet" href="jscookmenu/ThemeOffice/theme.css" type="text/css" />
etc.
I also hadn't included *.jsp in my filter-mapping in web.xml, so I added as follows:
<filter-mapping>
<filter-name>extensionsFilter</filter-name>
<url-pattern>*.jsp</url-pattern>
</filter-mapping>
By now, the menu was rendering on the page.
When I then tried to navigate from one page to another, I got this error:
dummyForm.elements.jscook_action is undefined
, which I solved by adding this to admin.jsp, as suggested by http://forums.sun.com/thread.jspa?forumID=427&threadID=761310:
<input type="hidden" id="jscook_action" name="jscook_action" />
Hope this helps someone, as the JSCookMenu website is still down and help seems to be pretty thin on the ground elsewhere.