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.
Related
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> -->
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 use the configuration file pretty-config.xml to rewrite urls:
<pretty-config xmlns="http://ocpsoft.com/prettyfaces/3.3.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://ocpsoft.com/prettyfaces/3.3.0
http://ocpsoft.com/xml/ns/prettyfaces/ocpsoft-pretty-faces-3.3.0.xsd">
<url-mapping id="connect_ss">
<pattern value="/sicav_security" />
<view-id value="/AuthentificationSS.jsf" />
</url-mapping>
<url-mapping id="connect_oblig">
<pattern value="/sicav_oblig" />
<view-id value="/AuthentificationCAPOBLIG.jsf" />
</url-mapping>
</pretty-config>
Can I replace it with annotations?
If I understand your question correctly, you are asking whether it is possible to configure PrettyFaces using annotations.
Yes, that is possible. You can simply use #UrlMapping for that:
#URLMapping(id="connect_ss", pattern="/sicav_security",
viewId="/AuthentificationSS.jsf")
public class SomeBean {
/* Your code */
}
Have a look at this part of the official documentation for details:
http://ocpsoft.org/docs/prettyfaces/3.3.3/en-US/html/Configuration.html#config.annotations
i used prettyfaces in my project and its working well but when i tryed to use similar pattern for two url-mapping it always keep the first in mind and neglagte the second url-mapping that have the same pattern.
i want to ask you if there is a way to have same pattern for different page with pretty faces thats my code :
<pretty-config xmlns="http://ocpsoft.com/prettyfaces/3.3.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://ocpsoft.com/prettyfaces/3.3.0
http://ocpsoft.com/xml/ns/prettyfaces/ocpsoft-pretty-faces-3.3.0.xsd">
<url-mapping id="accueillogin">
<pattern value="/login" />
<view-id value="/faces/login.xhtml" />
</url-mapping>
<url-mapping id="afficherarticlehome">
<pattern value="/article" />
<view-id value="/faces/admin/gestiondesarticles/afficherarticlehome.xhtml" />
</url-mapping>
<url-mapping id="afficherarticleges">
<pattern value="/article" />
<view-id value="/faces/admin/gestiondesarticles/afficherarticleges.xhtml" />
</url-mapping>
</pretty-config>
any idea ?
Of course it is not possible. It wouldn't be possible to differ between the two different urls when the pattern is typed. However, it is possible to pass a parameter to determine what you want to show (having both of them the same view-id):
<url-mapping id="afficherarticle">
<pattern value="/article" />
<view-id value="/faces/admin/gestiondesarticles/afficherarticle.xhtml" />
</url-mapping>
/article?section=home
/article?section=ges
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"))