开发者

Wicket: How to show Javascript dialog when Form.MultiPart(true)

开发者 https://www.devze.com 2023-02-12 00:44 出处:网络
When I try to upload file in Wicket I\'ve got the following exception: \"ERROR org.apache.wicket.RequestCycle.logRuntimeException(RequestCycle.java:1529) - ServletRequest does not contain multipart c

When I try to upload file in Wicket I've got the following exception:

"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.MultipartSer开发者_如何学GovletWebRequest.<init>(MultipartServletWebRequest.java:113)..."

However, when I set form.MultiPart(true) I can't get Javascript dialog by using:

target.appendJavascript("Some Message");

Does somebody know how to use Javascript when Form.Multipart(true)?

Thanks!


If you want to call the alert dialog as a response for an ajax request, you can use the appendJavascript() method (the argument is javascript code, not a simple string, like the code you posted):

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

If you want to call the alert when the page loads, you could use a behavior:

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

It's also possible use a Label, and render directly to a <script> tag. Just remember to call setEscapeModelStrings(false):

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

and

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

精彩评论

暂无评论...
验证码 换一张
取 消