...
tapestry-upload is not automatically included in Tapestry applications because of the additional dependencies it requires. To include it, just add the tapestry-upload dependency to the pom of your application, something like this:
Code Block |
|
|
<dependency>
<groupId>org.apache.tapestry</groupId>
<artifactId>tapestry-upload</artifactId>
<version>${tapestry-release-version}</version>
</dependency>
|
...
Component Template
Code Block |
|
|
<t:form>
<t:errors/>
<input t:type="upload" t:id="file" t:value="file" validate="required"/>
<br/>
<input type="submit" value="Upload"/>
</t:form> |
Here, because the value parameter was not bound, the component used the file property of its container (because the component's id is 'file'). If you want to upload as a different property, either bind the value parameter or change the component's id.
Page class
Code Block |
|
|
public class UploadExample
{
@Property
private UploadedFile file;
public void onSuccess()
{
File copied = new File("/my/file/location/" + file.getFileName());
file.write(copied);
}
} |
...
The event handler should return a non-null object, which will be handled as a navigational result. Example:
Code Block |
|
|
@Persist(PersistenceConstants.FLASH)
@Property
private String message;
Object onUploadException(FileUploadException ex)
{
message = "Upload exception: " + ex.getMessage();
return this;
} |
...