You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by eh...@apache.org on 2007/09/20 21:48:26 UTC
svn commit: r577894 - in
/wicket/trunk/jdk-1.5/wicket-examples/src/main/java/org/apache/wicket/examples/compref:
LinkPage.html LinkPage.java
Author: ehillenius
Date: Thu Sep 20 12:48:26 2007
New Revision: 577894
URL: http://svn.apache.org/viewvc?rev=577894&view=rev
Log:
added example of link state change record
Modified:
wicket/trunk/jdk-1.5/wicket-examples/src/main/java/org/apache/wicket/examples/compref/LinkPage.html
wicket/trunk/jdk-1.5/wicket-examples/src/main/java/org/apache/wicket/examples/compref/LinkPage.java
Modified: wicket/trunk/jdk-1.5/wicket-examples/src/main/java/org/apache/wicket/examples/compref/LinkPage.html
URL: http://svn.apache.org/viewvc/wicket/trunk/jdk-1.5/wicket-examples/src/main/java/org/apache/wicket/examples/compref/LinkPage.html?rev=577894&r1=577893&r2=577894&view=diff
==============================================================================
--- wicket/trunk/jdk-1.5/wicket-examples/src/main/java/org/apache/wicket/examples/compref/LinkPage.html (original)
+++ wicket/trunk/jdk-1.5/wicket-examples/src/main/java/org/apache/wicket/examples/compref/LinkPage.html Thu Sep 20 12:48:26 2007
@@ -21,6 +21,11 @@
</p>
<p>
+ Same as above, but this time a link that records a state change.<br />
+ <a href="#" wicket:id="linkWithStateChange">this link is clicked <span wicket:id="label">n</span> times</a>
+ </p>
+
+ <p>
And here is a link attached to a button element, with a nested label:<br />
<button wicket:id="link2">this button is clicked <span wicket:id="label2">n</span> times</button>
</p>
Modified: wicket/trunk/jdk-1.5/wicket-examples/src/main/java/org/apache/wicket/examples/compref/LinkPage.java
URL: http://svn.apache.org/viewvc/wicket/trunk/jdk-1.5/wicket-examples/src/main/java/org/apache/wicket/examples/compref/LinkPage.java?rev=577894&r1=577893&r2=577894&view=diff
==============================================================================
--- wicket/trunk/jdk-1.5/wicket-examples/src/main/java/org/apache/wicket/examples/compref/LinkPage.java (original)
+++ wicket/trunk/jdk-1.5/wicket-examples/src/main/java/org/apache/wicket/examples/compref/LinkPage.java Thu Sep 20 12:48:26 2007
@@ -22,6 +22,8 @@
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.link.Link;
import org.apache.wicket.model.Model;
+import org.apache.wicket.model.PropertyModel;
+import org.apache.wicket.version.undo.Change;
/**
@@ -51,7 +53,6 @@
}
};
add(link1);
-
// add a counter label to the link so that we can display it in the body
// of the link
link1.add(new Label("label1", new Model()
@@ -62,6 +63,33 @@
}
}));
+ final ClickCount count2 = new ClickCount();
+ // Same idea as above, but now we record a state change. Note that the
+ // URL will change because of this, and pressing the back button and
+ // clicking the link again would revert to the older value.
+ // The same thing could have been achieved by using setModelObject,
+ // which implicitly registers a state change (of type
+ // ComponentModelChange).
+ Link linkWithStateChange = new Link("linkWithStateChange")
+ {
+ public void onClick()
+ {
+ final int count = count1.clicks;
+ count2.clicks++;
+ addStateChange(new Change()
+ {
+ @Override
+ public void undo()
+ {
+ // revert
+ count2.clicks = count;
+ }
+ });
+ }
+ };
+ add(linkWithStateChange);
+ linkWithStateChange.add(new Label("label", new PropertyModel(count2, "clicks")));
+
// we can attach Link components to any HTML tag we want. If it is an
// anchor (<a href...),
// the url to this component is put in the href attribute. For other
@@ -69,9 +97,8 @@
// onclick javascript event handler is created that triggers the round
// trip
- // it is ofcourse possible to - instead of the above approach - hide as
- // much of the
- // component as possible within a class.
+ // it is of course possible to - instead of the above approach - hide as
+ // much of the component as possible within a class.
class CustomLink extends Link
{
final ClickCount count2;