• 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 do I initialize this managed property?

 
Ranch Hand
Posts: 436
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Saloon Keeper
Posts: 27764
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
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.
 
author
Posts: 81
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 27764
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
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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic