5

我需要在 Wicket 模式窗口的标题栏中添加一个按钮。我在 Wicket API 中找不到任何有用的东西来帮助我。有没有办法以这种方式自定义标题栏?

4

4 回答 4

7

你可以在 CSS 的帮助下实现这种效果。创建您的自定义模式窗口(以防您不想创建自定义样式)并指定 css 资源。

package org.ru5.test;

import org.apache.wicket.ResourceReference;
import org.apache.wicket.extensions.ajax.markup.html.modal.ModalWindow;
import org.apache.wicket.markup.html.CSSPackageResource;
import org.apache.wicket.markup.html.resources.CompressedResourceReference;
import org.apache.wicket.model.IModel;

public class CustomModalWindow extends ModalWindow {
    private static final long serialVersionUID = 1L;

    private static ResourceReference CSS = new CompressedResourceReference(
            CustomModalWindow.class, "res/custom-modal.css");

    /**
     * Creates a new modal window component.
     * 
     * @param id
     *            Id of component
     */
    public CustomModalWindow(final String id) {
        super(id);
        init();
    }

    /**
     * Creates a new modal window component.
     * 
     * @param id
     *            Id of component
     * @param model
     *            Model
     */
    public CustomModalWindow(final String id, final IModel<?> model) {
        super(id, model);
        init();
    }

    private void init() {
        add(CSSPackageResource.getHeaderContribution(CSS));
    }

}

/org/ru5/test/CustomModalWindow.html

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:wicket="http://wicket.apache.org">
<body><wicket:panel><div wicket:id="content"></div></wicket:panel></body>
</html>

您需要的一切:

/org/ru5/test/res/custom-modal.css

.headBtn{position: absolute; z-index: 20001; top: 2px; left: 200px;}

/org/ru5/test/TestPanelForTestWindow.html

....
<div class="headBtn">
<input type="button" value="ok">
</div>
....

您可以尝试覆盖 modal.js 函数,或者在 JS DOM 的帮助下制作一个技巧。希望这会有所帮助。

于 2010-09-27T12:57:59.880 回答
3

根据 /org/apache/wicket/extension/ajax/markup/html/modal/res/modal.js 您不能通过 wicket api 修改模态窗口装饰器,因为模态窗口标记完全在 javascript 中定义。因此,与往常一样,您可以选择简单但不好的方式并自行替换 modal.js,或者您几乎无法真正更改显示后的模态窗口,使用 js 修改类“w_captionText”的跨度。或者可能是(我没有测试它)您可以在 Caption 属性中定义您自定义的代码,并告诉检票口不要在此 Caption 中转义特殊的 html 字符。可能会有所帮助。

于 2009-09-08T14:10:16.983 回答
2

有点破解,但有效:

import org.apache.wicket.extensions.ajax.markup.html.modal.ModalWindow;
import org.apache.wicket.model.IModel;

public class FixedModalWindow extends ModalWindow {
  private static final long serialVersionUID = 1L;

  public FixedModalWindow(String id) {
    super(id);
    setResizable(false);
  }

  public FixedModalWindow(String id, IModel<?> model) {
    super(id, model);
    setResizable(false);
  }

  @Override
  public FixedModalWindow setResizable(boolean resizable) {
    // Cannot set resizable on the FixedModalWindow
    return this;
  }

  @Override
  public boolean isResizable() {
    return false;
  }

  @Override
  protected Object getShowJavascript()
  {
    // Hack in some JS to remove the onMove handlers
    StringBuffer showJS = new StringBuffer();
    showJS.append(" ");
    showJS.append((String) super.getShowJavascript());
    showJS.append("var popupWindow = Wicket.Window.get();\n");
    showJS.append("var nullHandler = function() {};\n");
    showJS.append("if(popupWindow != null) {\n");
    showJS.append("popupWindow.bind(popupWindow.caption, nullHandler);\n");
    showJS.append("popupWindow.bind(popupWindow.bottomRight, nullHandler);\n");
    showJS.append("popupWindow.bind(popupWindow.bottomLeft, nullHandler);\n");
    showJS.append("popupWindow.bind(popupWindow.bottom, nullHandler);\n");
    showJS.append("popupWindow.bind(popupWindow.left, nullHandler);\n");
    showJS.append("popupWindow.bind(popupWindow.right, nullHandler);\n");
    showJS.append("popupWindow.bind(popupWindow.topLeft, nullHandler);\n");
    showJS.append("popupWindow.bind(popupWindow.topRight, nullHandler);\n");
    showJS.append("popupWindow.bind(popupWindow.top, nullHandler);\n");
    showJS.append("}\n");
    return showJS.toString();
  }

}
于 2010-10-16T21:48:17.807 回答
1

如何在检票口的模态窗口中隐藏关闭按钮?我们找到了这样的解决方案:

ModalWindow yourModal = new ModalWindow("yourModalID") {
        @Override
        public void show(AjaxRequestTarget pTarget) {
            super.show(pTarget);

            pTarget.appendJavascript(""//
                    + "var thisWindow = Wicket.Window.get();\n"//
                    + "if (thisWindow) {\n"//
                    + "$('.w_close').attr('style', 'display:none;');\n"//
                    + "}"//
            );
        }
}

实际上,您可以从模态窗口插入任何类,并以某种方式对其进行更改。希望它可以帮助某人:)

于 2014-04-18T06:55:47.710 回答