You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Imants Firsts <im...@inbox.lv> on 2008/04/09 00:03:47 UTC
Using Upload inside a component
I would like to create a component, which I could add
to AppPropertyEditBlocks and would be able to edit
entity fields of type MyFile by utilizing tapestry
Upload component to upload the file.
AppPropertyEditBlocks.tml:
<t:block id="myfile">
<t:label for="myfileField"/>
<input t:id="myfileField"/>
</t:block>
AppPropertyEditBlocks.java:
@Component(parameters = {"value=context.propertyValue",
"label=prop:context.label",
"clientId=prop:context.propertyId"})
private MyFileField myfileField;
MyFileField.tml:
<input t:type="upload" t:value="uploadedFile"
xmlns:t="http://tapestry.apache.org/schema/tapestry_5_0_0.xsd"/>
public class MyFileField extends AbstractField {
@Parameter
private MyFile value;
@Property
private UploadedFile uploadedFile;
...
}
I would like to execute the following code on form
submission, so that my bound value parameter is updated
with just uploaded file.
if (uploadedFile != null) {
value = new MyFile(uploadedFile);
}
I have tried 2 solutions but none of them works:
1) This fails because processSubmission() for tapestry
Upload component is not called yet and thus
uploadedFile is always null.
protected void processSubmission(String elementName) {
if (uploadedFile != null) {
value = new MyFile(uploadedFile);
}
}
2) In this case uploadedFile is filled by tapestry
Upload, but the code fails, because value is bound to a
field, which uses PropertyContext, which is already
popped out of the Environment, when the defer() executes.
protected void processSubmission(String elementName) {
formSupport.defer(new Runnable() {
public void run() {
if (uploadedFile != null) {
value = new MyFile(uploadedFile);
}
}
});
}
Any solutions?
Thanks in advance,
Imants
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org