weld: inject entity manager in tomcat app
fiorenzino Mar 9, 2010 12:15 AMHi,
i'm working to a jsf application in tomcat with weld extension
(starting from this: http://seamframework.org/Documentation/WeldAndJPARunningInTomcat).
All works correctly, the em is injected in all managed beans.
I want use a custom resolver to load some facelets components from database.
Starting from this http://seamframework.org/Community/HowToDisplayAnXMLFileTransformedByXSLSSFileWithSeam ,
I wrote my CustomResolver, and briefly:
resourceUrl = new URL(null, resource, new DBStreamHandlerFactory().createURLStreamHandler("db")); DBStreamHandlerFactory ---> DBProtocolHandler ---> DBURLConnection.
I want inject my entitymanager in DBURLConnection class:
public class DBURLConnection extends URLConnection { @Inject EntityManager em; private String form; private String content = null; private Page currentPage; public DBURLConnection(URL u) { super(u); } @Override public synchronized InputStream getInputStream() throws IOException { if (!connected) connect(); if (content != null) { return IOUtils.toInputStream(content); } else { return null; } } public String getContentType() { return "text/html"; } public synchronized void connect() throws IOException { if (!connected) { try { this.form = url.getFile().substring(url.getFile().indexOf("/") + 1); System.out.println("form: " + this.form); this.currentPage= (Page) em.find(Page.class, this.form); this.content = this.currentPage.getContent(); } catch (Exception e){ content = "<ui:composition " + " xmlns=\"http://www.w3.org/1999/xhtml\" " + " xmlns:ui=\"http://java.sun.com/jsf/facelets\" " + " xmlns:c=\"http://java.sun.com/jstl/core\" " + " xmlns:f=\"http://java.sun.com/jsf/core\" " + " xmlns:h=\"http://java.sun.com/jsf/html\"> " + " <h:outputText value=\"#{bookFactory.text2}\" />" + " </ui:composition>"; } this.connected = true; } } @Override public long getExpiration() { return -1l; } @Override public long getLastModified() { return -1l; } }
But the em is null.
Also if i inject some beans, it's always null.
Some help??
Thank's in advance.
Fiorenzo