If you are using Maven you can add the wicket-velocity dependency (otherwise you can download the jar from http://wicketstuff.org/maven/repository/org/apache/wicket/wicket-velocity/)


Create a javascript file with a vm extension

<script language="JavaScript">
	function removeBlur(checked) {
		if(checked) {
			document.getElementById('${loginButtonId}').disabled = false; 
		} else {	
			document.getElementById('${loginButtonId}').disabled = true;

In your web page constructor add a javascript velocity header contributor

final Button loginButton = new Button("input-login-button", ...){...};
final Map<String, String> vars = new HashMap<String, String>(1); vars.put("loginButtonId", loginButton.getMarkupId());
return new VelocityHeaderContributor().add(new
VelocityJavascriptContributor(MyWebPage.class, "path/to/example-script.vm", Model.valueOf(vars), "nameOfScript"));

The "loginButtonId" will be replaced by the generated wicket markup id in our a javascript file named "nameOfScript.js" for our MyWebPage.class

  • No labels