当我以wicket形式添加文件上传器时,表单在提交后消失,而空白页面则反而出现。当我评论文件上传器字段时,每件事都可以。 谢谢你的帮助
在adduserPanel中的我调用UserClassPanel:
uploadfileForm = new Form("upoadfileWMC");
uploadfileForm.setOutputMarkupId(true);
uploadfileForm.setMultiPart(true);
uploadfileForm.setMaxSize(Bytes.kilobytes(500));
add(uploadfileForm);
uploadfileForm.setMultiPart(true);
add(uploadfileForm);
fileUploadField = new FileUploadField("fileUpload");
if (userClass.getdBId() == null) {
fileUploadField.setRequired(true);
}
fileUploadField.setOutputMarkupId(true);
fileUploadField.setLabel(Model.of("بارگذاری کارت ملی"));
fileUploadField.add(new BootstrapErrorAppender(fileUploadField));
final FeedbackPanel fileUploadfdk = new FeedbackPanel("fileUploadfdk", new ComponentFeedbackMessageFilter(fileUploadField));
fileUploadfdk.setOutputMarkupId(true);
uploadfileForm.add(fileUploadfdk);
uploadfileForm.add(fileUploadField);
AjaxSubmitLink upload = new AjaxSubmitLink("upload", uploadfileForm) {
@Override
protected void onError(AjaxRequestTarget target, Form<?> form) {
target.add(uploadfileForm);
target.add(feedback);
}
@Override
protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
final FileUpload uploadedFile = fileUploadField.getFileUpload();
try {
if (uploadedFile != null) {
// write to a new file
File newFile = new File(System.getProperty("java.io.tmpdir") + "/" + userClass.getMeliCode());
if (newFile.exists()) {
newFile.delete();
}
newFile.createNewFile();
uploadedFile.writeTo(newFile);
info("کارت ملی بارگذاری شد");
}
} catch (IOException ex) {
logger.warn("can't write upload file : " + ex);
error("خطا در ذخیره سازی عکس");
}
target.add(uploadfileForm);
target.add(feedback);
}
};
uploadfileForm.add(upload);
feedback = new FeedbackPanel("feedback", new ComponentFeedbackMessageFilter(upload));
feedback.setOutputMarkupId(true);
uploadfileForm.add(feedback);
UserClassPanel.html中的:
<form wicket:id="upoadfileWMC" class="form-group">
<!--<div wicket:id="upoadfileWMC" class="form-group">-->
<label dir="rtl" class="col-md-2 col-md-offset-1 control-label">بارگذاری کارت ملی</label>
<div class="col-md-5">
<input dir="rtl" wicket:id="fileUpload" type="file" class="form-control" id="choose-file" style="animation-fill-mode: both" required/>
<button wicket:id="upload" dir="rtl" type="submit" class="btn btn-success btn-lg btn-block">بارگذاری فایل</button>
<span class="help-block with-errors" wicket:id="fileUploadfdk"></span>
</div>
<!--</div>-->
<div wicket:id="feedback"></div>
</form>
并在addUserPanel.java中设置了一个AjaxSubmitLink,它以高层形式提交所有其他字段。
答案 0 :(得分:0)
我更改了我的脚本,因此发生了此事件。
@Override
public void renderHead(IHeaderResponse response) {
super.renderHead(response);
response.render(OnDomReadyHeaderItem.forScript(""
+ "$(document).ready(function() { "
// + " $(\"#" + locations.getMarkupId() + "\").select2({"
// + " language : \"fa\",dir:\"rtl\"});"
+ " $(\"#" + roles.getMarkupId() + "\").select2({"
+ " language : \"fa\",dir:\"rtl\"});"
+ " });"));
}
我评论2行,因为我删除了位置选择,我认为没有问题。顺便说一下现在好了。