File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSF and the fly likes how I can pass attribute from one bean to another in jsf Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSF
Bookmark "how I can pass attribute from one bean to another in jsf" Watch "how I can pass attribute from one bean to another in jsf" New topic
Author

how I can pass attribute from one bean to another in jsf

Anitha Senthilkumar
Greenhorn

Joined: Oct 19, 2011
Posts: 2
Hi,

I am new to jsf framework.I dont know how I can pass information from one bean to another in the Java code.For Example i have two bean classes in my web application. LoginBean class code:


and EmployeeBean class code:


I have to get the username that is getUname() from LoginBean to EmployeeBean. I tried like bellow code, but i am getting null for username .
Kindly help me on this.
Carl Manschold
Greenhorn

Joined: Oct 20, 2011
Posts: 6
I guess you use JSF 2 ? Try bean injection, you can read about it here
http://www.coderanch.com/t/555153/JSF/java/Dependency-Injection#2518740
http://stackoverflow.com/questions/5167920/jsf-2-managedproperty-injection-of-bean-from-dependency-jar
or just google it.

If you use JSF 1.2 I think you could fetch it via the facescontext (context.getApplication().getElResolver().getValue(elContext, null, "bean")
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16246
    
  21

JSF is based on Inversion of Control. So the preferred means of getting info from one bean to another is to inject the target bean into the source bean and have the source bean invoke the appropriate "set" method on the target bean.

I do not recommend using JSF-specific code to find beans. And if you do, using the EL subsystem is definitely the long slow way around, since for session and app-scope objects, you can use the facesContext to get the HttpServletRequest and use that to get the session/getAttribute or get the application attribute without having to parse and interpret EL. But it's even simpler to use a Managed Property and let JSF do it for you automatically and do it on a platform-independent (POJO) way.

As a side note, however, the technical term for webapps that implement their own security system is "hacked". J2EE has a standard security manager that's much more secure, requires minimal coding effort, and has had over 10 years to get all the bugs out, to boot.


Customer surveys are for companies who didn't pay proper attention to begin with.
Anitha Senthilkumar
Greenhorn

Joined: Oct 19, 2011
Posts: 2
Hi,

I have tried like this,



but im getting the bellow exception. i am using JSF 1.2


Carl Manschold
Greenhorn

Joined: Oct 20, 2011
Posts: 6
Think you have a typo, your method should be getEmpInfoAll() but it looks like you have spelled it getempInfoAll() .
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how I can pass attribute from one bean to another in jsf