Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Passin Backing Bean to another class  RSS feed

 
ryan bohnert
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am new to JSF and was trying to find an example.

My question is in the processPage() method... how do i pass the managed bean to the ProjectDAO insert statement?

Faces-config.xml


XHTML Code


Managed Bean Code


Project DAO




thanks
 
Tim Holloway
Bartender
Posts: 18705
71
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actually, you usually do it the other way around - inject the DAO into the backing bean, since it's the point where the GUI and business logic intersect. Incidentally, you don't "pass it to a class", you are dealing with instances.

In the normal course of events, you'd simply define the DAO as a ManagedProperty and JSF would automatically inject it into the backing bean. There is one problem, however, which is that your DAO object may not be a ManagedBean, and therefore won't be available for JSF to inject into your Project object. This is especially true in cases where the DAO has constructor arguments, since JSF can only instantiate objects using a no-argument constructor.

I get around that by using the Spring Framework in conjunction with JSF. Spring instantiates the DAOs, then a special bridge component configured in faces-config.xml ties the Spring object namespace to the JSF object namespace for EL processing purposes. When that is done, then the DAO can be injected into JSF backing beans exactly like it would be if it were a JSF object.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!