• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I guess you use JSF 2 ? Try bean injection, you can read about it here
https://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")
 
Saloon Keeper
Posts: 27752
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Think you have a typo, your method should be getEmpInfoAll() but it looks like you have spelled it getempInfoAll() .
 
reply
    Bookmark Topic Watch Topic
  • New Topic