wicket中的java无状态modaldialog

57hvy0tb  于 2021-06-26  发布在  Java
关注(0)|答案(1)|浏览(378)

如何使用wicket创建无状态modaldialog?
我尝试了以下代码,但结果是出错。删除时不会发生错误 getStatelessHint() 重写,但这会使它有状态。如果不可能,那么使用不推荐的modalwindow是否可能?
html格式:

<!DOCTYPE html>
<html>
<head>
    <style>
        .modal-dialog { border-radius: 5px; }
        .modal-dialog .modal-dialog-content { display: flex; flex-direction: column; }
        .modal-dialog-overlay.current-focus-trap .modal-dialog-content { resize: both; }
        .modal-dialog .modal-dialog-form { margin: 0; padding: 0; overflow: hidden; flex: 1; display: flex; flex-direction: column; }
        .modal-dialog .modal-dialog-header { border-radius: 5px 5px 0px 0px; background: #ffb158; margin: 0; padding-top: 4px; text-align: center; }
        .modal-dialog .modal-dialog-body { flex: 1; overflow-y: auto; padding: 20px; }
        .modal-dialog .modal-dialog-footer { padding: 5px; }
    </style>
</head>
<body>
    <a wicket:id="openModalLink">Open modal</a>

    <div id="window" wicket:id="window"></div>

    <wicket:fragment wicket:id="modalContentFragment">
        <h1>Modal Dialog</h1>
        <a wicket:id="closeModalLink">Close modal</a>
    </wicket:fragment>
</body>
</html>

java 语:

package org.example.modaltest;

import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.ajax.markup.html.AjaxLink;
import org.apache.wicket.extensions.ajax.markup.html.modal.ModalDialog;
import org.apache.wicket.extensions.ajax.markup.html.modal.theme.DefaultTheme;
import org.apache.wicket.markup.html.GenericWebPage;
import org.apache.wicket.markup.html.panel.Fragment;

public class ModalPage extends GenericWebPage<Void> {
    public ModalPage() {
        ModalDialog window = new ModalDialog("window");
        window.add(new DefaultTheme());
        window.setMarkupId("window");
        window.setOutputMarkupId(true);
        add(window);

        Fragment modalContentFragment = new Fragment(ModalDialog.CONTENT_ID, "modalContentFragment", this);
        window.setContent(modalContentFragment);
        modalContentFragment.setOutputMarkupId(true);

        AjaxLink<Void> closeModalLink = new AjaxLink<Void>("closeModalLink") {
            @Override
            public void onClick(AjaxRequestTarget target) {
                target.add(window);
                ModalDialog window1 = (ModalDialog) findPage().get("window");
                window1.close(target);
            }

            @Override
            protected boolean getStatelessHint() {
                return true;
            }
        };
        closeModalLink.setOutputMarkupId(true);
        modalContentFragment.add(closeModalLink);

        AjaxLink<Void> openModalLink = new AjaxLink<Void>("openModalLink") {
            @Override
            public void onClick(AjaxRequestTarget target) {
                ModalDialog window1 = (ModalDialog) findPage().get("window");
                window1.open(target);
            }

            @Override
            protected boolean getStatelessHint() {
                return true;
            }
        };
        add(openModalLink);
    }
}

浏览器出错:
拒绝访问。您无权访问您请求的页面。返回主页
java异常:

16:34:16.382 [http-nio-8080-exec-4] WARN  o.a.w.c.r.h.ListenerRequestHandler - behavior not enabled; ignore call. Behavior org.apache.wicket.ajax.markup.html.AjaxLink$1@5a149041 at component [AjaxLink [Component id = closeModalLink]]
16:34:16.386 [http-nio-8080-exec-4] WARN  RequestCycleExtra -********************************
16:34:16.390 [http-nio-8080-exec-4] WARN  RequestCycleExtra - Handling the following exception
org.apache.wicket.core.request.handler.ListenerInvocationNotAllowedException: Behavior rejected interface invocation. Component: [AjaxLink [Component id = closeModalLink]] Behavior: org.apache.wicket.ajax.markup.html.AjaxLink$1@5a149041
    at org.apache.wicket.core.request.handler.ListenerRequestHandler.invoke(ListenerRequestHandler.java:276)
    at org.apache.wicket.core.request.handler.ListenerRequestHandler.invokeListener(ListenerRequestHandler.java:222)
    at org.apache.wicket.core.request.handler.ListenerRequestHandler.respond(ListenerRequestHandler.java:208)
    at org.apache.wicket.request.cycle.RequestCycle$HandlerExecutor.respond(RequestCycle.java:902)
    at org.apache.wicket.request.RequestHandlerExecutor.execute(RequestHandlerExecutor.java:63)
    at org.apache.wicket.request.cycle.RequestCycle.execute(RequestCycle.java:283)
    at org.apache.wicket.request.cycle.RequestCycle.processRequest(RequestCycle.java:254)
    at org.apache.wicket.protocol.http.WicketFilter.processRequestCycle(WicketFilter.java:276)
    at org.apache.wicket.protocol.http.WicketFilter.processRequest(WicketFilter.java:207)
    at org.apache.wicket.protocol.http.WicketFilter.doFilter(WicketFilter.java:306)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:199)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:494)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:137)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92)
    at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:651)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343)
    at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:407)
    at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
    at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:754)
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1376)
    at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
    at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
    at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
    at java.base/java.lang.Thread.run(Thread.java:834)
16:34:16.390 [http-nio-8080-exec-4] WARN  RequestCycleExtra -********************************
kt06eoxx

kt06eoxx1#

问题如下:无状态链接为每个请求创建一个新页面。新页面不知道模式对话框是以前打开的。因此,对嵌套closemodallink的请求被拒绝,因为它当前不可见。
您必须通过请求url传输有关打开对话框的信息。e、 g.您的closemodallink可以通过#updateajaxattributes()向其请求中添加一个参数,该参数在创建新页面时被选中,并在请求时自动打开对话框。

相关问题