版本:
Tapestry版本:5.3.8
Tapestry-jQuery:3.4.2
我的项目包括上传多个文件,将它们写在文件系统上,为每个文件创建一个对象包装器,以便添加一些额外的信息。这些信息将由用户使用上传后的表单创建。
不幸的是,当区域(在表单内部:负责在上传文件时处理更新)更新时,我有异常“元素必须由表单组件”包围。
Index.java
public class Index
{
@Component
private FormInjector injector;
@Component
private Form uploadForm;
@InjectComponent
private Zone uploadResult;
@Inject
private Block uploadFields;
@Persist
@Property
private List uploadedFiles;
@Persist
@Property
private List customFiles;
@Persist
@Property
private CustomFile file;
@Inject
private AjaxResponseRenderer ajaxResponseRenderer;
@Environmental
private JavaScriptSupport jsSupport;
@Environmental
private FormSupport formSupport;
@OnEvent(component = "injector")
Block loadUploadFields(){
return uploadFields;
}
@OnEvent(component = "uploadFiles", value = JQueryEventConstants.AJAX_UPLOAD)
void onDocUpload(UploadedFile uploadedFile) {
CustomFile file = new CustomFile();
if (uploadedFile != null) {
if(uploadedFiles==null) {
uploadedFiles = new ArrayList();
}
uploadedFiles.add(uploadedFile);
file.setFilename(uploadedFile.getFileName());
if (customFiles==null) {
customFiles = new ArrayList();
}
customFiles.add(file);
}
ajaxResponseRenderer.addRender(uploadResult);
}
public void onUploadedFile() {
jsSupport.addScript("$('#injector').trigger()");
}
}
Index.tml
<j:ajaxUpload t:id="uploadFiles" t:multiple="true">
</j:ajaxUpload>
<h4>Uploaded Files</h4>
<table>
<thead>
<th>Name</th>
<th>Version</th>
<th>Reference</th>
</thead>
<t:Form t:id="uploadForm">
<t:zone t:id="uploadResult" id="uploadResult" elementName="tbody">
<t:if test="uploadedFiles">
<t:loop source="customFiles" value="file" element="tr"
formState="none">
<td>${file.filename}</td>
<!-- To inject file.version and file.reference textfield -->
<!-- Avoid "must be enclosed by a form component" exception" -->
<t:FormInjector t:id="injector" id="injector" />
<t:block t:id="uploadFields">
<td>
<input t:type="TextField" t:value="file.version" t:id="version" />
</td>
<td>
<input t:type="TextField" t:value="file.reference" t:id="reference" />
</td>
</t:block>
<!-- Trigger event "uploadedFile" that will call $("#injector").trigger() -->
<t:Trigger event="uploadedFile" />
</t:loop>
</t:if>
</t:zone>
</t:Form>
</table>
</html>
在以下帮助下:
Updating a zone inside a form in Tapestry 5
我试图使用FormInjector和Trigger组件,但我无法弄清楚它是如何工作的。现在我有一个例外:“没有类型的对象org.apache.tapestry5.services.FormSupport可以从环境中获得”
有什么建议使这项工作?
感谢您的帮助!