This week's book giveaway is in the Jython/Python forum.
We're giving away four copies of Murach's Python Programming and have Michael Urban and Joel Murach on-line!
See this thread for details.
Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How to access managed bean (JSF) from JSP  RSS feed

 
Yasushi Okubo
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • 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
 
Jeff Albertson
Ranch Hand
Posts: 1780
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
Thanks, I will try that.
yasushi
 
Yasushi Okubo
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, Jeff

It worked!

yasushi
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!