Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Bean inside a bean (using @ManagedProperty) (SOLVED)  RSS feed

 
Orfeas Theofanis
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello everyone!
I have a UserBean and a HouseBean, and I'm trying to access the UserBean's data from the HouseBean, and I can't find out how (I already searched a lot).
I've got this in my housebean:



But when I'm printing the userBean I get null.
Isn't it supposed to have the userBean's current value?

The scopes are: session for user, view for house.

Also, does it matter what name I use in @ManagedProperty("#{someTest}") or must it have the bean's class name? Or the bean's name as defined in @ManagedBean(value="..") ?

I'm using netbeans 8 with apache tomcat on ubuntu 14.04. (also using hibernate but I guess that doesn't matter anyway).

Thanks in advance!

EDIT: SOLVED!
Sorry about that :)
If anyone's wondering, the name does play a role... I had @ManagedBean(value="user") and I used another name in @ManagedProperty so it didn't work.
 
Tim Holloway
Bartender
Posts: 18531
61
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actually, what matters least to me is that you're using NetBeans. Your choice of IDE shouldn't color your app design. If it does, you need a more flexible IDE.

Anyway:

Also, does it matter what name I use in @ManagedProperty("#{someTest}") or must it have the bean's class name? Or the bean's name as defined in @ManagedBean(value="..") ?


Each of the J2EE scopes (application, session, request) has an associated dictionary pairing a bean name with a bean. View scope, BTW is a specially-managed session-scope object.

By default, if you annotate a POJO with the ManagedBean annotation and define its scope, the name that the constructed bean will be stored under is the simple class name (minus the package stuff) with the first character of the class name transposed to lower case. So MyBeanClass goes under "myBeanClass". You can override this with an option on the ManagedBean annotation.

The ManagedProperty then uses an EL expression to define what bean will be injected, so the corresponding annotation would be:


 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!