Created
February 10, 2012 11:55
-
-
Save topriddy/1789043 to your computer and use it in GitHub Desktop.
This Gist demonstrates how to stop internal link from propagating events higher the dom level after handling it
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.sf.topriddy; | |
import org.apache.wicket.ajax.AjaxEventBehavior; | |
import org.apache.wicket.ajax.AjaxRequestTarget; | |
import org.apache.wicket.ajax.markup.html.AjaxFallbackLink; | |
import org.apache.wicket.markup.html.WebMarkupContainer; | |
import org.apache.wicket.markup.html.WebPage; | |
import org.apache.wicket.util.string.AppendingStringBuffer; | |
/** | |
* | |
* @author topriddy | |
*/ | |
public final class DivLinkExample extends WebPage { | |
public DivLinkExample() { | |
super(); | |
WebMarkupContainer container = new WebMarkupContainer("fieldLink"); | |
container.add(new AjaxEventBehavior("onclick") { | |
@Override | |
protected void onEvent(AjaxRequestTarget target) { | |
AppendingStringBuffer buffer = new AppendingStringBuffer(); | |
buffer.append("if(flag == 0){" | |
+ "alert('Field Link clicked');}else{flag = 0;}"); | |
target.appendJavaScript(buffer.toString()); | |
} | |
}); | |
add(container); | |
container.add(new AjaxFallbackLink("firstLink") { | |
@Override | |
public void onClick(AjaxRequestTarget target) { | |
AppendingStringBuffer buffer = new AppendingStringBuffer(); | |
buffer.append("flag = 1;alert('First Link clicked');"); | |
target.appendJavaScript(buffer.toString()); | |
} | |
}); | |
container.add(new AjaxFallbackLink("secondLink") { | |
@Override | |
public void onClick(AjaxRequestTarget target) { | |
AppendingStringBuffer buffer = new AppendingStringBuffer(); | |
buffer.append("flag = 1;alert('Second Link clicked');"); | |
target.appendJavaScript(buffer.toString()); | |
} | |
}); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> | |
<html xmlns:wicket="http://wicket.apache.org"> | |
<head> | |
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252"/> | |
<title>DivLinkExample</title> | |
<link rel="stylesheet" type="text/css" href="style.css"/> | |
<script type="text/javascript" src="js/jquery-1.7.1.js"></script> | |
<style type="text/css"> | |
.field{ | |
background-color: yellow; | |
width: 300px; | |
padding: 15px; | |
} | |
.field:hover | |
{ | |
background-color: green; | |
cursor: pointer; | |
} | |
</style> | |
<script type="text/javascript"> | |
var flag = 0; | |
</script> | |
</head> | |
<body> | |
<p> | |
Below is an example of how to stop event propagation in wicket | |
</p> | |
<div class="field" wicket:id="fieldLink"> | |
<ol> | |
<li><a href="#" wicket:id="firstLink">First Link (Stops Propagation)</a></li> | |
<li><a href="#" wicket:id="secondLink">Second Link (default - Propagates up)</a></li> | |
</ol> | |
</div> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment