Wicket生成JavaScript
程序员文章站
2022-03-09 14:04:13
...
一,前言
介绍用Wicket生成JavaScript比较方便的方法。
二,直接生成
参考 : https://cwiki.apache.org/WICKET/calling-wicket-from-javascript.html
HTML
<script type="text/javascript" wicket:id="myScript">/* script will be rendered here */</script>
Java
Label myScript = new Label("myScript", "callWicket();"); myScript.setEscapeModelStrings(false); // do not HTML escape JavaScript code add(myScript);
三,用VM模板
HTML (文件名是PortletBorder.html)
<wicket:fragment wicket:id="javascript"></wicket:fragment>
VM (文件名是PortletBorder.js)
<script type="text/javascript"> var ${name} = { title : '${title}', items : Ext.getDom('${name}') }; </script>
Java (文件名是PortletBorder.java)
Map<String, String> map = new HashMap<String, String>(); map.put("name", portletName); map.put("title", portletTitle); add(new VelocityPanel("javascript", Model.ofMap(map)) { @Override protected IResourceStream getTemplateResource() { return new PackageResourceStream(PortletBorder.class, "PortletBorder.js"); } });
//END