For those Googling for an actual answer to the question, PrettyFaces is one way of doing this. It does URL 'beautification,' which includes making elements of the URL's path into receivable parameters.
I'm going to give an example using JAX-RS, then the equivalent with PrettyFaces:
Jax-RS
@Path("user")
public class UserEndpoint{
@PersistenceContext
EntityManager em;
@GET
@Path("{userid}")
public UserEntity getUser(@PathParam("userid")long userId){
return em.find(UserEntity.class, userId);
}
}
JSF with PrettyFaces
Good help for it on here: http://www.ocpsoft.org/prettyfaces/
Backing Bean
@Named
public class UserViewController{
@PersistenceContext
EntityManager em;
public UserEntity getUser(){
ExternalContext ec = FacesContext.getCurrentInstance().getExternalContext();
Map<String, String> params = ec.getRequestParameterMap();
long userId = Long.valueOf(params.get("userid"));
return em.find(UserEntity.class, userId);
}
}
pretty-config.xml (special file that must be created inside the WEB-INF folder)
<pretty-config xmlns="http://ocpsoft.org/schema/rewrite-config-prettyfaces"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://ocpsoft.org/schema/rewrite-config-prettyfaces
http://ocpsoft.org/xml/ns/prettyfaces/rewrite-config-prettyfaces.xsd">
<url-mapping id="view-user">
<pattern value="/user/#{userid}" />
<view-id value="/user/view.xhtml" />
</url-mapping>
</pretty-config>