views:

243

answers:

1

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)

+2  A: 

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

Chochos