01: /*
02: * $Id: AjaxLink.java 461926 2006-08-24 13:12:07Z knopp $ $Revision: 461926 $
03: * $Date: 2006-08-24 15:12:07 +0200 (Thu, 24 Aug 2006) $
04: *
05: * ==============================================================================
06: * Licensed under the Apache License, Version 2.0 (the "License"); you may not
07: * use this file except in compliance with the License. You may obtain a copy of
08: * the License at
09: *
10: * http://www.apache.org/licenses/LICENSE-2.0
11: *
12: * Unless required by applicable law or agreed to in writing, software
13: * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
14: * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
15: * License for the specific language governing permissions and limitations under
16: * the License.
17: */
18: package wicket.ajax.markup.html;
19:
20: import wicket.ajax.AjaxEventBehavior;
21: import wicket.ajax.AjaxRequestTarget;
22: import wicket.ajax.IAjaxCallDecorator;
23: import wicket.ajax.calldecorator.CancelEventIfNoAjaxDecorator;
24: import wicket.markup.ComponentTag;
25: import wicket.markup.html.WebMarkupContainer;
26: import wicket.model.IModel;
27:
28: /**
29: * A component that allows a trigger request to be triggered via html anchor tag
30: *
31: * @since 1.2
32: *
33: * @author Igor Vaynberg (ivaynberg)
34: *
35: */
36: public abstract class AjaxLink extends WebMarkupContainer implements
37: IAjaxLink {
38: private static final long serialVersionUID = 1L;
39:
40: /**
41: * Construct.
42: *
43: * @param id
44: */
45: public AjaxLink(final String id) {
46: this (id, null);
47: }
48:
49: /**
50: * Construct.
51: *
52: * @param id
53: * @param model
54: */
55: public AjaxLink(final String id, final IModel model) {
56: super (id, model);
57:
58: add(new AjaxEventBehavior("onclick") {
59: private static final long serialVersionUID = 1L;
60:
61: protected void onEvent(AjaxRequestTarget target) {
62: onClick(target);
63: }
64:
65: protected IAjaxCallDecorator getAjaxCallDecorator() {
66: return new CancelEventIfNoAjaxDecorator(AjaxLink.this
67: .getAjaxCallDecorator());
68: }
69:
70: });
71: }
72:
73: protected void onComponentTag(ComponentTag tag) {
74: super .onComponentTag(tag);
75: // disable any href attr in markup
76: if (tag.getName().equalsIgnoreCase("a")
77: || tag.getName().equalsIgnoreCase("link")
78: || tag.getName().equalsIgnoreCase("area")) {
79: tag.put("href", "#");
80: }
81: }
82:
83: /**
84: * Returns ajax call decorator that will be used to decorate the ajax call.
85: *
86: * @return ajax call decorator
87: */
88: protected IAjaxCallDecorator getAjaxCallDecorator() {
89: return null;
90: }
91:
92: /**
93: * Listener method invoked on the ajax request generated when the user
94: * clicks the link
95: *
96: * @param target
97: */
98: public abstract void onClick(final AjaxRequestTarget target);
99: }
|