Using Tomcat 7 --- Primefaces 3.4.1 --- javax faces 2.1.17 --- prettyfaces-jsf2 3.3.3
I configured pretty faces on my project correctly but my web filters are not working with new urls which are written by pretty faces.
Here is an example pretty-config.xml
<url-mapping id="home">
<pattern value="/home"/>
<view-id value="/secure/homepage.xhtml"/>
</url-mapping>
<url-mapping id="register">
<pattern value="/register"/>
<view-id value="/public/register.xhtml"/>
</url-mapping>
<url-mapping id="welcome">
<pattern value="/"/>
<view-id value="/public/welcome.xhtml"/>
</url-mapping>
<url-mapping id="profile">
<pattern value="/profile/#{userId}"/>
<view-id value="/profile.xhtml"/>
</url-mapping>
login(welcome) and register pages are in "public" folder, and their web filter is defined with annotation : @WebFilter("/public/*")
for my home page in "secure" folder (exactly there will be more pages in the folder), i defined a web filter also and its annotation : @WebFilter("/secure/*)
pretty urls are working fine, but these filters are only working when i write the original urls.
1) How can i repair my webfilters ?
2) I also want to block user for entering original url. I know that pretty faces is hiding original urls fully but is there a way to do it ?
-- SOLVED -- thanks for BalusC
if you defined your filters with annotations, you can configure dispatcher settings like
@WebFilter(urlPatterns = "/public/*", dispatcherTypes = {DispatcherType.REQUEST, DispatcherType.FORWARD})
PrettyFaces uses like many URL-rewriting solutions RequestDispatcher#forward()
to forward the request to the desired target resource.
Servlet filters, when mapped without any <dispatcher>
, listens by default on "initial" requests only, not on forwarded, included, nor error'ed requests.
So, when you map another servlet filter in web.xml
after the PrettyFaces one, then it would by default not be triggered, unless you explicitly set a <dispatcher>
on FORWARD
next to the default of REQUEST
(you should keep this one for the case PrettyFaces actually doesn't need to perform a forward).
<filter-mapping>
...
<dispatcher>REQUEST</dispatcher>
<dispatcher>FORWARD</dispatcher>
</filter-mapping>
Or, for the case you're using @WebFilter
on your filters, use the dispatcherTypes
attribute:
@WebFilter(..., dispatcherTypes = { REQUEST, FORWARD })
Alternatively, if the filter in question doesn't change the request/response target in any way, e.g. setting the charset, compressing using Gzip, listening on exceptions, etc, then you can also just put it before the PrettyFaces one.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With