I see, thats pretty good idea, will do like you wrote, I'm quite lazy in
repeating the code, so that solution is for me :)
Thanks everyone for help :)
Tomek
Jeff Bischoff wrote:
Tomek,
> session.setAttribute("USER", loginName);
You shouldn't need to do direct session/request manipulation as long
as you have a facescontext.
I also don't like including all this FacesContext/ValueBinding code in
every managed bean. Too much clutter.
Better is a utility class that performs such lookups between managed
beans:
public class WebLookup {
/**
* Look up a managed bean by JSP-EL value-binding expression
* @param ref a value-binding expression to lookup
* @return the managed bean referenced by the expression
*/
public static Object getManagedBean(String ref) {
// Find or create the web-tier data object
// ref like "#{loginBean}"
// would return the LoginBean
FacesContext context = FacesContext.getCurrentInstance();
ValueBinding binding =
context.getApplication().createValueBinding(ref);
return binding.getValue(context);
}
public static LoginBean getLoginBean() {
return (LoginBean )getManagedBean("#{loginBean}");
}
...
}
Regards,
Jeff Bischoff
Kenneth L Kurz & Associates, Inc.
[EMAIL PROTECTED] wrote:
Hi,
I'm wondering what solution for that you got boys:
- how should I pass the password and the user login through
beans, as I need both of them to retrieve data form database.
Is good enough to have loginBean.java and then on each bean which
needs connect to db do something like:
FacesContext context = FacesContext.getCurrentInstance();
ValueBinding vb =
context.getApplication().createValueBinding("#{loginBean}");
u = ((UserBean) vb.getValue(context));
userName = u.getLoginName();
passwd = u.getPasswd();
Or better solution will be put user and password to the session
like:
FacesContext fc = FacesContext.getCurrentInstance();
HttpSession session = (HttpSession)
fc.getExternalContext().getSession(false);
session.setAttribute("USER", loginName);
and then retrieve it when necessery:
HttpSession session = (HttpSession)
context.getExternalContext().getSession(false);
session.getAttribute("USER");
Thanks for any suggestion!
Tomek