Ques 7. How should do page navigation in apache tapestry?
Usage page properties:
Page1.page
<page-specification class="Welcome.Action">
<property name="success" value="Home" />
<property name="error" value="Error" />
</page-specification>
Page2.page
<page-specification class="Welcome.Action">
<property name="success" value="Home2" />
<property name="error" value="Error2" />
</page-specification>
Welcome.Action.java
public void submitListener(IRequestCycle cycle)
{
if (success)
cycle.activate(getSpecification().getProperty("success"));
if (error)
cycle.activate(getSpecification().getProperty("error"));
}
So on success, it will be redirected to Home2 and on error it will be redirected to Error2 page.
Ques 9. How to get a file from client input to server end in apache tapestry?
Make a method like the following a a listener, such as from a DirectLink or whatever.
(The Document is just a class that holds the file information you want to send to the user.)
public void downloadAction(IRequestCycle cycle)
{
try
{
HttpServletResponse response =
cycle.getRequestContext().getResponse();
byte[] data = new byte[1024];
FileInputStream in = document.getFileInputstream();
response.setHeader("Content-disposition",
"inline; filename=" +
document.getFileName());
response.setContentType(document.getMimeType());
response.setContentLength(new Long(document.getSize()).intValue());
ServletOutputStream out = response.getOutputStream();
while (in.read(data) > -1)
{
out.write(data);
}
in.close();
response.flushBuffer();
}
catch (IOException e)
{
e.printStackTrace();
}
}