• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How do I initialize this managed property?

 
Dave Alvarado
Ranch Hand
Posts: 436
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

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: myco.dor.online.interlock.model.SubVendorSession,
property: vehicle.state" error upon loading my app. Thanks for your help, - Dave
 
Tim Holloway
Saloon Keeper
Pie
Posts: 18282
56
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Bart Kummel
author
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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,
Bart
 
Tim Holloway
Saloon Keeper
Pie
Posts: 18282
56
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic