Wicket:如何在Form.MultiPart(true)时显示Javascript对话框

时间:2011-02-20 19:24:35

标签: javascript wicket

当我尝试在Wicket上传文件时,我遇到以下异常:

"ERROR org.apache.wicket.RequestCycle.logRuntimeException(RequestCycle.java:1529) - ServletRequest does not contain multipart content. One possible solution is to explicitly call Form.setMultipart(true), Wicket tries its best to auto-detect multipart forms but there are certain situation where it cannot.
java.lang.IllegalStateException: ServletRequest does not contain multipart content. One possible solution is to explicitly call Form.setMultipart(true), Wicket tries its best to auto-detect multipart forms but there are certain situation where it cannot.
at org.apache.wicket.protocol.http.servlet.MultipartServletWebRequest.<init>(MultipartServletWebRequest.java:113)..."

但是,当我设置form.MultiPart(true)时,我无法使用以下方式获取Javascript对话框:

target.appendJavascript("Some Message");

有人在Form.Multipart(true)时知道如何使用Javascript吗?

谢谢!

1 个答案:

答案 0 :(得分:3)

如果要将警报对话框作为ajax请求的响应调用,可以使用appendJavascript()方法(参数是javascript代码,而不是简单的字符串,就像您发布的代码一样):

target.appendJavaScript("alert('Some message');");

如果您想在页面加载时调用警报,则可以使用以下行为:

add(new AbstractBehavior() { // or Behavior, on Wicket 1.5
    @Override
    public void renderHead(Component component, IHeaderResponse response) {
        response.renderOnLoadJavaScript("alert('Some message');");
    }
});

也可以使用Label,并直接渲染到&lt; script&gt;标签。请记得致电setEscapeModelStrings(false)

add(new Label("alert", "alert('Some message');").setEscapeModelStrings(false));

<script type="text/javascript" wicket:id="alert"></script>