Java Tapestry在上传文件后注入表单字段
Java Tapestry在上传文件后注入表单字段,java,forms,tapestry,Java,Forms,Tapestry,版本: Tapestry版本:5.3.8 Tapestry jQuery:3.4.2 我的项目包括上传多个文件,将它们写入文件系统,为每个文件创建一个对象包装器,以便添加一些附加信息。这些信息将由用户在上传后使用表单创建。 不幸的是,当区域(在表单内:负责在上传文件时处理更新)更新时,我遇到了异常“元素必须由表单组件包围” Index.java public class Index { @Component private FormInjector injector;
版本:
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
上传文件
名称
版本
参考文献
${file.filename}
需要以下人员的帮助:
我试着使用FormInjector和Trigger组件,但我不知道它是如何工作的。现在我有一个例外:“环境中没有org.apache.tapestry5.services.FormSupport类型的对象可用” 有什么建议可以让这项工作顺利进行吗?
谢谢你的帮助 将
嵌套在
中。更多信息
<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>