Reputation: 613
I want to pass some variable values to the view-id node in the pretty-config.xml configuration file. For sample:
I want to do something like that:
<url-mapping id="allReports">
<pattern value="/report/#{type}" />
<view-id value="/pages/report/#{type}.xhtml" />
</url-mapping>
But I got the error:
java.lang.IllegalArgumentException: java.net.URISyntaxException: Illegal character in fragment at index 18: http://localhost/#{type}.xhtml
Someone know how to do that?
Thank you.
Upvotes: 4
Views: 6116
Reputation: 14865
I created it like that:
pretty-config.xml
<url-mapping id="static">
<pattern value="/s/#{staticViewBean.requestPath}" />
<view-id value="#{staticViewBean.getViewId}" />
</url-mapping>
StaticViewBean.java
@Controller("staticViewBean")
@Scope("request")
public class StaticViewBean {
private String requestPath;
public String getViewId() {
return "/WEB-INF/pages/s/" + requestPath + ".xhtml";
}
public String getRequestPath() {
return requestPath;
}
public void setRequestPath(String requestPath) {
this.requestPath = requestPath;
}
}
Upvotes: 0
Reputation: 31649
As the Prettyfaces main website says, you have to do the following one:
<url-mapping id="view-user">
<pattern value="/user/{username}" />
<view-id value="/user/view.xhtml" />
</url-mapping>
This is the equivalent to /user/view.xhtml?username=yourParam
. If you type this url /user/Administrator
, you receive in your view a request parameter which name is username
and value is Administrator
. Just follow this convention.
If you want to inherit from a parent id, just write a mapping for each type. For instance you can write:
<url-mapping parentId="view-user" id="admins">
<pattern value="/admin/#{user}" />
<view-id value="/user/admins/view.xhtml" />
</url-mapping>
<url-mapping parentId="view-user" id="externals">
<pattern value="/external/#{user}" />
<view-id value="/user/externals/view.xhtml" />
</url-mapping>
Also you have dynamic view id's, but I think it's not possible to concat them with a static String piece. To use them in the way you want you should take the param from the request and process the complete destination url in your bean.
Upvotes: 3