Skip to content

Instantly share code, notes, and snippets.

@uklance
Last active August 29, 2015 14:06
Show Gist options
  • Save uklance/bdad1e26cc99b9eccbaa to your computer and use it in GitHub Desktop.
Save uklance/bdad1e26cc99b9eccbaa to your computer and use it in GitHub Desktop.
public class FileBean {
private UploadedFile file;
public void setUploadedFile(UploadedFile file) {
this.file = file;
}
public UploadedFile getUploadedFile() {
return file;
}
}
public class Page {
@Property
private List<FileBean> fileBeans;
@Property
private FileBean fileBean;
public ValueEncoder<FileBean> getFileBeanEncoder() {
return new ValueEncoder<FileBean> {
public String toClient(V value) {
return "placeholder";
}
// tapestry will call this for each placeholder on the client
// it will call FileBean.setUploadedFile() with the UploadedFile instance
public FileBean toValue(String client) {
if (fileBeans == null) {
fileBeans = new ArrayList<FileBean>();
}
FileBean value = new FileBean();
fileBeans.add(value);
return value;
}
};
}
public FileBean onAddRow() {
// initialize the fileBean property so that tapestry can render another row
fileBean = new FileBean();
// return the fileBean instance so that tapestry can store a placeholder on the client
return fileBean;
}
public void onSuccess() {
doStuff(fileBeans);
}
}
<t:ajaxformloop source="fileBeans" value="fileBean" encoder="fileBeanEncoder">
<t:upload t:value="fileBean.uploadedFile" />
</t:ajaxformloop>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment