aspose file tools*
The moose likes JSF and the fly likes Servlet created JSF bean Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » JSF
Bookmark "Servlet created JSF bean" Watch "Servlet created JSF bean" New topic
Author

Servlet created JSF bean

Daniel Prene
Ranch Hand

Joined: Jul 15, 2005
Posts: 241
Is it possible for a servlet to pass a jsf page a bean it wants the jsf page to hook into?
Alexander Jesse
Ranch Hand

Joined: Mar 17, 2004
Posts: 35
I hope I understood you correctly...

I assume you want to construct a Bean (within the servlet) and store it in some context (application, session or request) and then have a JSF-page access it using the "normal" JSF-expression language. If that is the correct interpretation of your question, then th answer is YES.

Configure the bean in jsf's faces-config.xml. The bean-name and the context are crucial.

The servlet can instantiate the bean and store it in the context using the configured bean-name.

hth
Alexander
Bruce Jin
Ranch Hand

Joined: Sep 20, 2001
Posts: 671
Can one do this (construct a Bean within the servlet and store it in some context) without using config.xml file?


BJ - SCJP and SCWCD
We love Java programming. It is contagious, very cool, and lot of fun. - Peter Coad, Java Design

Crazy Bikes created by m-Power
Daniel Prene
Ranch Hand

Joined: Jul 15, 2005
Posts: 241
That's exactly what I was looking for! Excelent. I'm trying to integrate JSF in an already existant webapp that uses an adapted version of the Command and Controller pattern. How would I go about doing what you described?
Alexander Jesse
Ranch Hand

Joined: Mar 17, 2004
Posts: 35
Bruce: You do not need the faces-config.xml for this.

If you want to add a JavaBean to the session context:
- create the bean (should be obvious)

- add it to the session:


Now to access it in your JSF-files:
- add the bean-definition to faces-config.xml

- use it:


to use application context, you define "application" in the faces-config scope-attribute and use
to put the bean into the application context.

Obviously using the corresponding get-methods you could access the beans that were created using JSF-factories also from your servlets.

hope this helps
Alexander
Daniel Prene
Ranch Hand

Joined: Jul 15, 2005
Posts: 241
Oh! Didn't realize it was that simple. A HUGE 'Thank You!'

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Servlet created JSF bean