1
votes

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>
    <a href="home.xhtml">HOME</a>
</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...

1
Could you share the xhtml file? - chkal
I have edited my original question. - CyberGriZzly
What are the basic steps to set up pretty-faces? I do something definitely wrong... Everywhere it I look it says that it is really easy... - CyberGriZzly
It is really easy and described in the documentation. You could have a look at the Maven archetypes as a quick start: github.com/chkal/prettyfaces-archetypes/wiki - chkal
With you last modification you should see the home page if you enter localhost:8080/myapp/home in your browser. You question is quite confusing with all the modification sections. If it doesn't work, please post on ocpsoft.org/support and attach your sample app. I'm sure we will be able to help you there. - chkal

1 Answers

1
votes

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. :)