Author: mgrigorov Date: Sun Jan 23 11:04:06 2011 New Revision: 1062384 URL: http://svn.apache.org/viewvc?rev=1062384&view=rev Log: WICKET-3338 Please provide a LabelLink or something similar
Move the logic for working with provided text for link label/body to AbstractLink. Now all Link impls can use that, not only ExternalLink. Modified: wicket/trunk/wicket-core/src/main/java/org/apache/wicket/markup/html/link/AbstractLink.java wicket/trunk/wicket-core/src/main/java/org/apache/wicket/markup/html/link/ExternalLink.java Modified: wicket/trunk/wicket-core/src/main/java/org/apache/wicket/markup/html/link/AbstractLink.java URL: http://svn.apache.org/viewvc/wicket/trunk/wicket-core/src/main/java/org/apache/wicket/markup/html/link/AbstractLink.java?rev=1062384&r1=1062383&r2=1062384&view=diff ============================================================================== --- wicket/trunk/wicket-core/src/main/java/org/apache/wicket/markup/html/link/AbstractLink.java (original) +++ wicket/trunk/wicket-core/src/main/java/org/apache/wicket/markup/html/link/AbstractLink.java Sun Jan 23 11:04:06 2011 @@ -31,25 +31,45 @@ public abstract class AbstractLink exten { private static final long serialVersionUID = 1L; + /** this link's label/body. */ + private final IModel<?> label; + + /** + * Construct. + * + * @param id + */ + public AbstractLink(String id) + { + this(id, null); + } + /** * Construct. * * @param id + * the component id * @param model + * the link's model */ public AbstractLink(String id, IModel<?> model) { - super(id, model); + this(id, model, null); } /** * Construct. * * @param id + * the component id + * @param model + * the link's model + * @param labelModel */ - public AbstractLink(String id) + public AbstractLink(String id, IModel<?> model, final IModel<?> labelModel) { - super(id); + super(id, model); + label = wrap(labelModel); } /** @@ -165,9 +185,16 @@ public abstract class AbstractLink exten getResponse().write(getBeforeDisabledLink()); } - // Render the body of the link - super.onComponentTagBody(markupStream, openTag); - + if ((label != null) && (label.getObject() != null)) + { + replaceComponentTagBody(markupStream, openTag, + getDefaultModelObjectAsString(label.getObject())); + } + else + { + // Render the body of the link + super.onComponentTagBody(markupStream, openTag); + } // Draw anything after the body? if (!isLinkEnabled() && getAfterDisabledLink() != null) { @@ -204,4 +231,12 @@ public abstract class AbstractLink exten tag.put("disabled", "disabled"); } } + + /** + * @return the link's label/body + */ + public IModel<?> getLabel() + { + return label; + } } Modified: wicket/trunk/wicket-core/src/main/java/org/apache/wicket/markup/html/link/ExternalLink.java URL: http://svn.apache.org/viewvc/wicket/trunk/wicket-core/src/main/java/org/apache/wicket/markup/html/link/ExternalLink.java?rev=1062384&r1=1062383&r2=1062384&view=diff ============================================================================== --- wicket/trunk/wicket-core/src/main/java/org/apache/wicket/markup/html/link/ExternalLink.java (original) +++ wicket/trunk/wicket-core/src/main/java/org/apache/wicket/markup/html/link/ExternalLink.java Sun Jan 23 11:04:06 2011 @@ -17,7 +17,6 @@ package org.apache.wicket.markup.html.link; import org.apache.wicket.markup.ComponentTag; -import org.apache.wicket.markup.MarkupStream; import org.apache.wicket.model.IModel; import org.apache.wicket.model.Model; import org.apache.wicket.request.cycle.RequestCycle; @@ -33,9 +32,6 @@ public class ExternalLink extends Abstra { private static final long serialVersionUID = 1L; - /** this links' label. */ - private final IModel<?> label; - private boolean contextRelative = false; /** @@ -56,10 +52,9 @@ public class ExternalLink extends Abstra */ public ExternalLink(final String id, final String href, final String label) { - super(id); + super(id, null, Model.of(label)); setDefaultModel(href != null ? new Model<String>(href) : null); - this.label = (label != null ? new Model<String>(label) : null); } /** @@ -87,10 +82,9 @@ public class ExternalLink extends Abstra */ public ExternalLink(final String id, final IModel<String> href, final IModel<?> label) { - super(id); + super(id, null, label); setDefaultModel(wrap(href)); - this.label = wrap(label); } /** @@ -198,42 +192,6 @@ public class ExternalLink extends Abstra } /** - * Handle the container's body. - * - * @param markupStream - * The markup stream - * @param openTag - * The open tag for the body - * @see org.apache.wicket.Component#onComponentTagBody(org.apache.wicket.markup.MarkupStream, - * org.apache.wicket.markup.ComponentTag) - */ - @Override - public void onComponentTagBody(final MarkupStream markupStream, final ComponentTag openTag) - { - // Draw anything before the body? - if (!isLinkEnabled() && getBeforeDisabledLink() != null) - { - getResponse().write(getBeforeDisabledLink()); - } - - if ((label != null) && (label.getObject() != null)) - { - replaceComponentTagBody(markupStream, openTag, - getDefaultModelObjectAsString(label.getObject())); - } - else - { - super.onComponentTagBody(markupStream, openTag); - } - - // Draw anything after the body? - if (!isLinkEnabled() && getAfterDisabledLink() != null) - { - getResponse().write(getAfterDisabledLink()); - } - } - - /** * @return True if this link is automatically prepended with ../ to make it relative to the * context root. */ @@ -254,12 +212,4 @@ public class ExternalLink extends Abstra this.contextRelative = contextRelative; return this; } - - /** - * @return label attribute - */ - public IModel<?> getLabel() - { - return label; - } } \ No newline at end of file