I'm using JSF 2.0
this is my faces-config.xml
<?xml version="1.0" encoding="UTF-8"?>
<!-- This file is not required if you don't need any extra configuration. -->
<faces-config version="2.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-facesconfig_2_0.xsd">
<navigation-rule>
<from-view-id>/pages/test/test.html</from-view-id>
<navigation-case>
<from-outcome>write</from-outcome>
<to-view-id>/pages/test/test-write.html</to-view-id>
</navigation-case>
</navigation-rule>
</faces-config>
The TestController.java
#ManagedBean(name="testController")
#SessionScoped
public class TestController implements Serializable {
private static final long serialVersionUID = -3244711761400747261L;
public String test() {
return "write?faces-redirect=true";
}
in my test.xhtml file
<?xml version="1.0" encoding="UTF-8"?>
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
template="/WEB-INF/templates/default.xhtml">
<ui:define name="content">
<h:form>
<h:commandButton action="#{testController.test()}" value="test" />
</h:form>
</ui:define>
</ui:composition>
and this is my web.xml
<web-app 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"
version="3.0">
<display-name>Bachelor Demo</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>*.html</url-pattern>
</servlet-mapping>
</web-app>
What am I missing?
The view IDs should not contain the FacesServlet mapping. It should represent the physical file path/name. Change .html to .xhtml.
You should also remove ?faces-redirect=true and instead add a <redirect /> to the <navigation-case>.
<navigation-rule>
<from-view-id>/pages/test/test.xhtml</from-view-id>
<navigation-case>
<from-outcome>write</from-outcome>
<to-view-id>/pages/test/test-write.xhtml</to-view-id>
<redirect />
</navigation-case>
</navigation-rule>
By the way, this is the old JSF 1.x style. Are you aware of the new JSF2 implicit navigation? You could just return "/pages/test/test-write.xhtml?faces-redirect=true".
public String test() {
return "/pages/test/test-write.xhtml?faces-redirect=true";
}
No need for bloated XML navigation cases anymore.
Further, if your action method is really not doing anything else, then you can also just put exactly that return value in the action attribute instead.
<h:commandButton ... action="/pages/test/test-write.xhtml?faces-redirect=true" />
Even more, if it's plain page-to-page navigation, rather use <h:link> instead. It's more SEO friendly as searchbots don't index POST forms:
<h:link ... outcome="/pages/test/test-write.xhtml" />
Related
Im new to JSF 2. My question is related to BalusC's answer to this question jsf2 ajax update parts based on request parameters I tried the kickstart code BalusC posted and I encountered an EL parsing error:
/nameofpage.xhtml #12,64 rendered="#{bean.panels.contains('u1')}"
Error Parsing: #{bean.panels.contains('u1')}
I guess that this is caused because I'm not running a Servlet 3.0 / EL 2.2 capable container with a /WEB-INF/web.xml declared as per Servlet 3.0 spec. I'm using Tomcat 6.
BalusC suggested in his answer to create a custom EL function. But how do I accomplish this using a custom EL function? Or can this be fixed by just configuring certain parts of my project?
Below is my 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_2_5.xsd" version="2.5">
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.jsf</url-pattern>
</servlet-mapping>
<context-param>
<param-name>javax.faces.PROJECT_STAGE</param-name>
<param-value>Development</param-value>
</context-param>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
</web-app>
First create a final class with a public static method which does exactly the job you want:
package com.example;
import java.util.Collection;
public final class Functions {
private Functions() {
// Hide constructor.
}
public static boolean contains(Collection<Object> collection, Object item) {
return collection.contains(item);
}
}
Then define it as a facelet-taglib in /WEB-INF/functions.taglib.xml:
<?xml version="1.0" encoding="UTF-8"?>
<facelet-taglib
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-facelettaglibrary_2_0.xsd"
version="2.0">
<namespace>http://example.com/functions</namespace>
<function>
<function-name>contains</function-name>
<function-class>com.example.Functions</function-class>
<function-signature>boolean contains(java.util.Collection, java.lang.Object)</function-signature>
</function>
</facelet-taglib>
Then familarize Facelets with the new taglib in the existing /WEB-INF/web.xml:
<context-param>
<param-name>javax.faces.FACELETS_LIBRARIES</param-name>
<param-value>/WEB-INF/functions.taglib.xml</param-value>
</context-param>
(note: if you already have the javax.faces.FACELETS_LIBRARIES definied, then you can just add the new path semicolon separated)
Then define it in the Facelets XHTML file as new XML namespace:
<html
xmlns="http://www.w3.org/1999/xhtml"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:func="http://example.com/functions"
...
>
Finally you can use it as intended:
rendered="#{func:contains(bean.panels, 'u1')}"
As a completely different alternative, you can also include JBoss EL in your project. It works on Tomcat 6.0 and you'll be able to invoke non-getter methods in EL. Drop jboss-el.jar file in /WEB-INF/lib and add the following to your web.xml:
<context-param>
<param-name>com.sun.faces.expressionFactory</param-name>
<param-value>org.jboss.el.ExpressionFactoryImpl</param-value>
</context-param>
Since EL 2.2 there's another approach: create an #ApplicationScoped bean with methods in turn referring to those static functions. See also a.o. Utility methods in application scoped bean.
I have a problem in my NewFile.xhtml. I use jsf2.2.
When I put the library primefaces-3.5.jar into my web/lib folder and restart tomcat server, the web page does not work anymore. When I remove my PrimeFaces jar file every thing works without showing my PrimeFaces tags.
I put the external jar correctly, but I think there is something wrong:
my web.xml file
<!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>Sample JSF 2 Filter login app</display-name>
<!-- Login filter -->
<filter>
<filter-name>LoginFilter</filter-name>
<filter-class>somePackage.LoginFilter</filter-class>
</filter>
<!-- Set the login filter to secure all the pages in the /secured/* path of the application -->
<!-- Staring JSF -->
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<!-- JSF URL mapping -->
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.xhtml</url-pattern>
</servlet-mapping>
<!-- By default go to secured welcome page -->
<welcome-file-list>
<welcome-file>NewFile.xhtml</welcome-file>
</welcome-file-list>
</web-app>
my NewFile.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">
<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>
<h:body>
<h1>Hello World PrimeFaces</h1>
<h:form>
<p:editor value="#{editor.value}" />
</h:form>
</h:body>
</html>
As suggested on this post, Primefaces 3.5 does not support JSF 2.2, starting from 4.0 it has been supported.
You should consider a switch to the latest Primefaces release.
Read the documentation for more details: Primefaces User's Guide 3.5
I have been reading a lot of questions like this, but I'm not getting out of the trouble, and I'm starting to think that the problem is tomcat playing around.
First of all, here are my web.xml, my *-servlet.xml and my controller.
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">
<display-name>Spring REST Server</display-name>
<description>Spring REST Server</description>
<context-param>
<param-name>log4jConfigLocation</param-name>
<param-value>classpath:env/log4j.properties</param-value>
</context-param>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
classpath:config/applicationContext.xml
classpath:config/kimboo-servlet.xml
</param-value>
</context-param>
<context-param>
<param-name>webAppRootKey</param-name>
<param-value>Kimboo</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
</listener>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!-- Spring MVC Dispatcher Servlet -->
<servlet>
<servlet-name>kimboo</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>
classpath:config/applicationContext.xml
classpath:config/kimboo-servlet.xml
</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>kimboo</servlet-name>
<url-pattern>/home/</url-pattern>
</servlet-mapping>
</web-app>
This is my kimboo-servlet.xml
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">
<context:component-scan base-package="ar.com.kimboo.server.ui.controller" />
<mvc:annotation-driven />
<bean
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/AppClient/pages/" />
<property name="suffix" value=".html" />
</bean>
And this is my controller
#Controller
#RequestMapping(value = "/home")
public class HomeController {
#RequestMapping(value = "/")
public String home() {
return "login";
}
#RequestMapping(value = "/main")
public String main() {
return "main";
}
#RequestMapping(value = "/about")
public String main() {
return "about";
}
}
This is a pretty simple example, I don't know why isn't working. I have readed a lot of questions like this, here and in another sites, I don't know what I'm missing.
By the way, in the controller I tried all the convinations to match the url; put "/home/" or "home/" at the class level, and put "login" or "main" at method level.
The only thing that works is when I hit localhost:8080/myServer/home/. I tried using "/home/" in the url-pattern of the web.xml instead "/home/". I also tried use "/" and "/", but is the same.
The only way that this works is when in the url-pattern of the web.xml I use
<url-pattern>/home/</url-pattern>
<url-pattern>/home/main/</url-pattern>
<url-pattern>/home/login/</url-pattern>
Then I can hit all the url's. I don't know what to do, maybe this is a tomcat 7 problem?
you were not configured mapping for controller and annotation handler.Add this below bean configuration in the kimboo-servlet.xml and also add the respective jars.It may work.
<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter" />
<bean class="org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter" />
<bean id="simpleUrlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
<property name="mappings">
<value>
/home/**=homeController
</value>
</property>
</bean>
Rather than this being a TomCat problem I suspect this is a problem with how you have annotated the controller. Please replace your controller annotations as follows
#Controller
public class HomeController {
#RequestMapping(value = "/home")
public String home() {
return "login";
}
#RequestMapping(value = "/home/main")
public String main() {
return "main";
}
#RequestMapping(value = "home/about")
public String main() {
return "about";
}
}
This is only a guess. Sorry if I got it wrong. I remember seeing this problem in REST services. Maybe its the same.Dont have time to test it myself now.
Look at this question: Basic Spring MVC config: PageNotFound using InternalResourceViewResolver. The reason is your mapping which is too wide and interfere to JspServlet mapping.
I'm in the middle of learning Java EE with Trinidad but ran into some problem. The Trinidad 2.x examples use JSPX while their old demo site use pure JSF (XHTML). When I try to write the a test page using Facelets in XHTML, I kept getting java.lang.stackoverflowerror. I'm not sure if it's a configuration issue or a syntax error.
I'm using Glassfish V3, MySQL 5.6, JSF 2.1 (Apache MyFace) , Apache Trinidad 2.0. And I follow most of this guide: http://jianmingli.com/wp/?p=3813
Stack Trace I omitted the rest of the log because it's too long
java.lang.StackOverflowError
at java.net.URLStreamHandler.equals(URLStreamHandler.java:331)
at java.net.URL.equals(URL.java:862)
at java.util.concurrent.ConcurrentHashMap.get(ConcurrentHashMap.java:995)
at com.sun.faces.util.ExpiringConcurrentCache.get(ExpiringConcurrentCache.java:95)
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_2_5.xsd"
version="2.5">
<display-name>jsf2.myfaces2.trinidad2.one</display-name>
<!-- ================= JSF Settings ================= -->
<!-- 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 Mappings -->
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>/faces/*</url-pattern>
</servlet-mapping>
<!-- resource loader servlet -->
<servlet>
<servlet-name>resources</servlet-name>
<servlet-class>org.apache.myfaces.trinidad.webapp.ResourceServlet</servlet-class>
</servlet>
<!-- Important: You must include this adf mapping even though you are not
using ADF features. Without this mapping, JSF navigation will fail! -->
<servlet-mapping>
<servlet-name>resources</servlet-name>
<url-pattern>/adf/*</url-pattern>
</servlet-mapping>
<!-- setting the project stage to be DEVELOPMENT -->
<context-param>
<param-name>javax.faces.PROJECT_STAGE</param-name>
<param-value>Development</param-value>
</context-param>
<!-- Use client-side state saving. In Trinidad, it is an optimized, token-based
mechanism that is almost always a better choice than the standard JSF server-side
state saving. -->
<context-param>
<param-name>javax.faces.STATE_SAVING_METHOD</param-name>
<param-value>client</param-value>
<!--param-value> server</param-value -->
</context-param>
<!-- ================= Trinidad Settings ================= -->
<context-param>
<param-name>org.apache.myfaces.trinidad.USE_APPLICATION_VIEW_CACHE</param-name>
<param-value>false</param-value>
</context-param>
<context-param>
<param-name>org.apache.myfaces.trinidad.CHANGE_PERSISTENCE</param-name>
<param-value>session</param-value>
</context-param>
<context-param>
<param-name>javax.faces.FACELETS_VIEW_MAPPINGS</param-name>
<param-value></param-value>
</context-param>
<context-param>
<param-name>org.apache.myfaces.trinidad.ALTERNATE_VIEW_HANDLER</param-name>
<!-- TrinidadFaceletViewHander must be the alternate view handler if SessionChangeManager
is used -->
<param-value>org.apache.myfaces.trinidadinternal.facelets.TrinidadFaceletViewHandler</param-value>
</context-param>
<context-param>
<!--Unfortunately, Facelets provides no hook for plugging the PageResolver
into the logic handling "facelets.VIEW_MAPPINGS". You should leave "facelets.VIEW_MAPPINGS"
unset and use "org.apache.myfaces.trinidad.FACELETS_VIEW_MAPPINGS" instead. -->
<param-name>org.apache.myfaces.trinidad.FACELETS_VIEW_MAPPINGS</param-name>
<param-value>*.xhtml</param-value>
</context-param>
<filter>
<filter-name>trinidad</filter-name>
<filter-class>org.apache.myfaces.trinidad.webapp.TrinidadFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>trinidad</filter-name>
<servlet-name>faces</servlet-name>
</filter-mapping>
</web-app>
index.xhtml
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!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:trh="http://myfaces.apache.org/trinidad/html"
xmlns:tr="http://myfaces.apache.org/trinidad">
<ui:composition template="" >
<tr:table value="#{userTable.userList}" var="row">
<tr:column>
<f:facet name="header">
<tr:outputText value="User Name" />
</f:facet>
<tr:outputText value="#{row.username}" />
</tr:column>
<tr:column>
<f:facet name="header">
<tr:outputText value="Password" />
</f:facet>
<tr:outputText value="#{row.password}" />
</tr:column>
</tr:table>
</ui:composition>
</html>
index.jspx This works when I configure the "javax.faces.FACELETS_VIEW_MAPPINGS" to *.jspx and omit the Trinidad Facelets specific configuration in web.xml
<?xml version="1.0" encoding="iso-8859-1"?>
<jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" version="2.0"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:trh="http://myfaces.apache.org/trinidad/html"
xmlns:tr="http://myfaces.apache.org/trinidad">
<f:view>
<tr:document>
<tr:table value="#{userTable.userList}" var="row">
<tr:column>
<f:facet name="header">
<tr:outputText value="User Name" />
</f:facet>
<tr:outputText value="#{row.username}" />
</tr:column>
<tr:column>
<f:facet name="header">
<tr:outputText value="Password" />
</f:facet>
<tr:outputText value="#{row.password}" />
</tr:column>
</tr:table>
</tr:document>
</f:view>
</jsp:root>
The problem is fixed and I believe the ui:composition template="" was the cause of the StackOverFlowError. Once I removed the template="" bit, it worked. In addition, I came across the following in Apache Trinidad's mail archive regarding configuring web.xml for Trinidad 2.0 and Facelet:
You do not need to have an entry for ALTERNATE_VIEW_HANDLER with Trinidad 2.0.
You are getting the error because Trinidad is not yet compatible with
partial state saving in JSF 2.0.
Since partial state saving is enabled by default when Facelets are used,
you need to explicitly disable it.
Add the following context parameter in web.xml:
<context-param>
<param-name>javax.faces.PARTIAL_STATE_SAVING</param-name>
<param-value>false</param-value>
</context-param>
Link to Apache Trinidad mail post
Trinidad appears to cause a StackOverflowError when you use a relative path to a template in Faceletes. In your case, removing the extraneous template="" attribute from ui:component fixed the issue. In my case, I was actually using templates in my view, so I could not remove the attribute. Instead, I was able to work around the issue by using the absolute path to the template view.
For example, with the following view structure:
/views/template.xhtml
/view/index.xhtml
In index.xhtml, providing a relative path to template.xhtml causes a StackOverflowError:
<f:view
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets">
<ui:include src="template.xhtml" />
</f:view>
Changing to the absolute path of /views/template.xhtml fixes the StackOverflowError:
<f:view
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets">
<ui:include src="/views/template.xhtml" />
</f:view>
I am using GlassFishV3, JSF2, pretty faces 3
I have tried a lot of combinations of getting rid of my *.xhtml extension o prettify my URL, but I didn`t manage to do so.
Please if you know another solution give me an EXAMPLE of how to do it or if my solution is plausable please tell me were I gone wrong:
I followed the tutorial at http://ocpsoft.org/prettyfaces/ snd created a trivial app with just one index.xhtml and I have put a link to home.xhtml (both are in WebContent).
I have dwl the jar (I don`t use Maven) and I put it in WEB-INF/lib
according to the tutorial I don`t need to change my web.xml because in using GlassFishv3
my 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"
id="WebApp_ID" version="3.0">
<display-name>extension</display-name>
<welcome-file-list>
<welcome-file>index.xhtml</welcome-file>
</welcome-file-list>
<context-param>
<param-name>com.ocpsoft.pretty.DEVELOPMENT</param-name>
<param-value>true</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></web-app>
my pretty-config.xml
<pretty-config xmlns="http://ocpsoft.com/prettyfaces/3.3.3" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://ocpsoft.com/prettyfaces/3.3.3
http://ocpsoft.com/xml/ns/prettyfaces/ocpsoft-pretty-faces-3.3.3.xsd ">
<url-mapping id="home">
<pattern value="/home" />
<view-id value="/home.xhtml"/>
</url-mapping> </pretty-config>
with this configuration I keep getting java.lang.StackOverflowError (with others or my app doesn`t compile or I get a different error) the loop is
at com.sun.faces.facelets.impl.DefaultFacelet.include(DefaultFacelet.java:308)
at com.sun.faces.facelets.impl.DefaultFacelet.include(DefaultFacelet.java:367)
at com.sun.faces.facelets.impl.DefaultFacelet.include(DefaultFacelet.java:346)
at com.sun.faces.facelets.impl.DefaultFaceletContext.includeFacelet(DefaultFaceletContext.java:199)
at com.sun.faces.facelets.tag.ui.CompositionHandler.apply(CompositionHandler.java:155)
at com.sun.faces.facelets.compiler.NamespaceHandler.apply(NamespaceHandler.java:93)
at com.sun.faces.facelets.compiler.EncodingHandler.apply(EncodingHandler.java:86)
my index.xhtml works, but when I click on the link the above error appears
I don`t have any beans (another question would be if I have to put any anotations the the maped beans, if I manage to get pretty faces going)
Thank you very much for your time!
The modifications:
I did a trivial web app to see how the hiding of the extension works.
The index.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"><ui:composition template="">
<ui:define name="header">
Add your header here or delete to use the default
</ui:define>
<ui:define name="content">
<a id="home" href="home.xhtml">Home</a>
</ui:define>
<ui:define name="footer">
Add your footer here or delete to use the default
</ui:define></ui:composition>
and the 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">
<ui:composition template="">
<ui:define name="header">
Add your header here or delete to use the default
</ui:define>
<ui:define name="content">
home#######
</ui:define>
<ui:define name="footer">
Add your footer here or delete to use the default
</ui:define>
</ui:composition>
</html>
now if I start the app 127.0.01:8080/myapp there is an error instantly java.lang.StackOverflowError
but if I simply put in index.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">
<h:body>
<a id="home" href="home.xhtml">Home</a>
</h:body>
</html>
and in 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">
<h:body>
HOME
</h:body>
</html>
it works but the extension is prezent
started with 127.0.0.1:8080/myapp/ and then click on the link and 127.0.0.1:8080/myapp/home.xhtml
I want to do it like the first index and home with the template, because I work on a web app that already has templates.
The id="home" in the "a href" tag I dont know if it is necesary, the id its used by CSS to format it, but I am getting desprate :))
Any help would be appreciated. Thank you!
### MODIFICATIONS
so I started again with a trivial web app to see how pretty faces work
now I dont get any errors but I still cant change my URL
what have I done so far:
I put pretty-faces-jsf-3.3.3.jar in WEB-INF/lib
I put in WEB-INF pretty-config.xml
<?xml version="1.0" encoding="UTF-8"?><pretty-config xmlns="http://ocpsoft.com/prettyfaces/3.3.3"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://ocpsoft.com/prettyfaces/3.3.3
http://ocpsoft.com/xml/ns/prettyfaces/ocpsoft-pretty-faces-3.3.3.xsd">
<url-mapping id="home">
<pattern value="/home" />
<view-id value="/home.xhtml" />
</url-mapping>
my 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"
id="WebApp_ID" version="3.0">
<display-name>test</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
<context-param>
<param-name>com.ocpsoft.pretty.DEVELOPMENT</param-name>
<param-value>true</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></web-app>
in WEB-INF I have index.html, home.xhtml and template.xhtml
index.html
<!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">
<h:body>
HOME
</h:body>
</html>
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">
<ui:composition template="/tempate.xhtml">
<ui:define name="header">
Add your header here or delete to use the default
</ui:define>
<ui:define name="content">
########################
</ui:define>
<ui:define name="footer">
Add your footer here or delete to use the default
</ui:define>
</ui:composition>
</html>
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">
<head>
<title><ui:insert name="title">Default title</ui:insert></title>
</head>
<body>
<div id="header">
<ui:insert name="header">
Header area. See comments below this line in the source.
<!-- include your header file or uncomment the include below and create header.xhtml in this directory -->
<!-- <ui:include src="header.xhtml"/> -->
</ui:insert>
</div>
<div id="content">
<ui:insert name="content">
<ui:include src="home.xhtml" />
</ui:insert>
</div>
<div id="footer">
<ui:insert name="footer">
Footer area. See comments below this line in the source.
<!-- include your header file or uncomment the include below and create footer.xhtml in this directory -->
<!--<ui:include src="footer.xhtml"/> -->
</ui:insert> </div> </body></html>
I didn`t change my web.xml with
<web-app xmlns="http://java.sun.com/xml/ns/javaee" version="2.5"><filter>
<filter-name>Pretty Filter</filter-name>
<filter-class>com.ocpsoft.pretty.PrettyFilter</filter-class>
<async-supported>true</async-supported>
</filter>
<filter-mapping>
<filter-name>Pretty Filter</filter-name>
<url-pattern>/*</url-pattern>
<dispatcher>FORWARD</dispatcher>
<dispatcher>REQUEST</dispatcher>
<dispatcher>ERROR</dispatcher>
<dispatcher>ASYNC</dispatcher>
</filter-mapping></web-app>
because I use Glassfishv3
As I said it is a trivial web app, just to see how it works.
Please help me understand why I have difficulties...
I don't think this problem has anything to do with PrettyFaces. The stacktrace only shows some Facelets related stuff:
at com.sun.faces.facelets.impl.DefaultFacelet.include(DefaultFacelet.java:308)
at com.sun.faces.facelets.impl.DefaultFacelet.include(DefaultFacelet.java:367)
at com.sun.faces.facelets.impl.DefaultFacelet.include(DefaultFacelet.java:346)
at com.sun.faces.facelets.impl.DefaultFaceletContext.includeFacelet(DefaultFaceletContext.java:199)
at com.sun.faces.facelets.tag.ui.CompositionHandler.apply(CompositionHandler.java:155)
at com.sun.faces.facelets.compiler.NamespaceHandler.apply(NamespaceHandler.java:93)
at com.sun.faces.facelets.compiler.EncodingHandler.apply(EncodingHandler.java:86)
I saw that you are using an empty template attribute:
<ui:composition template="">
You page won't work without referencing a base template. I think this could cause the error you are getting.
BTW: You can test PrettyFaces without using Facelets templates. PrettyFaces doesn't known anything about the templates. So if it works without templates, it will also work with templates. :)