• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

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

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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")
 
Bartender
Posts: 19668
92
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

 
Anitha Senthilkumar
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have tried like this,



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


 
Carl Manschold
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Think you have a typo, your method should be getEmpInfoAll() but it looks like you have spelled it getempInfoAll() .
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!