这就是现在对我有用的方法,但不确定这是否是正确的做事方式。
首先我将网址改写为.addRule(Join.path("/users/{id}").to("/views/user/show.jsf"))
我把网址设为
<h:column>
<f:facet name="header">Show</f:facet>
<h:outputLink value="/users/#{user.id}">Show</h:outputLink>
</h:column>
这会将 url 生成为 /users/1 或 /users/200 等。
现在我可以从 jsf 页面 show.xhtml 以 <h:outputText value="#{param['id']}" /> 访问用户 id 参数
我也可以从bean中访问参数
public void show(){
Map<String, String> params = FacesContext.getCurrentInstance().
getExternalContext().getRequestParameterMap();
String user_id = params.get("id");
}
或者我也可以这样做
在show.xhtml 中
<ui:param name="user" value="#{userController.show(param['id'])}" />
Name: #{user.firstName}
在userController 中作为
public User show(Integer id){
user = userService.findById(id);
return user;
}