Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How can I access JSF managed bean from JSF converter?

 
Vladimir Kroupa
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I need to acces JSF managed bean from my validator class. Is there any easy way how to do this? I wasn't able to google anything helpful.

Thanks for any input,
Vladimir
 
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper
Posts: 4968
1
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you have access to the facesContext, you could just use the application's variableResolver:

facesContext.getCurrentInstance().getApplication().getVariableResolver().resolveVariable(context,"myManagedBeanNameInFacesConfigDotXML");

-Cameron McKenzie

 
Tim Holloway
Saloon Keeper
Pie
Posts: 18277
56
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JSF Managed Beans are simply ordinary JavaBeans that are instantiated by the JSF framework. That is, once the bean is built, it's just a regular old J2EE application-, session-, request- or page-scope JavaBean. To get access, therefore, all that you need is to get a handle on the appropriate part of the J2EE framework. And, of course, do so at a time in the request/response lifecycle when the bean actually exists in the case of request-scope beans.

Here's a snippet I use to get the HttpServletRequest:

 
Vladimir Kroupa
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tim, Cameron: many thanks to both of you!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic