I'm using JSF, Jboss. I used urlrewrite filter and i don't know why:
when i type localhost:8080/myweb/user/myname will be forwarded to localhost:8080/myweb/user.xhtml?u=myname. it makes me don't like urlrewritefilter.
After that, i try using prettyfaces. Maybe, it is good for others, not me. i can't find out good tutorials except the documentation. ajax error after adding prettyfaces into my project. And some codes in pretty-config.xml
<url-mapping id="ideas">
<pattern value="/article/#{g}" />
<view-id value="/ideas/article.xhtml" />
</url-mapping> -->
And a form in jsf page will redirect this page with param
public String addUserToGroup() {
...
return "/ideas/article.xhtml?g=" + g + "&faces-redirect=true";
}
can't run.
Can you give me some advices about what library i should use to rewrite URL now. Or how to fix errors of prettyfaces. thanks
Is your configuration commented out? I noticed the '-->' in your code snippit.
<url-mapping id="ideas">
<pattern value="/article/#{g}" />
<view-id value="/ideas/article.xhtml" />
</url-mapping> -->
Related
I have one question. How could pretty faces do this:
<code>
<url-mapping id="home">
<pattern value="/viewer" />
<view-id value="/pages/*" />
</url-mapping>
</code>
Well, I wonder if pretty faces could hide paths of all .xhtml in folder using just one configuration as shown as above, instead of to config for each and every file.
This mapping doesn't make any sense. To which view should PrettyFaces forward if the client requests /viewer?
However, you can do something similar with Rewrite, which is the successor of PrettyFaces. With Rewrite you can do something like:
.addRule( Join.path("/viewer/{page}").to("/pages/{page}.xhtml") )
This will basically map your URLs like this:
/viewer/foo -> /pages/foo.xhtml
/viewer/bar -> /pages/bar.xhtml
/viewer/whatever -> /pages/whatever.xhtml
If you want to migrate your app to Rewrite, which is really simple, have a look at the PrettyFaces Migration Guide.
I am facing problem with rewriting urls using pretty-config.xml and I want help. This is what I want.
I want to render the URL as:
http://www.example.com/{productId}
and the page actual URL is:
http://www.example.com/page/product.jsf
In short, I have one page but I want to render it each time as different url based on product id from the backing bean.
Sounds fairly simple. I would use this:
<url-mapping>
<pattern value="/#{productId}" />
<view-id value="/pages/product.jsf" />
</url-mapping>
Just make sure that you generate the correct links in your pages upon rendering.
I am trying the prettyfaces library for REST url mapping to JSF2 pages.
I first set up prettyfaces in maven's pom.xml:
<dependency>
<groupId>com.ocpsoft</groupId>
<artifactId>prettyfaces-jsf2</artifactId>
<version>3.3.3</version>
</dependency>
Then my pretty-config.xml:
<pretty-config xmlns="http://ocpsoft.com/prettyfaces/3.3.2"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://ocpsoft.com/prettyfaces/3.3.2
http://ocpsoft.com/xml/ns/prettyfaces/ocpsoft-pretty-faces-3.3.2.xsd">
<url-mapping id="view-marchi">
<pattern value="/marchi/{urlMarchio}" />
<view-id value="/marchio.xhtml" />
</url-mapping>
</pretty-config>
I have a marchio.xhtml in my webapp root folder. It's working directly accessed: www..com/marchio.xhtml.
However the mapping doesn't work as I expected:
www..com/marchi/testparam
404 - Not found!
I don't get the point... am I doing something wrong? Or maybe there's something misconfigured..?
I believe the parameters in the mapping have to match #{param-name}. As I can see, you have missed the #. Change your pattern in the url-mapping to:
<pattern value="/marchi/#{urlMarchio}" />
I'm currently trying to setup my project using pretty faces. The basic navigation and parameter setting works, but when I'm trying to inject the "locale" into a sessionScoped bin, prettyfaces throws an exception, saying
PrettyFaces: Exception occurred while processing for URL
That's my config:
<url-mapping id="locale">
<pattern value="/#{language: CurrentUser.language}" />
<view-id value="/faces/index.xhtml" />
</url-mapping>
<url-mapping parentId="locale" id="portal">
<pattern value="/portal" />
<view-id value="/faces/index.xhtml" />
</url-mapping>
If I remove the EL-injection, the rule works, but ofc. CurrentUser.language is not set, then.
Edit: i've now tried it with query-params - but also theres a "null" somewhere:
http://localhost:8090/portal/?language=en
causing:
PrettyFaces: Exception occurred while processing mapping<portal:#{currentUser.language}> for query parameter named<language> null
with config
<url-mapping id="portal">
<pattern value="/portal/" />
<view-id value="/faces/index.xhtml" />
<query-param name="language">#{currentUser.language}</query-param>
</url-mapping>
Any ideas?
Are you trying to inject into a Locale object field? There is probably no default converter for String -> Locale in EL/JSF, so you should probably inject into a Field, then use an <action>#{currentUser.language}</action> to convert that into a Locale object and set it.
Using Pretty Faces 3, I have some mappings like these:
<url-mapping id="search">
<pattern value="/search" />
<view-id value="/views/search.xhtml" />
</url-mapping>
<url-mapping id="edit">
<pattern value="/edit" />
<view-id value="/views/edit.xhtml" />
</url-mapping>
Is there any way to define all them using some wildcard, like this?
<url-mapping id="generic">
<pattern value="/*" />
<view-id value="/views/$1.xhtml" />
</url-mapping>
I know is possible to use EL in the view-id value, but I can manage it to work.
Its currently not possible to use a wildcard like this.
However as you already mentioned you could use a dynaview (EL expression for the view-id) to achieve something similar. We recently fixed a bug that prevented something like this to work correcty. Perhaps you could give 3.3.1-SNAPSHOT a try. My guess is that it will work fine now. Feel free to post a message on the forums if you have any further problems.
You might be better off using Rewrite which lets you do more powerful configuration:
https://github.com/ocpsoft/socialpm/blob/master/web/src/main/java/com/ocpsoft/socialpm/URLRewriteConfiguration.java
.addRule(Join.path("/{page}").to("/views/{page}.xhtml"))