就我而言,登录用户是会话属性而不是请求/页面属性。
就此而言,您可以将 user.id 保存在 session 属性中,而不是通过 url 请求将其传递到另一个页面,而是从您需要它的任何支持 bean 从 session 中获取它。
示例:
public void login(String username, String password ){
UserAccount account = myManagerBean.findUser(username, password);
HttpSession session = getCurrentRequestFromFacesContext().getSession(false);
session.addAttribute("user.account", account);
}
然后从任何其他支持 bean。
public UserAccount getUserAccount() {
HttpSession session = getCurrentRequestFromFacesContext().getSession(false);
return session.getAttribute("user.account");
}
但如果这就是您现在需要的,您可以将 id 作为请求参数传递:
<h:form>
<h:link outcome="Account">
<f:param name="user.username" value="#{logging.username}"/>
</h:link>
</h:form>
然后您可以将其直接附加到请求范围 bean 的支持 bean 属性或从请求中手动检索它:
@RequestScope
public class MyAccountBean {
@ManagedProperty("user.username")
private String username;
... or ...
public String getUserName() {
return getCurrentRequestFromFacesContext().getParameter("user.username");
}
}