Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Servlet created JSF bean

 
Daniel Prene
Ranch Hand
Posts: 241
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 672
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can one do this (construct a Bean within the servlet and store it in some context) without using config.xml file?
 
Daniel Prene
Ranch Hand
Posts: 241
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 241
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh! Didn't realize it was that simple. A HUGE 'Thank You!'

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic