在我的小组课程中,我有以下代码:
private Fragment fileUploadField(String id, UploadFeedbackPanel feedbackPanel, ComponentFeedbackPanel componentFeedbackPanel) {
String uploadType = isJSEnabled ? "multiple" : "single";
Fragment uploadFragment = new Fragment( "uploadContainer", uploadType, this );
if (isJSEnabled) {
multipleUpload = new MultiFileUploadField( id, new PropertyModel<Collection<FileUpload>>( this, "multiUploads" ), MAX_FILES );
uploadFragment.add( multipleUpload = multipleUpload);
multipleUpload.add( newOnChangeAjaxBehavior( feedbackPanel, componentFeedbackPanel ) );
} else {
uploadFragment.add( singleUpload = new FileUploadField( id ) );
singleUpload.add( newOnChangeAjaxBehavior( feedbackPanel, componentFeedbackPanel ) );
}
return uploadFragment;
}
我想为此字段添加标签,但我无法获取实际的输入字段ID。您可以看到这适用于单个上载字段,因为输入字段本身是渲染而没有任何周围元素。但是,在使用MultiFileUploadField
时,这似乎并未暴露出来。
另一种可接受的答案是使用FileUploadField
和具有multiple=true
属性的文件集合。但是,我不确定如何将文件数限制为MAX_FILES
。
<label wicket:for="file"><wicket:msg key="file">File:</wicket:msg></label>
<div wicket:id="uploadContainer" class="col-right">[upload fragment shows here]</div>
<wicket:fragment wicket:id="single">
<input wicket:id="file" type="file"/>
</wicket:fragment>
<wicket:fragment wicket:id="multiple">
<div wicket:id="file" class="mfuex"></div>
</wicket:fragment>
Wicket版本6.15.0。
答案 0 :(得分:0)
MultiFileUploadField
使用JavaScript生成输入字段:https://github.com/apache/wicket/blob/master/wicket-core/src/main/java/org/apache/wicket/markup/html/form/upload/MultiFileUploadField.js#L91
看看你是否可以以某种方式插入那里。如果你找到一种优雅的方式,我们很乐意将它包含在Wicket的下一个版本中!
如果您使用多个&#39;属性然后检查: How do I limit the number of file upload in html?