File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSF and the fly likes How can I access JSF managed bean from JSF converter? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSF
Bookmark "How can I access JSF managed bean from JSF converter?" Watch "How can I access JSF managed bean from JSF converter?" New topic
Author

How can I access JSF managed bean from JSF converter?

Vladimir Kroupa
Greenhorn

Joined: Dec 26, 2008
Posts: 28
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

Joined: Aug 26, 2006
Posts: 4968
    
    1

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

Joined: Jun 25, 2001
Posts: 16019
    
  20

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:


Customer surveys are for companies who didn't pay proper attention to begin with.
Vladimir Kroupa
Greenhorn

Joined: Dec 26, 2008
Posts: 28
Tim, Cameron: many thanks to both of you!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How can I access JSF managed bean from JSF converter?