• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Bear Bibeault
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • salvin francis
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Frits Walraven
Bartenders:
  • Jj Roberts
  • Carey Brown
  • Scott Selikoff

How to access managed bean (JSF) from JSP

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, experts

I need to access properties like list etc initilalized in a managed bean (JSF): testBean from scriptlet section: <%>...</%> on JSP page.

TestBean has been defined in my face-config.xml as a session bean:

<managed-bean>
<managed-bean-name>testBean</managed-bean-name>
<managed-bean-class>org.test.TestBean</managed-bean-class>
<managed-bean-scope>session</managed-bean-scope>
</managed-bean>

Is it possible to do so ? If so, please advsie me how to do so.

Thanks,
yasushi

Thanks,
yasushi
 
Ranch Hand
Posts: 1780
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In the interests of coding hygiene, I suggest that you avoid scriptlets. That's easy to do with JSF, but if you insist....

If the bean already exists, you can access it like any session-scoped attribute:

org.test.TestBean x = (org.test.TestBean) request.getSession().getAttribute("testBean");

(Note that there is nothing scriptlet-like about this code. This could be in any Java method.)

If the managed bean hasn't been created yet, this code wouldn't trigger its creation -- instead, getAttribute will return a null reference. To access a managed bean, triggering its creation when needed:

 
Yasushi Okubo
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks, I will try that.
yasushi
 
Yasushi Okubo
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, Jeff

It worked!

yasushi
 
Don't sweat petty things, or pet sweaty things. But cuddle this tiny ad:
the value of filler advertising in 2020
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic