Java 使用BootstrapDownloadLink刷新Wicket中的面板
我的问题很简单,但我不知道如何解决它。我有一个Java 使用BootstrapDownloadLink刷新Wicket中的面板,java,wicket,Java,Wicket,我的问题很简单,但我不知道如何解决它。我有一个feedbackPanel,如果BootstrapDownloadLink失败,我想显示一条错误消息。通过提交,我可以轻松做到: protected void onSubmit(AjaxRequestTarget target) { ... error("File_not_found"); //Wicket will print this on the feedback panel target.add(getModalPa
feedbackPanel
,如果BootstrapDownloadLink
失败,我想显示一条错误消息。通过提交,我可以轻松做到:
protected void onSubmit(AjaxRequestTarget target) {
...
error("File_not_found"); //Wicket will print this on the feedback panel
target.add(getModalPanel().getFeedbackPanel()); //But i need to refresh it first
}
但是这个按钮在一个面板中,我用一个populateItem填充它,这是我知道的唯一向它插入引导样式的方法。按钮的代码:
BootstrapDownloadLink downloadDocument = new BootstrapDownloadLink(IDITEMREPEATER, file) {
@Override
public void onClick() {
File file = (File)getModelObject();
if(file.exists()) {
IResourceStream resourceStream = new FileResourceStream(new org.apache.wicket.util.file.File(file));
getRequestCycle().scheduleRequestHandlerAfterCurrent(new ResourceStreamRequestHandler(resourceStream, file.getName()));
} else {
error(getString("error_fichero_no_existe"));
/// ???? need to refresh-> getModalPanel().getFeedbackPanel()
}
}
};
downloadDocument.setIconType(GlyphIconType.clouddownload);
downloadDocument.add(new AttributeModifier("title", getString("documentos.descargar")));
downloadDocument.add(new AttributeModifier("class", " btn btn-info negrita btn-xs center-block"));
downloadDocument.setVisible(Boolean.TRUE);
list.add(downloadDocument);
您可以使用
target.addChildren(getPage(),IFeedback.class)
。这将把页面中IFeedback接口的所有实例添加到AjaxRequestTarget
您还可以使用FeedbackPanel.class
而不是界面
或者使用
getPage()。如果您不想添加其他不相关的反馈面板,请访问(new IVisitor(){…})
以查找特定的反馈面板。您可以从AjaxDownloadLink
创建或扩展,例如
其主要思想是让一个AjaxBehavior
进行下载,您将获得一个public void onClick(AjaxRequestTarget)
,您可以在其中添加反馈面板
downloadBehavior = new AbstractAjaxBehavior()
{
private static final long serialVersionUID = 3472918725573624819L;
@Override
public void onRequest()
{
[...]
ResourceStreamRequestHandler handler = new ResourceStreamRequestHandler(
AjaxDownloadLink.this.getModelObject(), name);
handler.setContentDisposition(ContentDisposition.ATTACHMENT);
getComponent().getRequestCycle().scheduleRequestHandlerAfterCurrent(handler);
}
};
并在onclick中使用该行为:
@Override
public void onClick(AjaxRequestTarget aTarget)
{
String url = downloadBehavior.getCallbackUrl().toString();
if (addAntiCache) {
url = url + (url.contains("?") ? "&" : "?");
url = url + "antiCache=" + System.currentTimeMillis();
}
// the timeout is needed to let Wicket release the channel
aTarget.appendJavaScript("setTimeout(\"window.location.href='" + url + "'\", 100);");
}
什么是
BootstrapDownloadLink
?它不是wicket core的一部分?是的,它不是。对不起,我忘了。是一个从DownloadLink扩展并实现IBootStrapButton的类。我认为问题在于他的DownloadLink
在onclick中没有目标,因为它不是AjaxLink
?是的!我正在测试它,效果很好。更好的是,我可以用这个解决方案解决我遇到的其他问题。非常感谢!