Author: ivaynberg
Date: Wed Jul 18 13:06:10 2007
New Revision: 557375
URL: http://svn.apache.org/viewvc?view=rev&rev=557375
Log:
WICKET-766 allow pragmatic markup id override
Modified:
incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/Component.java
incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/MarkupContainer.java
Modified:
incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/Component.java
URL:
http://svn.apache.org/viewvc/incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/Component.java?view=diff&rev=557375&r1=557374&r2=557375
==============================================================================
---
incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/Component.java
(original)
+++
incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/Component.java
Wed Jul 18 13:06:10 2007
@@ -461,8 +461,8 @@
*/
public String toString()
{
- return "VisibilityChange[component: " +
component.getPath() + ", visible: " + visible
- + "]";
+ return "VisibilityChange[component: " +
component.getPath() + ", visible: " + visible +
+ "]";
}
/**
@@ -680,8 +680,8 @@
private ArrayList behaviors = null;
/** Component flags. See FLAG_* for possible non-exclusive flag values.
*/
- private int flags = FLAG_VISIBLE | FLAG_ESCAPE_MODEL_STRINGS |
FLAG_VERSIONED | FLAG_ENABLED
- | FLAG_IS_RENDER_ALLOWED;
+ private int flags = FLAG_VISIBLE | FLAG_ESCAPE_MODEL_STRINGS |
FLAG_VERSIONED | FLAG_ENABLED |
+ FLAG_IS_RENDER_ALLOWED;
/** Component id. */
private String id;
@@ -808,11 +808,10 @@
getApplication().notifyComponentOnAfterRenderListeners(this);
if (getFlag(FLAG_AFTER_RENDERING))
{
- throw new IllegalStateException(
- Component.class.getName()
- + " has not
been properly detached. Something in the hierarchy of "
- +
getClass().getName()
- + " has not
called super.onAfterRender() in the override of onAfterRender() method");
+ throw new
IllegalStateException(Component.class.getName() +
+ " has not been properly
detached. Something in the hierarchy of " +
+ getClass().getName() +
+ " has not called
super.onAfterRender() in the override of onAfterRender() method");
}
// always detach children because components can be
attached
// independently of their parents
@@ -847,11 +846,10 @@
getApplication().notifyComponentOnBeforeRenderListeners(this);
if (!getFlag(FLAG_BEFORE_RENDERING_SUPER_CALL_VERIFIED))
{
- throw new IllegalStateException(
- Component.class.getName()
- + " has not
been properly rendered. Something in the hierarchy of "
- +
getClass().getName()
- + " has not
called super.onBeforeRender() in the override of onBeforeRender() method");
+ throw new
IllegalStateException(Component.class.getName() +
+ " has not been properly
rendered. Something in the hierarchy of " +
+ getClass().getName() +
+ " has not called
super.onBeforeRender() in the override of onBeforeRender() method");
}
onBeforeRenderChildren();
setFlag(FLAG_RENDERING, true);
@@ -893,10 +891,10 @@
onDetach();
if (getFlag(FLAG_DETACHING))
{
- throw new
IllegalStateException(Component.class.getName()
- + " has not been properly detached.
Something in the hierarchy of "
- + getClass().getName()
- + " has not called super.onDetach() in
the override of onDetach() method");
+ throw new
IllegalStateException(Component.class.getName() +
+ " has not been properly detached.
Something in the hierarchy of " +
+ getClass().getName() +
+ " has not called super.onDetach() in
the override of onDetach() method");
}
setFlag(FLAG_ATTACHED, false);
@@ -1181,13 +1179,13 @@
/**
* Retrieves id by which this component is represented within the
markup.
- * This is either the id attribute if it is set explicitly in the
markup, or
- * a generated id.
+ * This is either the id attribute set explicitly via a call to
+ * [EMAIL PROTECTED] #setMarkupId(String)}, id attribute defined in the
markup, or an
+ * automatically generated id - in that order.
* <p>
- * The point of this function is to generate a unique id to make it
easy to
- * locate this component in the generated markup for post-wicket
processing
- * such as javascript or an xslt transform in case no explicit id was
set
- * yet.
+ * If no explicit id is set this function will generate an id value that
+ * will be unique in the page. This is the preferred way as there is no
+ * chance of id collision.
* <p>
* Note: This method should only be called after the component or its
parent
* have been added to the page.
@@ -1219,11 +1217,39 @@
markupId = getId() + page.getAutoIndex();
// }
setMetaData(MARKUP_ID_KEY, markupId);
+
}
return markupId;
}
/**
+ * Sets this component's markup id to a user defined value. It is up to
the
+ * user to ensure this value is unique.
+ * <p>
+ * The recommended way is to let wicket generate the value
automatically,
+ * this method is here to serve as an override for that value in cases
where
+ * a specific id must be used.
+ * <p>
+ * If null is passed in the user defined value is cleared and markup id
+ * value will fall back on automatically generated value
+ *
+ * @see #getMarkupId()
+ *
+ * @param markupId
+ * markup id value or null to clear any previous user defined
+ * value
+ */
+ public void setMarkupId(String markupId)
+ {
+ if (markupId != null && Strings.isEmpty(markupId))
+ {
+ throw new IllegalArgumentException("Markup id cannot be
an empty string");
+ }
+ setMetaData(MARKUP_ID_KEY, markupId);
+
+ }
+
+ /**
* Gets metadata for this component using the given key.
*
* @param key
@@ -1866,8 +1892,8 @@
if (behaviors == null || !behaviors.contains(behavior))
{
throw new IllegalStateException(
- "Tried to remove a behavior that was
not added to the component. Behavior: "
- + behavior.toString());
+ "Tried to remove a behavior that was
not added to the component. Behavior: " +
+ behavior.toString());
}
if (!behavior.isTemporary())
@@ -2089,8 +2115,8 @@
{
// We were something other than <tag> or <tag/>
markupStream
- .throwMarkupException("Method
renderComponent called on bad markup element: "
- + tag);
+ .throwMarkupException("Method
renderComponent called on bad markup element: " +
+ tag);
}
if (tag.isOpenClose() && openTag.isOpen())
@@ -2130,7 +2156,8 @@
// rendered.
if (getRenderBodyOnly() == false)
{
- final boolean stripWicketTags =
Application.get().getMarkupSettings().getStripWicketTags();
+ final boolean stripWicketTags =
Application.get().getMarkupSettings()
+
.getStripWicketTags();
if (!(openTag instanceof
WicketTag) || !stripWicketTags)
{
// Close the manually
opened panel tag.
@@ -2224,8 +2251,8 @@
if (!getId().equals(replacement.getId()))
{
throw new IllegalArgumentException(
- "Replacement component must have the
same id as the component it will replace. Replacement id [["
- + replacement.getId() +
"]], replaced id [[" + getId() + "]].");
+ "Replacement component must have the
same id as the component it will replace. Replacement id [[" +
+ replacement.getId() +
"]], replaced id [[" + getId() + "]].");
}
if (parent == null)
{
@@ -2407,8 +2434,8 @@
if (model == null)
{
throw new IllegalStateException(
- "Attempt to set model object on null
model of component: "
- +
getPageRelativePath());
+ "Attempt to set model object on null
model of component: " +
+ getPageRelativePath());
}
// Check authorization
@@ -2837,8 +2864,8 @@
if (!tag.getName().equalsIgnoreCase(name))
{
findMarkupStream().throwMarkupException(
- "Component " + getId() + " must be
applied to a tag of type '" + name
- + "', not " +
tag.toUserDebugString());
+ "Component " + getId() + " must be
applied to a tag of type '" + name +
+ "', not " +
tag.toUserDebugString());
}
}
@@ -2863,9 +2890,9 @@
if (tagAttributeValue == null ||
!value.equalsIgnoreCase(tagAttributeValue))
{
findMarkupStream().throwMarkupException(
- "Component " + getId() + " must
be applied to a tag with '" + key
- + "' attribute
matching '" + value + "', not '" + tagAttributeValue
- + "'");
+ "Component " + getId() + " must
be applied to a tag with '" + key +
+ "' attribute
matching '" + value + "', not '" + tagAttributeValue +
+ "'");
}
}
}
@@ -2903,7 +2930,8 @@
{
model.detach();
}
- // also detach the wrapped model of a component assignet wrap
(not inherited)
+ // also detach the wrapped model of a component assignet wrap
(not
+ // inherited)
if (model instanceof IWrapModel &&
!getFlag(FLAG_INHERITABLE_MODEL))
{
((IWrapModel)model).getWrappedModel().detach();
@@ -2934,8 +2962,8 @@
{
if (parent == null)
{
- throw new IllegalStateException("Cannot find
markupstream for " + this
- + " as there is no parent");
+ throw new IllegalStateException("Cannot find
markupstream for " + this +
+ " as there is no parent");
}
return parent.findMarkupStream();
@@ -3152,8 +3180,8 @@
protected boolean isBehaviorAccepted(final IBehavior behavior)
{
// Ignore AttributeModifiers when
FLAG_IGNORE_ATTRIBUTE_MODIFIER is set
- if ((behavior instanceof AttributeModifier)
- && (getFlag(FLAG_IGNORE_ATTRIBUTE_MODIFIER) !=
false))
+ if ((behavior instanceof AttributeModifier) &&
+ (getFlag(FLAG_IGNORE_ATTRIBUTE_MODIFIER) !=
false))
{
return false;
}
@@ -3310,8 +3338,8 @@
if (!(tag instanceof WicketTag) || !stripWicketTags)
{
// Apply behavior modifiers
- if ((behaviors != null) && !behaviors.isEmpty() &&
!tag.isClose()
- && (isIgnoreAttributeModifier() ==
false))
+ if ((behaviors != null) && !behaviors.isEmpty() &&
!tag.isClose() &&
+ (isIgnoreAttributeModifier() == false))
{
tag = tag.mutable();
@@ -3393,9 +3421,9 @@
if ((markupOpenTag != null) && markupOpenTag.isOpen()
&& !markupStream.atCloseTag())
{
// There must be a component in this discarded
body
- markupStream.throwMarkupException("Expected
close tag for '" + markupOpenTag
- + "' Possible attempt to embed
component(s) '" + markupStream.get()
- + "' in the body of this
component which discards its body");
+ markupStream.throwMarkupException("Expected
close tag for '" + markupOpenTag +
+ "' Possible attempt to embed
component(s) '" + markupStream.get() +
+ "' in the body of this
component which discards its body");
}
}
}
@@ -3511,10 +3539,16 @@
return this;
}
throw new IllegalArgumentException(
- exceptionMessage("Component is not a container
and so does "
- + "not contain the path " +
path));
+ exceptionMessage("Component is not a container
and so does " +
+ "not contain the path " +
path));
}
+ /**
+ * Checks whether or not this component has a markup id value generated,
+ * whether it is automatic or user defined
+ *
+ * @return true if this component has a markup id value generated
+ */
final boolean hasMarkupIdMetaData()
{
return getMetaData(MARKUP_ID_KEY) != null;
@@ -3538,12 +3572,12 @@
if (!getFlag(FLAG_ATTACH_SUPER_CALL_VERIFIED))
{
throw new IllegalStateException(
- "Component "
- + this
- + " of type "
- +
getClass().getName()
- + " has not
been properly attached. "
- + "Something in
its class hierarchy has failed to call super.onAttach() in an override of
onAttach() method");
+ "Component " +
+ this +
+ " of type " +
+
getClass().getName() +
+ " has not been
properly attached. " +
+ "Something in
its class hierarchy has failed to call super.onAttach() in an override of
onAttach() method");
}
setFlag(FLAG_ATTACHING, false);
setFlag(FLAG_ATTACHED, true);
@@ -3642,11 +3676,6 @@
throw new WicketRuntimeException("Null component id is
not allowed.");
}
this.id = id;
- }
-
- final void setMarkupIdMetaData(String markupId)
- {
- setMetaData(MARKUP_ID_KEY, markupId);
}
/**
Modified:
incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/MarkupContainer.java
URL:
http://svn.apache.org/viewvc/incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/MarkupContainer.java?view=diff&rev=557375&r1=557374&r2=557375
==============================================================================
---
incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/MarkupContainer.java
(original)
+++
incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/MarkupContainer.java
Wed Jul 18 13:06:10 2007
@@ -136,7 +136,7 @@
public final MarkupContainer add(final Component child)
{
checkHierarchyChange(child);
-
+
if (child == null)
{
throw new IllegalArgumentException("argument child may
not be null");
@@ -151,8 +151,8 @@
addedComponent(child);
if (put(child) != null)
{
- throw new IllegalArgumentException(exceptionMessage("A
child with id '" + child.getId()
- + "' already exists"));
+ throw new IllegalArgumentException(exceptionMessage("A
child with id '" +
+ child.getId() + "' already exists"));
}
return this;
@@ -169,7 +169,7 @@
public final MarkupContainer addOrReplace(final Component child)
{
checkHierarchyChange(child);
-
+
if (child == null)
{
throw new IllegalArgumentException("argument child must
be not null");
@@ -204,8 +204,8 @@
* @param component
* The component to add
* @param markupStream
- * Null, if the parent container is able to provide the
markup.
- * Else the markup stream to be used to render the
component.
+ * Null, if the parent container is able to provide the
markup.
+ * Else the markup stream to be used to render the component.
* @return True, if component has been added
*/
public final boolean autoAdd(final Component component, final
MarkupStream markupStream)
@@ -233,20 +233,21 @@
}
return true;
}
-
+
/**
*
* @param component
* The component to add
* @return True, if component has been added
*
- * @deprecated since 1.3 Please use [EMAIL PROTECTED]
#autoAdd(Component, MarkupStream)} instead
+ * @deprecated since 1.3 Please use
+ * [EMAIL PROTECTED] #autoAdd(Component, MarkupStream)}
instead
*/
public final boolean autoAdd(final Component component)
{
return autoAdd(component, null);
}
-
+
/**
* @param component
* The component to check
@@ -351,7 +352,8 @@
{
try
{
- return
getApplication().getMarkupSettings().getMarkupCache().getMarkupStream(this,
false, throwException);
+ return
getApplication().getMarkupSettings().getMarkupCache().getMarkupStream(this,
+ false, throwException);
}
catch (MarkupException ex)
{
@@ -363,12 +365,9 @@
{
// throw exception since there is no associated markup
throw new MarkupNotFoundException(
- exceptionMessage("Markup of type '"
- + getMarkupType()
- + "' for component '"
- + getClass().getName()
- + "' not found."
- + " Enable debug
messages for org.apache.wicket.util.resource to get a list of all filenames
tried"),
+ exceptionMessage("Markup of type '" +
getMarkupType() + "' for component '" +
+ getClass().getName() +
"' not found." +
+ " Enable debug messages
for org.apache.wicket.util.resource to get a list of all filenames tried"),
ex);
}
}
@@ -520,7 +519,7 @@
public void remove(final Component component)
{
checkHierarchyChange(component);
-
+
if (component == null)
{
throw new IllegalArgumentException("argument component
may not be null");
@@ -550,8 +549,8 @@
}
else
{
- throw new WicketRuntimeException("Unable to find a
component with id '" + id
- + "' to remove");
+ throw new WicketRuntimeException("Unable to find a
component with id '" + id +
+ "' to remove");
}
}
@@ -573,8 +572,8 @@
public String toString()
{
- return "RemoveAllChange[component: " +
getPath() + ", removed Children: "
- + removedChildren + "]";
+ return "RemoveAllChange[component: " +
getPath() + ", removed Children: " +
+ removedChildren + "]";
}
public void undo()
@@ -641,23 +640,23 @@
setIgnoreAttributeModifier(true);
renderComponentTag(associatedMarkupOpenTag);
associatedMarkupStream.next();
-
- if
(getApplication().getDebugSettings().isOutputMarkupContainerClassName())
+
+ if
(getApplication().getDebugSettings().isOutputMarkupContainerClassName())
{
getResponse().write("<!-- MARKUP FOR ");
getResponse().write(getClass().getName());
getResponse().write(" BEGIN -->");
}
-
+
renderComponentTagBody(associatedMarkupStream,
associatedMarkupOpenTag);
-
+
if
(getApplication().getDebugSettings().isOutputMarkupContainerClassName())
{
getResponse().write("<!-- MARKUP FOR ");
getResponse().write(getClass().getName());
getResponse().write(" END -->");
}
-
+
renderClosingComponentTag(associatedMarkupStream,
associatedMarkupOpenTag, false);
setMarkupStream(originalMarkupStream);
}
@@ -679,7 +678,7 @@
public final MarkupContainer replace(final Component child)
{
checkHierarchyChange(child);
-
+
if (child == null)
{
throw new IllegalArgumentException("argument child must
be not null");
@@ -699,13 +698,13 @@
if (replaced == null)
{
throw new WicketRuntimeException(
- exceptionMessage("Cannot
replace a component which has not been added: id='"
- + child.getId()
+ "', component=" + child));
+ exceptionMessage("Cannot
replace a component which has not been added: id='" +
+ child.getId() +
"', component=" + child));
}
// first remove the component.
removedComponent(replaced);
-
+
// then add the other one.
addedComponent(child);
@@ -714,7 +713,7 @@
// The generated markup id remains the same
String replacedId = (replaced.hasMarkupIdMetaData()) ?
replaced.getMarkupId() : null;
- child.setMarkupIdMetaData(replacedId);
+ child.setMarkupId(replacedId);
}
return this;
@@ -843,23 +842,23 @@
value = visitor.component(child);
// If visitor returns a non-null value, it
halts the traversal
- if ((value != IVisitor.CONTINUE_TRAVERSAL)
- && (value !=
IVisitor.CONTINUE_TRAVERSAL_BUT_DONT_GO_DEEPER))
+ if ((value != IVisitor.CONTINUE_TRAVERSAL) &&
+ (value !=
IVisitor.CONTINUE_TRAVERSAL_BUT_DONT_GO_DEEPER))
{
return value;
}
}
// If child is a container
- if ((child instanceof MarkupContainer)
- && (value !=
IVisitor.CONTINUE_TRAVERSAL_BUT_DONT_GO_DEEPER))
+ if ((child instanceof MarkupContainer) &&
+ (value !=
IVisitor.CONTINUE_TRAVERSAL_BUT_DONT_GO_DEEPER))
{
// visit the children in the container
value =
((MarkupContainer)child).visitChildren(clazz, visitor);
// If visitor returns a non-null value, it
halts the traversal
- if ((value != IVisitor.CONTINUE_TRAVERSAL)
- && (value !=
IVisitor.CONTINUE_TRAVERSAL_BUT_DONT_GO_DEEPER))
+ if ((value != IVisitor.CONTINUE_TRAVERSAL) &&
+ (value !=
IVisitor.CONTINUE_TRAVERSAL_BUT_DONT_GO_DEEPER))
{
return value;
}
@@ -1236,8 +1235,8 @@
{
if (((WicketTag)tag).isChildTag())
{
-
markupStream.throwMarkupException("Found " + tag.toString()
- + " but no
<wicket:extend>");
+
markupStream.throwMarkupException("Found " + tag.toString() +
+ " but no
<wicket:extend>");
}
else
{
@@ -1246,10 +1245,10 @@
}
// No one was able to handle the component id
- markupStream.throwMarkupException("Unable to
find component with id '" + id
- + "' in " + this + ". This
means that you declared wicket:id=" + id
- + " in your markup, but that
you either did not add the "
- + "component to your page at
all, or that the hierarchy does not match.");
+ markupStream.throwMarkupException("Unable to
find component with id '" + id +
+ "' in " + this + ". This means
that you declared wicket:id=" + id +
+ " in your markup, but that you
either did not add the " +
+ "component to your page at all,
or that the hierarchy does not match.");
}
}
else
@@ -1334,8 +1333,8 @@
renderNext(markupStream);
if (index == markupStream.getCurrentIndex())
{
- markupStream.throwMarkupException("Component at
markup stream index " + index
- + " failed to advance the
markup stream");
+ markupStream.throwMarkupException("Component at
markup stream index " + index +
+ " failed to advance the markup
stream");
}
}
}
@@ -1372,8 +1371,8 @@
renderNext(markupStream);
if (index == markupStream.getCurrentIndex())
{
-
markupStream.throwMarkupException("Markup element at index " + index
- + " failed to advance
the markup stream");
+
markupStream.throwMarkupException("Markup element at index " + index +
+ " failed to advance the
markup stream");
}
}
}
@@ -1407,10 +1406,15 @@
onAttach();
if (!getFlag(FLAG_ATTACH_SUPER_CALL_VERIFIED))
{
- throw new IllegalStateException("Component " +
this + " of type " + getClass().getName() + " has not been properly attached. "
- + "Something in its class
hierarchy has failed to call super.onAttach() in an override of onAttach()
method");
+ throw new IllegalStateException(
+ "Component " +
+ this +
+ " of type " +
+
getClass().getName() +
+ " has not been
properly attached. " +
+ "Something in
its class hierarchy has failed to call super.onAttach() in an override of
onAttach() method");
}
-
+
visitChildren(new IVisitor()
{
public Object component(Component component)
@@ -1419,13 +1423,18 @@
component.onAttach();
if
(!component.getFlag(FLAG_ATTACH_SUPER_CALL_VERIFIED))
{
- throw new
IllegalStateException("Component " + component + " of type " +
component.getClass().getName() + " has not been properly attached. "
- + "Something in
its class hierarchy has failed to call super.onAttach() in an override of
onAttach() method");
+ throw new IllegalStateException(
+ "Component " +
+
component +
+
" of type " +
+
component.getClass().getName() +
+
" has not been properly attached. " +
+
"Something in its class hierarchy has failed to call super.onAttach() in an
override of onAttach() method");
}
return IVisitor.CONTINUE_TRAVERSAL;
}
});
-
+
visitChildren(new IVisitor()
{
public Object component(Component component)
@@ -1480,8 +1489,8 @@
}
else
{
- throw new WicketRuntimeException("Error
attaching this container for rendering: "
- + this, ex);
+ throw new WicketRuntimeException("Error
attaching this container for rendering: " +
+ this, ex);
}
}
}