It's not a secret anymore!
The moose likes JSF and the fly likes How do I initialize this managed property? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSF
Bookmark "How do I initialize this managed property?" Watch "How do I initialize this managed property?" New topic

How do I initialize this managed property?

Dave Alvarado
Ranch Hand

Joined: Jul 02, 2008
Posts: 436

I'm using MyFaces 1.1.5 with Tomahawk 1.1.7. I have a managed-bean, subVendorSession, which has this field ...

That record in turn, has this field

In my faces-config.xml, how do I initialize the vehicle state field? I have tried this ...

But I am getting a "javax.faces.el.PropertyNotFoundException: Bean:,
property: vehicle.state" error upon loading my app. Thanks for your help, - Dave
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 17417

The property name must the name of a simple property of the backing bean itself. You're attempting to initialize a property in a secondary bean.

You can avoid this issue by making vehicle a managed bean, setting its "state" property as a managed property in the vehicle bean's definition, then injecting the vehicle bean into the subVendorSession bean.

An IDE is no substitute for an Intelligent Developer.
Bart Kummel
Ranch Hand

Joined: Nov 30, 2007
Posts: 81
Hi Dave, Tim,

The snippet of the Vehicle class reveals some JPA annotations. And Dave is referring to it as a "record". So I think Vehicle does represent a database record; is that right?

In that case, I guess it doesn't make sense to make a managed bean out of it. Instead, I'd expect it to be initialized by JPA with a value from your database. The only situation where that isn't true is when you are trying to insert a new Vehicle into the database. If that is the case, can't you just initialize the Vehicle's state in the constructor of the Vehicle entity class?

Best regards,

SCJP 1.4 | SCJD 1.6 | Visit my website | Author of the book Apache MyFaces 1.2 Web Application Development
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 17417

Hmmm. And after I'd just spent all that time explaining why domain model objects make poor backing beans, too!

Good point. The options in that case are:

1. Make "CA" the default value in Vehicle's state property by setting it in the default constructor.

2. Inject a Vehicle into subVendorSession by whatever action method is going to result in a page that needs it and initialize that Vehicle object's state value either explicitly or implicitly (via constructor). I do this all the time, incidentally.

In either event, the real problem isn't so much the state as it is that the Vehicle is a domain object and it's not generally good practice to inject domain model objects into backing beans as managed property values.
I agree. Here's the link:
subject: How do I initialize this managed property?
jQuery in Action, 3rd edition