-
15. Re: PDF-documentStore
foxyuca Jan 16, 2010 9:31 PM (in response to mobwerner)HI, i need help, i have a problem in line Map<String,Object> dataStore = (Map<String, Object>) conversation.get(DATA_STORE); the dataStore Map is NULL thx__ #
-
16. Re: PDF-documentStore
zeppelinux.dmitry.diligesoft.com Jan 16, 2010 9:51 PM (in response to mobwerner)it didn't worked for me too, try:
DocumentStore dataStore = DocumentStore.instance();
-
17. Re: PDF-documentStore
rodriguezrps Jan 28, 2010 12:03 PM (in response to mobwerner)dataStore is null
i triedDocumentStore dataStore = DocumentStore.instance();
and
Map<String,Object> dataStore = (Map<String, Object>) conversation.get(DATA_STORE);
anyone can help me? i really need this.
-
18. Re: PDF-documentStore
cash1981 Jan 28, 2010 12:44 PM (in response to mobwerner)Remember to ensure that the pdf.xhtml is a valid seam pdf file.
private byte[] createPDF(String path) { // String DATA_STORE = // "org.jboss.seam.document.documentStore.dataStore"; EmptyFacesContext emptyFacesContext = new EmptyFacesContext(); byte[] bytes = null; try { Renderer render = Renderer.instance(); log.info("Generating final pdf from #0", path + "/status/status_pdf.xhtml"); render.render(path + "/status/status_pdf.xhtml"); DocumentStore doc = DocumentStore.instance(); if (doc != null) { DocumentData data = doc.getDocumentData("1"); ByteArrayDocumentData byteData = null; if (data instanceof ByteArrayDocumentData) { byteData = (ByteArrayDocumentData) data; } else { throw new IllegalArgumentException("Couldnt get the bytes from the pdf document, unkown class " + data.getClass().getName()); } bytes = byteData.getData(); } } catch (Exception ex) { log.error("Error when trying to get the content of the pdf in bytes with the message #0", ex.getMessage()); ex.printStackTrace(); } finally { emptyFacesContext.restore(); } return bytes; }
-
19. Re: PDF-documentStore
rodriguezrps Jan 28, 2010 2:18 PM (in response to mobwerner)ty for help Shervin it works now!
-
20. Re: PDF-documentStore
ganjiprabhakar Mar 16, 2010 3:48 PM (in response to mobwerner)Thanks for sharing coding example about rendering PDF enabled XHTML page to generate PDF and save it on the server side.
I've been using PDF capability in various applications and in all case I render pdf enabled xhtml page and which shows PDF in the browser window (new tab/new window) in both IE 7, 8 and Firefox 3.x.
I now have a requirement to generate PDF and save it on the server rather than displaying it to the browser.
I followed all instructions and used coded from the email thread. Thanks a lot.
However, I struck with an exception: java.lang.IllegalArgumentException: resource doesn't exist: tempTagReceiptPdf.xhtml
Basically, this file is located under
WebContent/pages/transactions/tempTagReceiptPdf.xhtmlI tried to render it by passing view id (Renderer.instance().render(viewid)) in various ways and all of them throw the the above exception.
Here are the ways I tried
/WebContent/pages/transactions/tempTagReceiptPdf.xhtml
WebContent/pages/transactions/tempTagReceiptPdf.xhtml
/pages/transactions/tempTagReceiptPdf.xhtml
pages/transactions/tempTagReceiptPdf.xhtml
--I even placed the file under WEB-INF
/WEB-INF/pdfPrintPages/tempTagReceiptPdf.xhtml
/WEB-INF/pdfPrintPages/tempTagReceiptPdf.xhtml-- with web app context
EZPass/pages/transactions/tempTagReceiptPdf.xhtml
/EZPass/pages/transactions/tempTagReceiptPdf.xhtml--with full url
http://localhost:8080/EZPass/pages/transactions/tempTagReceiptPdf.xhtmlAny help is much appreciated. Thanks in advance
-
21. Re: PDF-documentStore
ganjiprabhakar Mar 17, 2010 3:18 PM (in response to mobwerner)I finally able to generate PDF with the images and saving it on the server by moving my pages and associated images to
WebContent/WEB-INF/classes/
I don't know whether it is most elegant way of doing things, but all other options to load pages from
/WebContent/pages/transactions/aPage.xhtml which access images from
/WebContent/images/someImage.jpgled me to exception java.lang.IllegalArgumentException: resource doesn't exist.
Hope this helps somebody.
-
22. Re: PDF-documentStore
zeppelinux.dmitry.diligesoft.com Apr 26, 2010 12:09 AM (in response to mobwerner)It doesn't work in 100% of configurations until you add some extra hack described here:
-
23. Re: PDF-documentStore
enda Jul 28, 2010 7:38 PM (in response to mobwerner)Uff this is my third post, hope it will find all people struggling with unicode :)
Howdy,
here is the trick for Unicode :)
Get font and put it in your project :)
<p:font name="/resources/arialuni.ttf" encoding="Identity-H" embedded="true"> +ěščřžýáíé+ĚŠČŘŽÝÁÍ </p:font>
-
24. Re: PDF-documentStore
abucs01 Sep 8, 2010 1:40 AM (in response to mobwerner)When i try to store PDF i am getting this error... kindly help me out
I am in storePDF 11:04:48,875 INFO [STDOUT] i am in try 11:04:48,875 ERROR [STDERR] java.lang.IllegalArgumentException: resource doesn't exist: /project/pdf/invoiceGeneratePDF.seam?reservationId=946&sp=1&bankCommissionDetailsId=13 11:04:48,875 ERROR [STDERR] at org.jboss.seam.ui.facelet.RendererRequest.faceletForViewId(RendererRequest.java:90) 11:04:48,875 ERROR [STDERR] at org.jboss.seam.ui.facelet.RendererRequest.run(RendererRequest.java:73) 11:04:48,875 ERROR [STDERR] at org.jboss.seam.ui.facelet.FaceletsRenderer.render(FaceletsRenderer.java:43) 11:04:48,875 ERROR [STDERR] at com.sec.ezeeCSA.EzeeLinkReportAction.storePDF(EzeeLinkReportAction.java:181) 11:04:48,875 ERROR [STDERR] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 11:04:48,875 ERROR [STDERR] at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) 11:04:48,875 ERROR [STDERR] at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) 11:04:48,875 ERROR [STDERR] at java.lang.reflect.Method.invoke(Unknown Source) 11:04:48,875 ERROR [STDERR] at org.jboss.seam.util.Reflections.invoke(Reflections.java:22) 11:04:48,875 ERROR [STDERR] at org.jboss.seam.intercept.RootInvocationContext.proceed(RootInvocationContext.java:31) 11:04:48,875 ERROR [STDERR] at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:56) 11:04:48,875 ERROR [STDERR] at org.jboss.seam.transaction.RollbackInterceptor.aroundInvoke(RollbackInterceptor.java:28) 11:04:48,875 ERROR [STDERR] at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68) 11:04:48,875 ERROR [STDERR] at org.jboss.seam.core.BijectionInterceptor.aroundInvoke(BijectionInterceptor.java:77) 11:04:48,875 ERROR [STDERR] at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68) 11:04:48,875 ERROR [STDERR] at org.jboss.seam.core.ConversationInterceptor.aroundInvoke(ConversationInterceptor.java:56) 11:04:48,875 ERROR [STDERR] at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68) 11:04:48,875 ERROR [STDERR] at org.jboss.seam.core.MethodContextInterceptor.aroundInvoke(MethodContextInterceptor.java:44) 11:04:48,875 ERROR [STDERR] at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68) 11:04:48,875 ERROR [STDERR] at org.jboss.seam.core.SynchronizationInterceptor.aroundInvoke(SynchronizationInterceptor.java:32) 11:04:48,875 ERROR [STDERR] at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68) 11:04:48,875 ERROR [STDERR] at org.jboss.seam.intercept.RootInterceptor.invoke(RootInterceptor.java:107) 11:04:48,875 ERROR [STDERR] at org.jboss.seam.intercept.JavaBeanInterceptor.interceptInvocation(JavaBeanInterceptor.java:185) 11:04:48,875 ERROR [STDERR] at org.jboss.seam.intercept.JavaBeanInterceptor.invoke(JavaBeanInterceptor.java:103) 11:04:48,875 ERROR [STDERR] at com.sec.ezeeCSA.EzeeLinkReportAction_$$_javassist_19.storePDF(EzeeLinkReportAction_$$_javassist_19.java) 11:04:48,875 ERROR [STDERR] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 11:04:48,875 ERROR [STDERR] at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) 11:04:48,875 ERROR [STDERR] at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) 11:04:48,875 ERROR [STDERR] at java.lang.reflect.Method.invoke(Unknown Source) 11:04:48,875 ERROR [STDERR] at org.jboss.el.util.ReflectionUtil.invokeMethod(ReflectionUtil.java:329) 11:04:48,875 ERROR [STDERR] at org.jboss.el.util.ReflectionUtil.invokeMethod(ReflectionUtil.java:274) 11:04:48,875 ERROR [STDERR] at org.jboss.el.parser.AstMethodSuffix.getValue(AstMethodSuffix.java:59) 11:04:48,875 ERROR [STDERR] at org.jboss.el.parser.AstMethodSuffix.invoke(AstMethodSuffix.java:65) 11:04:48,875 ERROR [STDERR] at org.jboss.el.parser.AstValue.invoke(AstValue.java:96) 11:04:48,875 ERROR [STDERR] at org.jboss.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:276)
-
25. Re: PDF-documentStore
raimundhoelle Mar 31, 2011 2:28 PM (in response to mobwerner)
Shervin Asgari wrote on Jan 28, 2010 12:44:Regrettably Shervin's SEAM-2.1-adaption of Bens solution works only for the first document created in a conversation. The reason is the following code:
[...] DocumentData data = doc.getDocumentData("1"); [...]
The document keys are automatically generated by the document store and there's no proper way to get the last used key. In the current SEAM version the key starts with
1
so the code works at least for the first document, but not for following document creations in the same conversation.To solve that problem, i've tried two solutions.
First, it is possible to get the current document key per reflection out of the datastore:
Class<?> clazz = doc.getClass(); Field field = clazz.getField("nextId"); field.setAccessible(true); long nextId = field.getLong(doc); DocumentData data = doc.getDocumentData( Long.toString(nextId - 1) );
(Error handling should be added!)
That's not a nice solution because its very strong dependency of the internal implementation which may change with the next release (tested with 2.2.0.GA).
The second solution hasn't such a strong dependency but it's also not a really proper solution. After rendering the PDF or Excel document, the Renderer performs a redirect to the new document URL. This document URL contains the document key parameter, e. g. ...?docId=.... We can catch the URL and extract the docId. (The parametername
docId
is hard coded in the DocumentStore).Since we have replaced the standard context with a self created dummy context, it is easy to catch the redirection URL:
/** * Dummy context with protocolling the URL redirected to. */ public class EmptyFacesContext extends MockFacesContext { FacesContext originalFacesContext; public EmptyFacesContext() { super(new ProtocollingContext()); originalFacesContext = FacesContext.getCurrentInstance(); createViewRoot(); FacesContext.setCurrentInstance(this); } public void restore() { setCurrentInstance(originalFacesContext); } public String getLastUrl() { return ((ProtocollingContext) getExternalContext()).getLastUrl(); } // External context with protocol private static class ProtocollingContext extends MockExternalContext { private String lastUrl; @Override public void redirect( String AUrl ) throws IOException { lastUrl = AUrl; super.redirect(AUrl); } public String getLastUrl() { return lastUrl; } } }
Maybe that's helpful for someone.
Regards, Raimund
-
26. Re: PDF-documentStore
tchoque Jun 13, 2011 6:13 PM (in response to mobwerner)Hi,
I have the following problems:
1) when call the below method:
EmptyFacesContext emptyFacesContext = new EmptyFacesContext();
public class EmptyFacesContext extends MockFacesContext {
FacesContext originalFacesContext;
public EmptyFacesContext(){
super(new MockExternalContext());
originalFacesContext = FacesContext.getCurrentInstance();
createViewRoot();
FacesContext.setCurrentInstance(this);
}
public void restore(){
setCurrentInstance(originalFacesContext);
}
}
17:47:15,349 ERROR [SeamPhaseListener] uncaught exception
javax.el.ELException: javax.ejb.EJBTransactionRolledbackException: Application was not properly initialized at startup, could not find Factory: javax.faces.application.ApplicationFactory
at org.jboss.el.util.ReflectionUtil.invokeMethod(ReflectionUtil.java:333)
at org.jboss.el.util.ReflectionUtil.invokeMethod(ReflectionUtil.java:342)
at org.jboss.el.parser.AstPropertySuffix.invoke(AstPropertySuffix.java:58)
at org.jboss.el.parser.AstValue.invoke(AstValue.java:96)
at org.jboss.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:276)
at org.jboss.seam.core.Expressions$2.invoke(Expressions.java:173)
at org.jboss.seam.navigation.Pages.callAction(Pages.java:643)
at org.jboss.seam.navigation.Pages.preRender(Pages.java:296)
at org.jboss.seam.jsf.SeamPhaseListener.preRenderPage(SeamPhaseListener.java:560)
at org.jboss.seam.jsf.SeamPhaseListener.beforeRenderResponse(SeamPhaseListener.java:471)
at org.jboss.seam.jsf.SeamPhaseListener.beforeServletPhase(SeamPhaseListener.java:144)
at org.jboss.seam.jsf.SeamPhaseListener.beforePhase(SeamPhaseListener.java:114)
at com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:222)
at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:144)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:245)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:530)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:83)
at org.jboss.seam.web.MultipartFilter.doFilter(MultipartFilter.java:85)
at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
at org.jboss.seam.web.ExceptionFilter.doFilter(ExceptionFilter.java:64)
at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
at org.jboss.seam.web.RedirectFilter.doFilter(RedirectFilter.java:45)
at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
at org.jboss.seam.web.CharacterEncodingFilter.doFilter(CharacterEncodingFilter.java:42)
at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
at org.ajax4jsf.webapp.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:206)
at org.ajax4jsf.webapp.BaseFilter.handleRequest(BaseFilter.java:290)
at org.ajax4jsf.webapp.BaseFilter.processUploadsAndHandleRequest(BaseFilter.java:388)
at org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:515)
at org.jboss.seam.web.Ajax4jsfFilter.doFilter(Ajax4jsfFilter.java:60)
at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
at org.jboss.seam.web.LoggingFilter.doFilter(LoggingFilter.java:58)
at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
at com.binariaconsultores.plataforma.gui.parametros.generales.CookieFilter.doFilter(CookieFilter.java:80)
at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
at org.jboss.seam.servlet.SeamFilter.doFilter(SeamFilter.java:158)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:179)
at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:84)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:157)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:262)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:446)
at java.lang.Thread.run(Thread.java:636)
Caused by: javax.ejb.EJBTransactionRolledbackException: Application was not properly initialized at startup, could not find Factory: javax.faces.application.ApplicationFactory
at org.jboss.ejb3.tx.Ejb3TxPolicy.handleInCallerTx(Ejb3TxPolicy.java:87)
2) And when use DocumentStore doc = DocumentStore.instance();
18:09:56,220 ERROR [SeamPhaseListener] uncaught exception
javax.el.ELException: javax.ejb.EJBTransactionRolledbackException: org.jboss.seam.pdf.DocumentStore_$$_javassist_19 cannot be cast to org.jboss.seam.pdf.DocumentStore
at org.jboss.el.util.ReflectionUtil.invokeMethod(ReflectionUtil.java:333)
at org.jboss.el.util.ReflectionUtil.invokeMethod(ReflectionUtil.java:342)
at org.jboss.el.parser.AstPropertySuffix.invoke(AstPropertySuffix.java:58)
at org.jboss.el.parser.AstValue.invoke(AstValue.java:96)
at org.jboss.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:276)
at org.jboss.seam.core.Expressions$2.invoke(Expressions.java:173)
at org.jboss.seam.navigation.Pages.callAction(Pages.java:643)
at org.jboss.seam.navigation.Pages.preRender(Pages.java:296)
at org.jboss.seam.jsf.SeamPhaseListener.preRenderPage(SeamPhaseListener.java:560)
at org.jboss.seam.jsf.SeamPhaseListener.beforeRenderResponse(SeamPhaseListener.java:471)
at org.jboss.seam.jsf.SeamPhaseListener.beforeServletPhase(SeamPhaseListener.java:144)
at org.jboss.seam.jsf.SeamPhaseListener.beforePhase(SeamPhaseListener.java:114)
at com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:222)
at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:144)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:245)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:530)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:83)
at org.jboss.seam.web.MultipartFilter.doFilter(MultipartFilter.java:85)
at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
at org.jboss.seam.web.ExceptionFilter.doFilter(ExceptionFilter.java:64)
at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
at org.jboss.seam.web.RedirectFilter.doFilter(RedirectFilter.java:45)
at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
at org.jboss.seam.web.CharacterEncodingFilter.doFilter(CharacterEncodingFilter.java:42)
at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
at org.ajax4jsf.webapp.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:206)
at org.ajax4jsf.webapp.BaseFilter.handleRequest(BaseFilter.java:290)
at org.ajax4jsf.webapp.BaseFilter.processUploadsAndHandleRequest(BaseFilter.java:388)
at org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:515)
at org.jboss.seam.web.Ajax4jsfFilter.doFilter(Ajax4jsfFilter.java:60)
at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
at org.jboss.seam.web.LoggingFilter.doFilter(LoggingFilter.java:58)
at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
at com.binariaconsultores.plataforma.gui.parametros.generales.CookieFilter.doFilter(CookieFilter.java:80)
at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
at org.jboss.seam.servlet.SeamFilter.doFilter(SeamFilter.java:158)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
Any help is much appreciated and sorry my bad english.