Win a copy of TDD for a Shopping Website LiveProject this week in the Testing forum!
  • 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
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

Backing Bean Constructors

 
Ranch Hand
Posts: 241
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is there a way to pass args to a Backing Bean's constructor? Perhaps some sort of controllor that manages creation?

Thank you in advaneced, I appreciate your time,
-D.P.
 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In a managed bean situation you're reallly not supposed to have constructors that take arbitrary arguments. The container is supposed to manage bean creation which works best if the constructor is simple and standardized - it simplifies the configuration.

Arguments that would be in a constructor are typically passed into the managed bean using the managed-property elements in faces-config.xml, which invoke the appropriate setters. I'm hard pressed to come up with a real-life backing bean situation where you couldn't replace constructor arguments with use of managed properties.

That all said, it would certainly be possible to create a bean in Java code (say, inside the methods of another bean) that has a constructor that takes arbitrary arguments. You could then bind this bean instance into the framework using the ValueBinding API. I'm not sure to what extent this bean would then be "managed", but it may accomplish what you're looking for. But I would very much recommend that you investigate managed properties before going this route.
 
Daniel Prene
Ranch Hand
Posts: 241
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I was looking for somthing more dynamic then that, but I found a solution. I just pass the parmeters with the request and retreive them from the HttpServletRequest
 
Ranch Hand
Posts: 1780
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I've been learning Spring and one of its core features is the BeanFactory, which can be configured in roughly the same way as JSF's managed beans. Spring's approach has some nice things missing from managed beans:
1. The ability to invoke specific constructor and pass it arguments.
2. The ability to create beans by invoke static or non-static methods of factory classes
3. The ability to derive or template parameters. So if you have several beans that need to have the same properties set with the same values, you can do this in one place.
4. The ability to specify "init" and "destroy" methods of the bean and have them invoked properly.

On the other hand, there are some things missing that occur in managed beans:
1. There is no notion like managed-bean-scope. You can indicate is a bean will be a singleton, but there is no notion of session.
2. There is no "param" scope for http parameters

Still the notions are so similar I daydream that they may converge in a best-of-breed sort of way. I mean, why reinvent the wheel, the underlying paradigm, dependency injection, should be given a standard implementation once and for all, no?
 
please buy my thing and then I'll have more money:
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic