2

I need to integrate pretty faces with my jsf 2.0, primefaces application, but its giving some troubles.

As mentioned in the getting started i placed following in my web.xml, added the required jar in the lib folder

<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>
 </filter-mapping>

other items in my web.xml

  <welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
  </welcome-file-list>
  <context-param>
        <param-name>com.sun.faces.expressionFactory</param-name>
        <param-value>org.jboss.el.ExpressionFactoryImpl</param-value>
  </context-param>
  <context-param>
        <param-name>org.primefaces.extensions.DELIVER_UNCOMPRESSED_RESOURCES</param-name>
        <param-value>false</param-value>
  </context-param>

But i am getting following Error:

Invalid content was found starting with element 'async-supported'. One of '{"http://java.sun.com/xml/ns/javaee":init-param}' is expected

If i remove <async-supported> from the project builds, project compiles but the mapping doesnt work.

pretty-config.xml is same as in the getting started.

Do i need to mention in my web.xml the name/path of the mapping file i.e pretty-config.xml?

EDIT:

I am using Glassfish server 3.

siebz0r
  • 18,867
  • 14
  • 64
  • 107
hitesh israni
  • 1,742
  • 4
  • 25
  • 48

1 Answers1

5

It is very important to check the version attribute you are using in your web.xml. If you have version="2.5" set, you have to add this to your web.xml:

<filter>
  <filter-name>Pretty Filter</filter-name>
  <filter-class>com.ocpsoft.pretty.PrettyFilter</filter-class>
</filter>
<filter-mapping> 
  <filter-name>Pretty Filter</filter-name> 
  <url-pattern>/*</url-pattern> 
  <dispatcher>FORWARD</dispatcher> 
  <dispatcher>REQUEST</dispatcher> 
  <dispatcher>ERROR</dispatcher>
</filter-mapping>

Please not that <async-supported>true</async-supported> is NOT set here, because it is only supported in Servlet 3.0.

If you have version="3.0" set in your web.xml, you don't have to add anything to your web.xml. In this case PrettyFaces automatically registers the filter using the web-fragment.xml that is included in prettyfaces-jsf2.jar.

You don't have to specify the location of pretty-config.xml anywhere. Just place it in your WEB-INF folder and PrettyFaces will find it.

You should also add one mapping to your pretty-config.xml, so you can check if everything works correctly. If you have for example a page that you typically access using an URL like:

http://localhost:8080/myapp/faces/login.xhtml

Then you can add this mapping:

<url-mapping id="login">
  <pattern value="/login" />
  <view-id value="/faces/login.xhtml" />
</url-mapping>

Now you should be able to access the page using this link:

http://localhost:8080/myapp/login
chkal
  • 5,598
  • 21
  • 26
  • i am using servlet version 2.5. and i think i have followed all the things that you mentioned. i will check if i missed some thing. thnx a lot! i will update/comment after trying. – hitesh israni Oct 15 '12 at 12:32
  • In this case you added the filter correctly (without async-supported). So if you see "PrettyFilter started" on the console and have a correct pretty-config.xml in your WEB-INF, everything should work fine. :) – chkal Oct 15 '12 at 12:36
  • also, if i use pretty url, should my ManagedBeans implement`Serializable`? – hitesh israni Oct 15 '12 at 12:44
  • Typically your managed beans are request scoped of your are using PrettyFaces. So you don't need to implement Serializable. – chkal Oct 15 '12 at 13:06
  • Was Christian's answer correct? If so, you should mark it as "accepted!" He deserves points for such a thorough answer! – Lincoln Oct 15 '12 at 15:31
  • +1 for the the clear and precise answer. Unfortunately, still i am facing some troubles. @Lincoln of course he does. thnx, guys for answering and commenting on my problem. – hitesh israni Oct 15 '12 at 17:59