jQuery in Action, 3rd edition
The moose likes JSF and the fly likes Using inheritance for managed beans Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSF
Bookmark "Using inheritance for managed beans" Watch "Using inheritance for managed beans" New topic

Using inheritance for managed beans

Luke Murphy
Ranch Hand

Joined: May 12, 2010
Posts: 300
Is it considered bad or good practise to have managed beans inheriting from each other?

For example, I have a lot of similar backing beans.
I would like to factor out the commonality into a base backing bean.
I see no reason why I shouldn't do this,

Any tips or comments?

Ilari Moilanen
Ranch Hand

Joined: Apr 15, 2008
Posts: 199
I have a "BaseBean" that all my managed beans inherit from. The BaseBean itself is of course not a managed bean since I do not need it as one. And I have observed no problems whatsoever with this structure

EDIT: Now that I think about it I am no longer sure if I have a managed bean annotation in my base bean. At least I have managedPropertys inside it. I will check tomorrow. BTW I use JSF 2
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 17039

I have several apps that employ inheritance, both on managed beans and on domain model beans. No real problem as long as I mark the base bean to indicate any managed properties it may have.

The worst of my offenses are being committed in JSF2, but I'm pretty sure JSF1 supported inheritance too. I may even have some and just forgot about them.

An IDE is no substitute for an Intelligent Developer.
Ilari Moilanen
Ranch Hand

Joined: Apr 15, 2008
Posts: 199
Yep, no @ManagedBean annotation in my "BaseBean" as I thought.
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com
subject: Using inheritance for managed beans
It's not a secret anymore!