You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by csckid <te...@gmail.com> on 2011/11/27 08:41:07 UTC

fault found

I tried the following example to generate pdf file and return to user
browser. 
http://wiki.apache.org/tapestry/Tapestry5HowToCreateADynamicPDF

The problem I found is method public StreamResponse onSubmit() is called
three times. I really couldn't understand why this was so, but it would be
really helpful if someone could help me out with this.

--
View this message in context: http://tapestry.1045711.n5.nabble.com/fault-found-tp5026068p5026068.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: fault found

Posted by csckid <te...@gmail.com>.
Found out the problem :D

All my downloads are done by Internet download manager. My problem was
actually similar to what 'Lance' said. Browser sends one request and 2 more
from IDM(thats makes it three times). Anyways, I have disabled IDM and went
with normal downloader that came out with the browser and my method was just
called once :).  

Now the question is, how would I tackle IDM? :S


Another question, what framework did this website
use(http://tapestry.1045711.n5.nabble.com)?

--
View this message in context: http://tapestry.1045711.n5.nabble.com/fault-found-tp5026068p5029218.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: fault found

Posted by Peter Stavrinides <P....@albourne.com>.
One thing you can check is that your submit method references the correct form id, using catch all event methods could receive bubbled up events from other forms:

i.e.: onSuccess() should become  onSuccessFrom<FormId>()

Kind regards,
Peter

----- Original Message -----
From: "Christian Riedel" <cr...@googlemail.com>
To: "Tapestry users" <us...@tapestry.apache.org>
Sent: Monday, 28 November, 2011 2:38:40 PM
Subject: Re: fault found

then it is caused by some portion of the code that you did not show.
I tried it out and the onSubmit method is only called once, as expected. 

jsp won't help you here.


Am 28.11.2011 um 12:18 schrieb csckid:

> I tried with smaller project that has only hibernate and spring integrated
> and no custom filters. It didn't work still. 
> 
> Is there any other way to download the file beside this procedure? Can I
> link it through jsp? If that is possible can you please show me the way.
> 
> --
> View this message in context: http://tapestry.1045711.n5.nabble.com/fault-found-tp5026068p5028554.html
> Sent from the Tapestry - User mailing list archive at Nabble.com.
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: fault found

Posted by Christian Riedel <cr...@googlemail.com>.
then it is caused by some portion of the code that you did not show.
I tried it out and the onSubmit method is only called once, as expected. 

jsp won't help you here.


Am 28.11.2011 um 12:18 schrieb csckid:

> I tried with smaller project that has only hibernate and spring integrated
> and no custom filters. It didn't work still. 
> 
> Is there any other way to download the file beside this procedure? Can I
> link it through jsp? If that is possible can you please show me the way.
> 
> --
> View this message in context: http://tapestry.1045711.n5.nabble.com/fault-found-tp5026068p5028554.html
> Sent from the Tapestry - User mailing list archive at Nabble.com.
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: fault found

Posted by Lance Java <la...@googlemail.com>.
This sounds like an IE bug I encountered years ago. Are you using an old
version of IE (5 perhaps). From memory, IE sends two requests for the PDF
and then Acrobat sends one itself.

My solution at the time (I don't have access to the code) involved ignoring
two of the requests and only returning content to one of them. Each request
could be differentiated by the request headers. I can't remeber the headers
or which ones we ignored or served.

Lance.

On Monday, 28 November 2011, csckid <te...@gmail.com> wrote:
> I tried with smaller project that has only hibernate and spring integrated
> and no custom filters. It didn't work still.
>
> Is there any other way to download the file beside this procedure? Can I
> link it through jsp? If that is possible can you please show me the way.
>
> --
> View this message in context:
http://tapestry.1045711.n5.nabble.com/fault-found-tp5026068p5028554.html
> Sent from the Tapestry - User mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>

Re: fault found

Posted by csckid <te...@gmail.com>.
I tried with smaller project that has only hibernate and spring integrated
and no custom filters. It didn't work still. 

Is there any other way to download the file beside this procedure? Can I
link it through jsp? If that is possible can you please show me the way.

--
View this message in context: http://tapestry.1045711.n5.nabble.com/fault-found-tp5026068p5028554.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: fault found

Posted by Christian Riedel <cr...@googlemail.com>.
Should be called only once if you have this code in a fresh project. 
Are you sure there are no such things like custom filters that might process things more than once?


Am 27.11.2011 um 12:53 schrieb csckid:

> Smaller sample:
> 
> *Contact.tml*
> <html t:type="layout" title="Contact com.kids.crm"
>      xmlns:t="http://tapestry.apache.org/schema/tapestry_5_1_0.xsd"
>      xmlns:p="tapestry:parameter">
> 
>    <p>Contact com.kids.crm ...</p>
> <t:form t:id="doReportsForm"  >
>       <t:submit t:id="onSubmit" name="Run Report" value="Run Report" />
> </t:form>
> </html>
> 
> 
> 
> *Contact.java*
> package com.kids.crm.pages;
> 
> import java.io.BufferedWriter;
> import java.io.File;
> import java.io.FileInputStream;
> import java.io.FileWriter;
> import java.io.IOException;
> import java.io.InputStream;
> 
> import org.apache.tapestry5.StreamResponse;
> import org.apache.tapestry5.annotations.InjectPage;
> 
> import com.kids.crm.reports.pdf.PDFGenerator;
> import com.kids.crm.reports.pdf.PDFStreamResponse;
> 
> 
> 
> public class Contact
> {
> 	public StreamResponse onSubmit() {		
> 	         try {
> 			System.out.println("\n\n\n\n\nContact\n\n\n\n");
> 		    File tmpFile = File.createTempFile("hava", null);
> 		    BufferedWriter br = new BufferedWriter(new FileWriter(tmpFile));
> 		    br.append("something to test\nAnother line to test");
> 		    br.flush();
> 		    br.close();
> 
> 		    return new PDFStreamResponse(new
> FileInputStream(tmpFile.getAbsolutePath()), "results_file");
> 		 } catch (IOException e) {
> 		     e.printStackTrace();
> 		 }
> 
> 		   return null; 
> 		
> 		
>    }
> }
> 
> *
> PDFStreamResponse.java*
> package com.kids.crm.reports.pdf;
> 
> import java.io.IOException;
> import java.io.InputStream;
> 
> import javax.servlet.http.HttpServletResponse;
> 
> import org.apache.tapestry5.StreamResponse;
> import org.apache.tapestry5.services.Response;
> 
> public class PDFStreamResponse implements StreamResponse{
> 	private InputStream is;
>    private String filename="default";
> 
>    public PDFStreamResponse(InputStream is, String args) {
>            this.is = is;
>                    this.filename = args;
>    }
> 
>    public String getContentType() {
>            return "application/pdf";
>    }
> 
>    public InputStream getStream() throws IOException {
>            return is;
>    }
> 
>    public void prepareResponse(Response arg0) {
>            arg0.setHeader("Content-Disposition", "attachment; filename="
>                            + filename + ".pdf");
>    }
> 
> 
> }
> 
> 
> 
> 
> --
> View this message in context: http://tapestry.1045711.n5.nabble.com/fault-found-tp5026068p5026316.html
> Sent from the Tapestry - User mailing list archive at Nabble.com.
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: fault found

Posted by csckid <te...@gmail.com>.
Smaller sample:

*Contact.tml*
<html t:type="layout" title="Contact com.kids.crm"
      xmlns:t="http://tapestry.apache.org/schema/tapestry_5_1_0.xsd"
      xmlns:p="tapestry:parameter">

    <p>Contact com.kids.crm ...</p>
<t:form t:id="doReportsForm"  >
       <t:submit t:id="onSubmit" name="Run Report" value="Run Report" />
</t:form>
</html>



*Contact.java*
package com.kids.crm.pages;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;

import org.apache.tapestry5.StreamResponse;
import org.apache.tapestry5.annotations.InjectPage;

import com.kids.crm.reports.pdf.PDFGenerator;
import com.kids.crm.reports.pdf.PDFStreamResponse;



public class Contact
{
	public StreamResponse onSubmit() {		
 	         try {
			System.out.println("\n\n\n\n\nContact\n\n\n\n");
		    File tmpFile = File.createTempFile("hava", null);
		    BufferedWriter br = new BufferedWriter(new FileWriter(tmpFile));
		    br.append("something to test\nAnother line to test");
		    br.flush();
		    br.close();

		    return new PDFStreamResponse(new
FileInputStream(tmpFile.getAbsolutePath()), "results_file");
		 } catch (IOException e) {
		     e.printStackTrace();
		 }

		   return null; 
		
		
    }
}

*
PDFStreamResponse.java*
package com.kids.crm.reports.pdf;

import java.io.IOException;
import java.io.InputStream;

import javax.servlet.http.HttpServletResponse;

import org.apache.tapestry5.StreamResponse;
import org.apache.tapestry5.services.Response;

public class PDFStreamResponse implements StreamResponse{
	private InputStream is;
    private String filename="default";

    public PDFStreamResponse(InputStream is, String args) {
            this.is = is;
                    this.filename = args;
    }

    public String getContentType() {
            return "application/pdf";
    }

    public InputStream getStream() throws IOException {
            return is;
    }

    public void prepareResponse(Response arg0) {
            arg0.setHeader("Content-Disposition", "attachment; filename="
                            + filename + ".pdf");
    }


}




--
View this message in context: http://tapestry.1045711.n5.nabble.com/fault-found-tp5026068p5026316.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: fault found

Posted by csckid <te...@gmail.com>.
*Contact.java*

import java.io.InputStream;

import org.apache.tapestry5.StreamResponse;

import com.kids.crm.reports.pdf.PDFGenerator;
import com.kids.crm.reports.pdf.PDFStreamResponse;



public class Contact
{
	public StreamResponse onSubmit() {
        // Create PDF
        InputStream is = PDFGenerator.generatePDF("This is the content of a
Dynamically Generated PDF");
        // Return response
        return new PDFStreamResponse(is,"MyDynamicSample");
    }
}



*Contact.tml*
<html t:type="layout" title="Contact com.kids.crm"
      xmlns:t="http://tapestry.apache.org/schema/tapestry_5_1_0.xsd"
      xmlns:p="tapestry:parameter">

    <p>Contact com.kids.crm ...</p>
<t:form t:id="doReportsForm" action="reportsForm" target="_blank">

       <t:submit t:id="onSubmit" name="Run Report" value="Run Report" />

</t:form>
</html>


PDFGenerator.java

package com.kids.crm.reports.pdf;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;

import com.itextpdf.text.Document;
import com.itextpdf.text.DocumentException;
import com.itextpdf.text.Paragraph;
import com.itextpdf.text.pdf.PdfWriter;

public class PDFGenerator {
	public static InputStream generatePDF(String teststring) {
		// step 1: creation of a document-object
		Document document = new Document();

		System.out.println("\n\n\n\n\ntold ya 1\n\n\n\n");
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		try {
			// step 2:
			// we create a writer that listens to the document
			// and directs a PDF-stream to a file
			PdfWriter writer = PdfWriter.getInstance(document, baos);
			// step 3: we open the document
			document.open();
			// step 4: we add a paragraph to the document
			document.add(new Paragraph(teststring));
		} catch (DocumentException de) {
			System.err.println(de.getMessage());
		}
		// step 5: we close the document
		document.close();
		ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
		return bais;
	}

}


*PDFStreamResponse.java*

package com.kids.crm.reports.pdf;

import java.io.IOException;
import java.io.InputStream;

import org.apache.tapestry5.StreamResponse;
import org.apache.tapestry5.services.Response;

public class PDFStreamResponse implements StreamResponse{
	private InputStream is;
    private String filename="default";

    public PDFStreamResponse(InputStream is, String... args) {
            this.is = is;
            if (args != null) {
                    this.filename = args[0];
            }
    }

    public String getContentType() {
            return "application/pdf";
    }

    public InputStream getStream() throws IOException {
            return is;
    }

    public void prepareResponse(Response arg0) {
            arg0.setHeader("Content-Disposition", "attachment; filename="
                            + filename + ".pdf");
    }


}





--
View this message in context: http://tapestry.1045711.n5.nabble.com/fault-found-tp5026068p5026121.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: fault found

Posted by Christian Riedel <cr...@googlemail.com>.
Show us your code and we can tell you what's wrong!

Am 27.11.2011 um 08:41 schrieb csckid:

> I tried the following example to generate pdf file and return to user
> browser. 
> http://wiki.apache.org/tapestry/Tapestry5HowToCreateADynamicPDF
> 
> The problem I found is method public StreamResponse onSubmit() is called
> three times. I really couldn't understand why this was so, but it would be
> really helpful if someone could help me out with this.
> 
> --
> View this message in context: http://tapestry.1045711.n5.nabble.com/fault-found-tp5026068p5026068.html
> Sent from the Tapestry - User mailing list archive at Nabble.com.
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org