Passing query string with PrettyFaces

1.2k views Asked by At

I'm working with JSF2 and PrettyFaces for creating a 'SEO-friendly URLs'.
Now I'm facing a problem when I want to pass parameters after the PrettyFaces is creating a new url those parameters will been delete and i want to avoid that.

I will explain it with an example:
Currently when hitting this url:
http://www.mysite.com/index.jsf?param1=value1&param2=value2
After the PrettyFaces I'm getting this url:
http://www.mysite.com/

But I want it to be like that, so when hitting this url:
http://www.mysite.com/index.jsf?param1=value1&param2=value2
After the PrettyFaces i'll get this url:
http://www.mysite.com/?param1=value1

Please note: That I only want to pass specific parameters. from the example above, only param1 should be passed.

My configuration on the 'pretty-config.xml':

<url-mapping>    
    <pattern>/</pattern>    
     <view-id>/jsp/index.jsf</view-id>    
</url-mapping>
1

There are 1 answers

2
Lincoln On BEST ANSWER

I'm actually surprised that the query string is not being preserved. I would guess that something is else is going on, other than prettyfaces. What version of PRettyFaces are you using? I'm also guessing that this is a problem with PrettyFaces, that this was a bug in the version you're using, but I think that's unlikely.

The only thing the url-mapping you've pasted should do is perform an internal forward from "/" to "/jsp/index.jsf". It will not do any client redirection from "/index.jsf" to "/"; this is why I think there is something else at play here. (See the code for reference: https://github.com/ocpsoft/rewrite/blob/master/config-prettyfaces/src/main/java/org/ocpsoft/rewrite/prettyfaces/UrlMappingRuleAdaptor.java#L213)

With regard to stripping out certain query parameters and leaving others, then I highly suggest looking at the Rewrite framework (which is the new core of PrettyFaces), you can use it to build very custom rewriting rules: http://ocpsoft.org/prettyfaces/ and http://ocpsoft.org/rewrite/

I hope this helps.