Reputation: 4864
i write a custom spring scope base on FacesContext Logique,
public class DynamicScope implements Scope{
@Override
public Object get(String name, ObjectFactory<?> objectFactory) {
AbsErpFolder erpFolder = null;
if (FacesContext.getCurrentInstance()!=null)
erpFolder = (AbsErpFolder)FacesUtils.getExternalContext().
getRequestMap().get( ErpFolderKey );
............
}
Now i need to instanciate a bean in FileServlet Filter using
WebApplicationContext wsc = WebApplicationContextUtils.getWebApplicationContext(config.getServletContext());
IGenericService erpFileService = (IGenericService) wsc.getBean("erpFileService");
The problem is during the execution my ServletFile the current FacesContext is null (the dynamic scope can't work ) so how to get the current request ?
Upvotes: 1
Views: 663
Reputation: 4864
ThreadLocal should do the trick ( Defined in my first Filter )
public static ThreadLocal servletRequestHolder = new ThreadLocal();
public static HttpServletRequest getCurrentRequest(){
return (HttpServletRequest) servletRequestHolder.get();
}
@Override
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain)
throws ServletException, IOException {
servletRequestHolder.set( request );
...........
}
Upvotes: 1