从Java生成Javascript弹出警报

时间:2015-04-23 14:13:39

标签: java javascript jquery wicket

如何从Java中生成Javascript弹出窗口?

我正在使用wicket / jquery库。

我尝试了以下但是失败并且找不到警报方法错误

import javax.script.*;

public class ExecuteScript {
  public static void main(String[] args) throws Exception {
    // create a script engine manager
    ScriptEngineManager factory = new ScriptEngineManager();
    // create a JavaScript engine
    ScriptEngine engine = factory.getEngineByName("JavaScript");
    // evaluate JavaScript code from String
    engine.eval("alert(\"Test\")");
  }
}

1 个答案:

答案 0 :(得分:0)

弹出对话框通常通过单击某个按钮(按钮)触发,或者您可以将new AjaxEventBehavior("click")添加到Wicket组件。下面的代码片段让您了解如何将它与AjaxButton一起使用。

public class MyPanel extends Panel {

  private ModalWindow modalWindow;

  public MyPanel(String id) {

    super(id);

    modalWindow = new ModalWindow("debugDialog");

    add(modalWindow);

    add(new AjaxButton("myButton") {
      protected void onSubmit(AjaxRequestTarget target) {

        Component dbgPanel = // Create a panel to contain the window content
        modalWindow.setContent(dbgPanel);
        modalWindow.show(target);
      }
    }
  }
}