Reputation: 665
my problem is that i want to pass a value (id of the logged in user) to a page. the following code shows the link to the page
<h:form>
<h:link outcome="Account">
#{logging.username}
</h:link>
</h:form>
so i want to pass the "logging.id to the "Account" when that page loads i want to pass the id to another backing bean used by that Account page. so what is the way to do this ? please kindly help me
Upvotes: 1
Views: 5990
Reputation: 3533
As far as i am concerned, the logged in user is a session property rather than a request/page property.
For that matter, you could save the user.id in the session attribute, and rather than passing it to another page through a url request, you get it from the session from any backing bean you so require it from.
example:
public void login(String username, String password ){
UserAccount account = myManagerBean.findUser(username, password);
HttpSession session = getCurrentRequestFromFacesContext().getSession(false);
session.addAttribute("user.account", account);
}
And then from any other backing bean.
public UserAccount getUserAccount() {
HttpSession session = getCurrentRequestFromFacesContext().getSession(false);
return session.getAttribute("user.account");
}
But if thats now what you require, you could pass the id as a request parameter:
<h:form>
<h:link outcome="Account">
<f:param name="user.username" value="#{logging.username}"/>
</h:link>
</h:form>
You could then attach this directly to a backing bean property of a request scope bean or manually retrieve it from the request:
@RequestScope
public class MyAccountBean {
@ManagedProperty("user.username")
private String username;
... or ...
public String getUserName() {
return getCurrentRequestFromFacesContext().getParameter("user.username");
}
}
Upvotes: 2