Peter Maas wrote:
It helped me in going over the sources to find other locations where the
bean might be used.... and I found a generic servlet which also uses the
bean... it is however jsf unaware... is it possible to retrieve to bean
from the jsf context from a generic servlet in the same webapp?
It's difficult (as Mike Kienenberger's reply shows).
I solve this problem by putting the info I want to share between JSF and
non-jsf-servlets into a separate class stored in the session.
Here's some *very* rough pseudocode :-)
public class MySharedInfo {
public MySharedInfo getInstance(Session session) {
MySharedInfo instance = session.get("mySharedInfo");
if (instance == null) {
// create it and store it in the session
}
}
}
The servlet can just call MySharedInfo.getInstance(session).
A simple managed bean can then provide access to this from JSF and JSP
stuff:
public class MySharedBean {
public MySharedInfo getSharedInfo() {
Session session = facesContext.getExternalContext()...
return MySharedInfo.getInstance(session);
}
...
}
#{mySharedBean.sharedInfo.foo} will reference the shared data.
Hope this helps,
Simon