Package org.apache.wicket.markup
Class ComponentTag
- java.lang.Object
-
- org.apache.wicket.markup.MarkupElement
-
- org.apache.wicket.markup.ComponentTag
-
- Direct Known Subclasses:
WicketTag
public class ComponentTag extends MarkupElement
A subclass of MarkupElement which represents a "significant" markup tag, such as a component open tag. Insignificant markup tags (those which are merely concerned with markup formatting operations and do not denote components or component nesting) are coalesced into instances of RawMarkup (also a subclass of MarkupElement).- Author:
- Jonathan Locke
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
ComponentTag.IAutoComponentFactory
Factory that creates component during markup root container's initialization.
-
Field Summary
Fields Modifier and Type Field Description static int
CONTAINS_WICKET_ID
If true, the current tag contains a child or a descendant with the "wicket:id" attributestatic int
RENDER_RAW
Render the tag as RawMarkup even if no Component can be foundprotected XmlTag
xmlTag
The underlying xml tag
-
Constructor Summary
Constructors Constructor Description ComponentTag(String name, XmlTag.TagType type)
Automatically create a XmlTag, assign the name and the type, and construct a ComponentTag based on this XmlTag.ComponentTag(ComponentTag tag)
ConstructorComponentTag(XmlTag tag)
Construct.
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description void
addBehavior(Behavior behavior)
Adds a behavior to this component tag.void
append(String key, CharSequence value, String separator)
Appends specifiedvalue
to the attributeboolean
closes(MarkupElement open)
Gets whether this tag closes the provided open tag.boolean
containsWicketId()
Says if the current tag contains a child or a descendant with the "wicket:id" attribute.void
enableAutolink(boolean autolink)
If autolink is set to true, href attributes will automatically be converted into Wicket bookmarkable URLs.boolean
equalTo(MarkupElement element)
This is not an implementation of equals because we don't care about hashCodes for MarkupElements yet.String
getAttribute(String name)
A convenient method.IValueMap
getAttributes()
ComponentTag.IAutoComponentFactory
getAutoComponentFactory()
Iterator<? extends Behavior>
getBehaviors()
boolean
getFlag(int flag)
THIS METHOD IS NOT PART OF THE WICKET PUBLIC API.String
getId()
Get the tag's component idint
getLength()
Gets the length of the tag in characters.Class<? extends Component>
getMarkupClass()
In case of inherited markup, the base and the extended markups are merged and the information about the tags origin is lost.String
getName()
String
getNamespace()
ComponentTag
getOpenTag()
If set, return the corresponding open tag (ComponentTag).int
getPos()
XmlTag.TagType
getType()
Object
getUserData(String key)
Gets userData.XmlTag
getXmlTag()
boolean
hasBehaviors()
boolean
hasNoCloseTag()
boolean
isAutoComponentTag()
boolean
isAutolinkEnabled()
True if autolink is enabled and the tag contains a href attribute.boolean
isClose()
boolean
isIgnore()
Gets ignore.boolean
isOpen()
boolean
isOpen(String id)
boolean
isOpenClose()
boolean
isOpenClose(String id)
void
makeImmutable()
Makes this tag object immutable by making the attribute map unmodifiable.ComponentTag
mutable()
Gets this tag if it is already mutable, or a mutable copy of this tag if it is immutable.void
onBeforeRender(Component component, MarkupStream markupStream)
For subclasses to override.void
put(String key, boolean value)
void
put(String key, int value)
void
put(String key, CharSequence value)
void
put(String key, StringValue value)
void
putAll(Map<String,Object> map)
void
putInternal(String key, CharSequence value)
THIS METHOD IS NOT PART OF THE PUBLIC API, DO NOT CALL ITvoid
remove(String key)
boolean
requiresCloseTag()
Gets whether this tag does not require a closing tag.void
setAutoComponentFactory(ComponentTag.IAutoComponentFactory autoComponentFactory)
void
setAutoComponentTag(boolean auto)
void
setContainsWicketId(boolean containsWicketId)
Sets the flag to indicate if the current tag contains a child or a descendant with the "wicket:id" attribute.void
setFlag(int flag, boolean set)
THIS METHOD IS NOT PART OF THE WICKET PUBLIC API.void
setHasNoCloseTag(boolean hasNoCloseTag)
True if the HTML tag (e.g.void
setId(String id)
Set the component's id.void
setIgnore(boolean ignore)
Sets ignore.<C extends Component>
voidsetMarkupClass(Class<C> wicketHeaderClass)
Set the class of wicket component which contains the wicket:head tag.void
setModified(boolean modified)
Manually mark the ComponentTag being modified.void
setName(String name)
void
setNamespace(String namespace)
void
setOpenTag(ComponentTag tag)
Assuming this is a close tag, assign it's corresponding open tag.void
setType(XmlTag.TagType type)
THIS METHOD IS NOT PART OF THE WICKET PUBLIC API.void
setUserData(String key, Object value)
Sets userData.CharSequence
syntheticCloseTagString()
Deprecated, for removal: This API element is subject to removal in a future version.use {writeSyntheticCloseTag(Response)
} insteadCharSequence
toCharSequence()
String
toString()
Converts this object to a string representation.String
toUserDebugString()
Converts this object to a string representation including useful information for debuggingvoid
writeOutput(Response response, boolean stripWicketAttributes, String namespace)
Write the tag to the responsevoid
writeSyntheticCloseTag(Response response)
Writes the synthetic close tag for this tag to the response
-
-
-
Field Detail
-
RENDER_RAW
public static final int RENDER_RAW
Render the tag as RawMarkup even if no Component can be found- See Also:
- Constant Field Values
-
CONTAINS_WICKET_ID
public static final int CONTAINS_WICKET_ID
If true, the current tag contains a child or a descendant with the "wicket:id" attribute- See Also:
- Constant Field Values
-
-
Constructor Detail
-
ComponentTag
public ComponentTag(String name, XmlTag.TagType type)
Automatically create a XmlTag, assign the name and the type, and construct a ComponentTag based on this XmlTag.- Parameters:
name
- The name of html tagtype
- The type of tag
-
ComponentTag
public ComponentTag(XmlTag tag)
Construct.- Parameters:
tag
- The underlying xml tag
-
ComponentTag
public ComponentTag(ComponentTag tag)
Constructor- Parameters:
tag
- The ComponentTag tag which this wicket tag is based upon.
-
-
Method Detail
-
setFlag
public final void setFlag(int flag, boolean set)
THIS METHOD IS NOT PART OF THE WICKET PUBLIC API. DO NOT USE IT!- Parameters:
flag
- The flag to setset
- True to turn the flag on, false to turn it off
-
getFlag
public final boolean getFlag(int flag)
THIS METHOD IS NOT PART OF THE WICKET PUBLIC API. DO NOT USE IT!- Parameters:
flag
- The flag to test- Returns:
- True if the flag is set
-
addBehavior
public final void addBehavior(Behavior behavior)
Adds a behavior to this component tag.- Parameters:
behavior
-
-
hasBehaviors
public final boolean hasBehaviors()
- Returns:
- true if this tag has any behaviors added, false otherwise
-
getBehaviors
public final Iterator<? extends Behavior> getBehaviors()
- Returns:
- read only iterator over added behaviors
-
closes
public final boolean closes(MarkupElement open)
Gets whether this tag closes the provided open tag.- Overrides:
closes
in classMarkupElement
- Parameters:
open
- The open tag- Returns:
- True if this tag closes the given open tag
-
enableAutolink
public final void enableAutolink(boolean autolink)
If autolink is set to true, href attributes will automatically be converted into Wicket bookmarkable URLs.- Parameters:
autolink
- enable/disable automatic href conversion
-
getAttributes
public final IValueMap getAttributes()
- Returns:
- The tag#s attributes
- See Also:
XmlTag.getAttributes()
-
getAttribute
public final String getAttribute(String name)
A convenient method. The same as getAttributes().getString(name)- Parameters:
name
-- Returns:
- The attributes value
-
getId
public final String getId()
Get the tag's component id- Returns:
- The component id attribute of this tag
-
getLength
public final int getLength()
Gets the length of the tag in characters.- Returns:
- The tag's length
-
getNamespace
public final String getNamespace()
- Returns:
- The tag's namespace
-
getOpenTag
public final ComponentTag getOpenTag()
If set, return the corresponding open tag (ComponentTag).- Returns:
- The corresponding open tag
-
getPos
public final int getPos()
- Returns:
- Tag location (index in input string)
- See Also:
XmlTag.getPos()
-
getType
public final XmlTag.TagType getType()
- Returns:
- the tag type (OPEN, CLOSE or OPEN_CLOSE).
-
isAutolinkEnabled
public final boolean isAutolinkEnabled()
True if autolink is enabled and the tag contains a href attribute.- Returns:
- True, if the href contained should automatically be converted
-
isClose
public final boolean isClose()
- Returns:
- True if this tag is a close tag
- See Also:
XmlTag.isClose()
-
isOpen
public final boolean isOpen()
- Returns:
- True if this tag is an open tag
- See Also:
XmlTag.isOpen()
-
isOpen
public final boolean isOpen(String id)
- Parameters:
id
- Required component id- Returns:
- True if this tag is an open tag with the given component name
- See Also:
XmlTag.isOpen()
-
isOpenClose
public final boolean isOpenClose()
- Returns:
- True if this tag is an open and a close tag
- See Also:
XmlTag.isOpenClose()
-
isOpenClose
public final boolean isOpenClose(String id)
- Parameters:
id
- Required component id- Returns:
- True if this tag is an openclose tag with the given component id
- See Also:
XmlTag.isOpenClose()
-
makeImmutable
public final void makeImmutable()
Makes this tag object immutable by making the attribute map unmodifiable. Immutable tags cannot be made mutable again. They can only be copied into new mutable tag objects.
-
mutable
public ComponentTag mutable()
Gets this tag if it is already mutable, or a mutable copy of this tag if it is immutable.- Returns:
- This tag if it is already mutable, or a mutable copy of this tag if it is immutable.
-
put
public final void put(String key, boolean value)
- Parameters:
key
- The keyvalue
- The value- See Also:
XmlTag.put(String, boolean)
-
put
public final void put(String key, int value)
- Parameters:
key
- The keyvalue
- The value- See Also:
XmlTag.put(String, int)
-
put
public final void put(String key, CharSequence value)
- Parameters:
key
- The keyvalue
- The value- See Also:
XmlTag.put(String, CharSequence)
-
putInternal
public final void putInternal(String key, CharSequence value)
THIS METHOD IS NOT PART OF THE PUBLIC API, DO NOT CALL IT- Parameters:
key
- The keyvalue
- The value- See Also:
XmlTag.put(String, CharSequence)
-
append
public final void append(String key, CharSequence value, String separator)
Appends specifiedvalue
to the attribute- Parameters:
key
- The keyvalue
- The valueseparator
- The separator used to append the value
-
put
public final void put(String key, StringValue value)
- Parameters:
key
- The keyvalue
- The value- See Also:
XmlTag.put(String, StringValue)
-
putAll
public final void putAll(Map<String,Object> map)
- Parameters:
map
- a key/value map- See Also:
XmlTag.putAll(Map)
-
remove
public final void remove(String key)
- Parameters:
key
- The key to remove- See Also:
XmlTag.remove(String)
-
requiresCloseTag
public final boolean requiresCloseTag()
Gets whether this tag does not require a closing tag.- Returns:
- True if this tag does not require a closing tag
-
setId
public final void setId(String id)
Set the component's id. The value is usually taken from the tag's id attribute, e.g. wicket:id="componentId".- Parameters:
id
- The component's id assigned to the tag.
-
setName
public final void setName(String name)
- Parameters:
name
- New tag name- See Also:
XmlTag.setName(String)
-
setNamespace
public final void setNamespace(String namespace)
- Parameters:
namespace
- New tag name namespace- See Also:
XmlTag.setNamespace(String)
-
setOpenTag
public final void setOpenTag(ComponentTag tag)
Assuming this is a close tag, assign it's corresponding open tag.- Parameters:
tag
- the open-tag- Throws:
RuntimeException
- if 'this' is not a close tag
-
setType
public final void setType(XmlTag.TagType type)
THIS METHOD IS NOT PART OF THE WICKET PUBLIC API. DO NOT CALL IT.- Parameters:
type
- The new type
-
syntheticCloseTagString
@Deprecated(since="9.10.0", forRemoval=true) public final CharSequence syntheticCloseTagString()
Deprecated, for removal: This API element is subject to removal in a future version.use {writeSyntheticCloseTag(Response)
} instead- Returns:
- A synthetic close tag for this tag
-
writeSyntheticCloseTag
public final void writeSyntheticCloseTag(Response response)
Writes the synthetic close tag for this tag to the response- Parameters:
response
- The response to write to
-
toCharSequence
public CharSequence toCharSequence()
- Specified by:
toCharSequence
in classMarkupElement
- Returns:
- Gets the charsequence representation of this element
- See Also:
MarkupElement.toCharSequence()
-
writeOutput
public final void writeOutput(Response response, boolean stripWicketAttributes, String namespace)
Write the tag to the response- Parameters:
response
- The response to write tostripWicketAttributes
- if true, wicket:id are removed from outputnamespace
- Wicket's namespace to use
-
toUserDebugString
public final String toUserDebugString()
Converts this object to a string representation including useful information for debugging- Specified by:
toUserDebugString
in classMarkupElement
- Returns:
- String version of this object
-
setModified
public final void setModified(boolean modified)
Manually mark the ComponentTag being modified. Flagging the tag being modified does not happen automatically.- Parameters:
modified
-
-
hasNoCloseTag
public boolean hasNoCloseTag()
- Returns:
- True if the HTML tag (e.g. br) has no close tag
-
setHasNoCloseTag
public void setHasNoCloseTag(boolean hasNoCloseTag)
True if the HTML tag (e.g. br) has no close tag- Parameters:
hasNoCloseTag
-
-
setContainsWicketId
public void setContainsWicketId(boolean containsWicketId)
Sets the flag to indicate if the current tag contains a child or a descendant with the "wicket:id" attribute.- Parameters:
containsWicketId
-
-
containsWicketId
public boolean containsWicketId()
Says if the current tag contains a child or a descendant with the "wicket:id" attribute.- Returns:
- true if the current tag contains a child or a descendant with the "wicket:id" attribute.
-
getMarkupClass
public Class<? extends Component> getMarkupClass()
In case of inherited markup, the base and the extended markups are merged and the information about the tags origin is lost. In some cases like wicket:head and wicket:link this information however is required.- Returns:
- wicketHeaderClass
-
setMarkupClass
public <C extends Component> void setMarkupClass(Class<C> wicketHeaderClass)
Set the class of wicket component which contains the wicket:head tag.- Type Parameters:
C
-- Parameters:
wicketHeaderClass
- wicketHeaderClass
-
equalTo
public boolean equalTo(MarkupElement element)
Description copied from class:MarkupElement
This is not an implementation of equals because we don't care about hashCodes for MarkupElements yet. Also, this method only compares the namespace, name and attributes of the given MarkupElements.- Specified by:
equalTo
in classMarkupElement
- Parameters:
element
- The markup element to compare with- Returns:
- True if the other element equals this one
- See Also:
MarkupElement.equalTo(org.apache.wicket.markup.MarkupElement)
-
isIgnore
public boolean isIgnore()
Gets ignore.- Returns:
- If true than MarkupParser will remove it from the markup
-
setIgnore
public void setIgnore(boolean ignore)
Sets ignore.- Parameters:
ignore
- If true than MarkupParser will remove it from the markup
-
isAutoComponentTag
public boolean isAutoComponentTag()
- Returns:
- True, if wicket:id has been automatically created (internal component)
-
setAutoComponentTag
public void setAutoComponentTag(boolean auto)
- Parameters:
auto
- True, if wicket:id has been automatically created (internal component)
-
getUserData
public Object getUserData(String key)
Gets userData.- Parameters:
key
- The key to store and retrieve the value- Returns:
- userData
-
setUserData
public void setUserData(String key, Object value)
Sets userData.- Parameters:
key
- The key to store and retrieve the valuevalue
- The user specific value to store
-
onBeforeRender
public void onBeforeRender(Component component, MarkupStream markupStream)
For subclasses to override. Gets called just before a Component gets rendered. It is guaranteed that the markupStream is set on the Component and determineVisibility is not yet called.- Parameters:
component
- The component that is about to be renderedmarkupStream
- The current markup stream
-
getAutoComponentFactory
public ComponentTag.IAutoComponentFactory getAutoComponentFactory()
-
setAutoComponentFactory
public void setAutoComponentFactory(ComponentTag.IAutoComponentFactory autoComponentFactory)
-
-