-
1. Re: PDF-documentStore
nickarls Feb 20, 2008 10:01 AM (in response to mobwerner)
Jacobs Werner wrote on Feb 20, 2008 08:16 AM:
documentStore via Contexts? Or is there an other way to achieve this?
I have found that databases are really good for storing stuff in ;-)
-
2. Re: PDF-documentStore
mobwerner Feb 20, 2008 10:12 AM (in response to mobwerner)Hi Nicklas,
My problem is not so much where to store the pdf. But more how do I retrieve the pdf data after rendering my mail or even without rendering at all.
If I do not misunderstand seam doc, they store the pdf temporary in the DocumentStore.(org.jboss.seam.pdf.DocumentStore, conversation scoped built-in component).
I would like to access this DocumentStore via Contexts.thx,
Werner
-
3. Re: PDF-documentStore
nickarls Feb 20, 2008 3:20 PM (in response to mobwerner)There used to be a DocumentStore.instance()... does it give you not null?
-
4. Re: PDF-documentStore
mobwerner Feb 21, 2008 10:39 AM (in response to mobwerner)Thanks for the response,it gives me nothing (no documentData) in the documentStore so I still do not manage.
I am looking now into a solution they proposed in the
following Seam JIRA issue and its reference to another item in Jboss Forum. -
5. Re: PDF-documentStore
bravocharlie.seam.signup.benny.me.uk May 26, 2008 6:33 PM (in response to mobwerner)There is a way to get the data from the conversation context, without having to change anything:
First you need to create a temporary FacesContext so that the PDF redirect doesn't propagate.
public class EmptyFacesContext extends MockFacesContext { FacesContext originalFacesContext; public EmptyFacesContext(){ super(new MockExternalContext()); originalFacesContext = FacesContext.getCurrentInstance(); createViewRoot(); FacesContext.setCurrentInstance(this); } public void restore(){ setCurrentInstance(originalFacesContext); } }
Then we render the PDF, and obtain the data by reflection (as the Seam PDF jar wont necessarily be accessible in your EJB classpath).
String DATA_STORE = "org.jboss.seam.pdf.documentStore.dataStore"; EmptyFacesContext emptyFacesContext = new EmptyFacesContext(); try { Renderer renderer = Renderer.instance(); renderer.render("/WEB-INF/pdfs/pdf.xhtml"); byte[] bytes = null; Map<String,Object> dataStore = (Map<String, Object>) conversation.get(DATA_STORE); if (dataStore != null){ Collection documentDatas = dataStore.values(); if (!documentDatas.isEmpty()){ Object documentData = documentDatas.iterator().next(); if (documentData != null){ Method method = Reflections.getGetterMethod(documentData.getClass(), "data"); Object data = Reflections.invokeAndWrap(method, documentData); if (data instanceof byte[]) { bytes = (byte[]) data; } } } } } finally { emptyFacesContext.restore(); }
Then create your PDF facelet, and away you go.
Cheers- Ben
-
6. Re: PDF-documentStore
bravocharlie.seam.signup.benny.me.uk Jun 5, 2008 1:14 PM (in response to mobwerner)at the top of the second block above
Context conversation = Contexts.getConversationContext()
-
7. Re: PDF-documentStore
maniappan.mani.yostechnologies.com Jul 24, 2008 7:08 AM (in response to mobwerner)Hi Ben,
How do I resolve the MockFacesContext and MockExternalContext methods?
Mani. -
8. Re: PDF-documentStore
maniappan.mani.yostechnologies.com Jul 24, 2008 7:26 AM (in response to mobwerner)Hi Ben,Forget my last request, posted early w/o checking the docs. - Mani.
-
9. Re: PDF-documentStore
lcurros Oct 23, 2008 10:28 AM (in response to mobwerner)Hi! I have tested this approach to save pdf on server. It's very usefull.
Just say that when render is executed fails if you have commented code in xhtml.
Is there any way to solve this without removing comments? -
10. Re: PDF-documentStore
georges.georges.berscheid.mpulse.eu Dec 18, 2008 6:02 PM (in response to mobwerner)Try putting the following in your web.xml:
<context-param> <param-name>facelets.SKIP_COMMENTS</param-name> <param-value>true</param-value> </context-param>
That has solved a bunch of comment-related problems for me.
Cheers,
Georges -
11. Re: PDF-documentStore
cash1981 Jun 16, 2009 2:55 PM (in response to mobwerner)The following code in the new Seam 2.1.2 does not compile because DocumentData no longer has getData(). It is moved to ByteArrayDocumentData.
EmptyFacesContext emptyFacesContext = new EmptyFacesContext(); // Context conversation = Contexts.getConversationContext(); byte[] bytes = null; Renderer.instance().render(path + "/status/status_pdf.xhtml"); DocumentStore doc = DocumentStore.instance(); if (doc != null) { DocumentData data = doc.getDocumentData("1"); bytes = data.getData(); }
How can I get the data from the ByteArrayDocumentData object?
-
12. Re: PDF-documentStore
cash1981 Jun 16, 2009 3:34 PM (in response to mobwerner)Hmm, after further debugging I see that the data is actually automatically a ByteArrayDocumentData object. So I just needed to cast it and it worked
-
13. Re: PDF-documentStore
patoroco Nov 9, 2009 9:01 AM (in response to mobwerner)Hi! I'm beginner on Seam, and I need to save a PDF on the server-side (for digital signature). I have been trying this sample, but I don't understand how I create the
PDF facelet
. I suppose that this is trivial for all of you, but I am disoriented with so many layers and technologies (Java, JSP, JSF, Seam...)Regards, and sorry my bad english ;)
-
14. Re: PDF-documentStore
cash1981 Nov 9, 2009 1:23 PM (in response to mobwerner)If you don't understand the code above then you should read the Seam pdf documentation. In the code above path + "/status/status_pdf.xhtml" is a link to a seam pdf xhtml page.
I don't know what more to say. It's pretty straight forward if you have a valid seam pdf xhtml page.