Question

How Can I put information in a outputstream from tapestry5 ?

I need a page when a user enters it open a dialog for save or open the file with the outputstream information.

I write the next code:

public class Index {

@Inject
private RequestGlobals requestGlobals;

@OnEvent("activate")
public void onActivate() {
    try {
        HttpServletResponse response = requestGlobals.getHTTPServletResponse();
        response.setContentType("text/txt");
        PrintWriter out = response.getWriter();
        out.println("hellooooooo");
        out.flush();
    } catch (IOException ex) {
        Logger.getLogger(Index.class.getName()).log(Level.SEVERE, null, ex);
    }
}

}

I hope that the result is only "helloooooooo" but is ("helloooooooo" + my html raw page)

Was it helpful?

Solution

Your method should have a return type of StreamResponse. You return an implementation of the interface StreamResponse, which simply returns the data you want with the content type you want.

Look it up here:

http://tapestry.apache.org/tapestry5/apidocs/

more info here:

http://tapestry.formos.com/nightly/tapestry5/tapestry-core/guide/pagenav.html

OTHER TIPS

If you are dealing with large response streams, using StreamResponse can be somewhat inconvenient and inefficient (because you have to return an InputStream). Better would be to write response directly to OutputStream.

Fortunately, in Tapestry Wiki, there is a page for solving exactly this: Tapestry5: How To Create A Component Event Result Processor.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top