Author: jdonnerstag
Date: Fri Feb 12 19:01:25 2010
New Revision: 909562
URL: http://svn.apache.org/viewvc?rev=909562&view=rev
Log:
wip on onMarkupAttached
Modified:
wicket/trunk/wicket/src/main/java/org/apache/wicket/Component.java
wicket/trunk/wicket/src/main/java/org/apache/wicket/MarkupContainer.java
wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/html/WebMarkupContainerWithAssociatedMarkup.java
wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/html/border/Border.java
wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/html/panel/Fragment.java
wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/html/panel/Panel.java
wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/html/form/CheckGroupDisabledTestPage.html
wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/html/form/CheckGroupDisabledTestPage_expected.html
wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/html/form/CheckGroupTestPage1.html
wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/html/form/CheckGroupTestPage1_expected.html
Modified: wicket/trunk/wicket/src/main/java/org/apache/wicket/Component.java
URL:
http://svn.apache.org/viewvc/wicket/trunk/wicket/src/main/java/org/apache/wicket/Component.java?rev=909562&r1=909561&r2=909562&view=diff
==============================================================================
--- wicket/trunk/wicket/src/main/java/org/apache/wicket/Component.java
(original)
+++ wicket/trunk/wicket/src/main/java/org/apache/wicket/Component.java Fri Feb
12 19:01:25 2010
@@ -2541,10 +2541,9 @@
try
{
// Render open tag
- boolean tagRendered = false;
if (getRenderBodyOnly() == false)
{
- tagRendered = renderComponentTag(tag);
+ renderComponentTag(tag);
}
markupStream.next();
@@ -2553,17 +2552,25 @@
{
// Render the body
onComponentTagBody(markupStream, tag);
+ }
- // Render close tag
- if ((tag.hasNoCloseTag() == false) &&
tagRendered)
+ // Render close tag
+ if (tag.isOpen())
+ {
+ if (openTag.isOpen())
{
- // Close the tag.
-
getResponse().write(tag.syntheticCloseTagString());
+ renderClosingComponentTag(markupStream,
tag, getRenderBodyOnly());
+ }
+ else if (getRenderBodyOnly() == false)
+ {
+ if (needToRenderTag(openTag))
+ {
+ // Close the manually opened
tag. And since the user might have changed the
+ // tag name ...
+
getResponse().write(tag.syntheticCloseTagString());
+ }
}
}
-
- // make sure we moved the cursor to the end.
- markupStream.next();
}
catch (RuntimeException re)
{
@@ -3820,9 +3827,8 @@
*
* @param tag
* The tag to write
- * @return true, if tag was rendered
*/
- protected final boolean renderComponentTag(ComponentTag tag)
+ protected final void renderComponentTag(ComponentTag tag)
{
if (needToRenderTag(tag))
{
@@ -3861,11 +3867,7 @@
// Write the tag
tag.writeOutput(getResponse(), !needToRenderTag(null),
getMarkup().getMarkupResourceStream().getWicketNamespace());
-
- return true;
}
-
- return false;
}
/**
Modified:
wicket/trunk/wicket/src/main/java/org/apache/wicket/MarkupContainer.java
URL:
http://svn.apache.org/viewvc/wicket/trunk/wicket/src/main/java/org/apache/wicket/MarkupContainer.java?rev=909562&r1=909561&r2=909562&view=diff
==============================================================================
--- wicket/trunk/wicket/src/main/java/org/apache/wicket/MarkupContainer.java
(original)
+++ wicket/trunk/wicket/src/main/java/org/apache/wicket/MarkupContainer.java
Fri Feb 12 19:01:25 2010
@@ -33,6 +33,7 @@
import org.apache.wicket.markup.MarkupType;
import org.apache.wicket.markup.RawMarkup;
import org.apache.wicket.markup.WicketTag;
+import org.apache.wicket.markup.html.HeaderPartContainer;
import org.apache.wicket.markup.resolver.ComponentResolvers;
import org.apache.wicket.model.IComponentInheritedModel;
import org.apache.wicket.model.IModel;
Modified:
wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/html/WebMarkupContainerWithAssociatedMarkup.java
URL:
http://svn.apache.org/viewvc/wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/html/WebMarkupContainerWithAssociatedMarkup.java?rev=909562&r1=909561&r2=909562&view=diff
==============================================================================
---
wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/html/WebMarkupContainerWithAssociatedMarkup.java
(original)
+++
wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/html/WebMarkupContainerWithAssociatedMarkup.java
Fri Feb 12 19:01:25 2010
@@ -19,21 +19,18 @@
import org.apache.wicket.Component;
import org.apache.wicket.markup.ComponentTag;
import org.apache.wicket.markup.IMarkupFragment;
-import org.apache.wicket.markup.MarkupException;
-import org.apache.wicket.markup.MarkupNotFoundException;
import org.apache.wicket.markup.MarkupStream;
import org.apache.wicket.markup.TagUtils;
import org.apache.wicket.markup.WicketTag;
import org.apache.wicket.markup.html.internal.HtmlHeaderContainer;
import org.apache.wicket.model.IModel;
-import org.apache.wicket.util.lang.Checks;
/**
* WebMarkupContainer with it's own markup and possibly <wicket:head> tag.
*
* @author Juergen Donnerstag
*/
-public abstract class WebMarkupContainerWithAssociatedMarkup extends
WebMarkupContainer
+public class WebMarkupContainerWithAssociatedMarkup extends WebMarkupContainer
{
private static final long serialVersionUID = 1L;
@@ -128,81 +125,4 @@
return childMarkup;
}
-
- /**
- * Convenience method for subclasses to call. It is exactly like you
would implement
- * getMarkup(child) in your subclass. The only difference is, you need
to provide the name of
- * tag, such as 'panel' in <wicket:panel>
- *
- * @param tagName
- * @param child
- * @return the markup fragment for the child
- */
- public final IMarkupFragment getMarkup(final String tagName, final
Component child)
- {
- Checks.argumentNotEmpty(tagName, "tagName");
-
- // get the associated markup resource file
- IMarkupFragment markup = getAssociatedMarkup();
- if (markup == null)
- {
- throw new MarkupException("Unable to find associated
markup file for: " +
- this.toString());
- }
-
- // Find <wicket:'name'>
- IMarkupFragment panelMarkup = findTag(markup, tagName);
- if (panelMarkup == null)
- {
- throw new MarkupNotFoundException("Expected to find
<wicket:" + tagName +
- "> in associated markup file. Markup: " +
markup.toString());
- }
-
- // If child == null, return the markup fragment starting with
the <wicket:border> tag
- if (child == null)
- {
- return panelMarkup;
- }
-
- // Find the markup for the child component
- panelMarkup = panelMarkup.find(child.getId());
- if (panelMarkup != null)
- {
- return panelMarkup;
- }
-
- return findMarkupInAssociatedFileHeader(markup, child);
- }
-
- /**
- * Search for <wicket:panel ...> on the same level.
- *
- * @param markup
- * @param name
- * @return null, if not found
- */
- private final IMarkupFragment findTag(final IMarkupFragment markup,
final String name)
- {
- MarkupStream stream = new MarkupStream(markup);
-
- while (stream.skipUntil(ComponentTag.class))
- {
- ComponentTag tag = stream.getTag();
- if (tag.isOpen() || tag.isOpenClose())
- {
- if (tag instanceof WicketTag)
- {
- if
(tag.getName().equalsIgnoreCase(name))
- {
- return
stream.getMarkupFragment();
- }
- }
- stream.skipToMatchingCloseTag(tag);
- }
-
- stream.next();
- }
-
- return null;
- }
}
\ No newline at end of file
Modified:
wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/html/border/Border.java
URL:
http://svn.apache.org/viewvc/wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/html/border/Border.java?rev=909562&r1=909561&r2=909562&view=diff
==============================================================================
---
wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/html/border/Border.java
(original)
+++
wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/html/border/Border.java
Fri Feb 12 19:01:25 2010
@@ -22,6 +22,9 @@
import org.apache.wicket.behavior.IBehavior;
import org.apache.wicket.markup.ComponentTag;
import org.apache.wicket.markup.IMarkupFragment;
+import org.apache.wicket.markup.MarkupElement;
+import org.apache.wicket.markup.MarkupException;
+import org.apache.wicket.markup.MarkupFragment;
import org.apache.wicket.markup.MarkupStream;
import org.apache.wicket.markup.WicketTag;
import org.apache.wicket.markup.html.TransparentWebMarkupContainer;
@@ -359,13 +362,50 @@
@Override
public IMarkupFragment getMarkup(final Component child)
{
+ // Border require an associated markup resource file
+ IMarkupFragment markup = getAssociatedMarkup();
+ if (markup == null)
+ {
+ throw new MarkupException("Unable to find associated
markup file for Border: " +
+ this.toString());
+ }
+
+ // Find <wicket:border>
+ IMarkupFragment childMarkup = null;
+ for (int i = 0; i < markup.size(); i++)
+ {
+ MarkupElement elem = markup.get(i);
+ if (elem instanceof WicketTag)
+ {
+ WicketTag tag = (WicketTag)elem;
+ if (tag.isBorderTag())
+ {
+ childMarkup = new
MarkupFragment(markup, i);
+ break;
+ }
+ }
+ }
+
+ // If child == null, return the markup fragment starting with
the <wicket:border> tag
+ if (child == null)
+ {
+ return childMarkup;
+ }
+
// Since we created the body component instance, identifying
that we found it is easy.
- if ((child != null) && (child == body))
+ if (child == body)
{
return body.getMarkup();
}
- return getMarkup(BORDER, child);
+ // Find the markup for the child component
+ childMarkup = childMarkup.find(child.getId());
+ if (childMarkup != null)
+ {
+ return childMarkup;
+ }
+
+ return findMarkupInAssociatedFileHeader(markup, child);
}
/**
Modified:
wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/html/panel/Fragment.java
URL:
http://svn.apache.org/viewvc/wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/html/panel/Fragment.java?rev=909562&r1=909561&r2=909562&view=diff
==============================================================================
---
wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/html/panel/Fragment.java
(original)
+++
wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/html/panel/Fragment.java
Fri Feb 12 19:01:25 2010
@@ -24,7 +24,7 @@
import org.apache.wicket.markup.MarkupException;
import org.apache.wicket.markup.MarkupNotFoundException;
import org.apache.wicket.markup.MarkupStream;
-import org.apache.wicket.markup.html.WebMarkupContainer;
+import org.apache.wicket.markup.html.WebMarkupContainerWithAssociatedMarkup;
import org.apache.wicket.markup.parser.XmlTag;
import org.apache.wicket.model.IModel;
import org.apache.wicket.util.lang.Objects;
@@ -52,7 +52,7 @@
*
* @author Juergen Donnerstag
*/
-public class Fragment extends WebMarkupContainer
+public class Fragment extends WebMarkupContainerWithAssociatedMarkup
{
private static final long serialVersionUID = 1L;
@@ -148,6 +148,12 @@
@Override
protected void onComponentTagBody(final MarkupStream markupStream,
final ComponentTag openTag)
{
+ // Skip the components body. It will be replaced by the fragment
+ if
(((ComponentTag)markupStream.get(markupStream.getCurrentIndex() - 1)).isOpen())
+ {
+ markupStream.skipRawMarkup();
+ }
+
final MarkupStream providerMarkupStream =
chooseMarkupStream(markupStream);
if (providerMarkupStream == null)
{
Modified:
wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/html/panel/Panel.java
URL:
http://svn.apache.org/viewvc/wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/html/panel/Panel.java?rev=909562&r1=909561&r2=909562&view=diff
==============================================================================
---
wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/html/panel/Panel.java
(original)
+++
wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/html/panel/Panel.java
Fri Feb 12 19:01:25 2010
@@ -19,7 +19,10 @@
import org.apache.wicket.Component;
import org.apache.wicket.markup.ComponentTag;
import org.apache.wicket.markup.IMarkupFragment;
+import org.apache.wicket.markup.MarkupException;
+import org.apache.wicket.markup.MarkupNotFoundException;
import org.apache.wicket.markup.MarkupStream;
+import org.apache.wicket.markup.WicketTag;
import org.apache.wicket.markup.html.WebMarkupContainerWithAssociatedMarkup;
import org.apache.wicket.markup.parser.XmlTag;
import org.apache.wicket.markup.parser.filter.WicketTagIdentifier;
@@ -116,6 +119,17 @@
// Render the associated markup
renderAssociatedMarkup(PANEL,
"Markup for a panel component has to contain part
'<wicket:panel>'");
+
+ if (wasOpenCloseTag == false)
+ {
+ // Skip any raw markup in the body
+ markupStream.skipRawMarkup();
+ if (markupStream.get().closes(openTag) == false)
+ {
+ throw new MarkupException("close tag not found
for tag: " + openTag.toString() +
+ ". Component: " + this.toString());
+ }
+ }
}
/**
@@ -124,6 +138,68 @@
@Override
public IMarkupFragment getMarkup(final Component child)
{
- return getMarkup(PANEL, child);
+ IMarkupFragment markup = getAssociatedMarkup();
+ if (markup == null)
+ {
+ throw new MarkupNotFoundException(
+ "Failed to find markup file associated with
panel. Panel: " + this.toString());
+ }
+
+ // Find <wicket:panel>
+ IMarkupFragment panelMarkup = findPanelTag(markup);
+ if (panelMarkup == null)
+ {
+ throw new MarkupNotFoundException(
+ "Expected to find <wicket:panel> in associated
markup file. Markup: " +
+ markup.toString());
+ }
+
+ // If child == null, than return the markup fragment starting
with <wicket:panel>
+ if (child == null)
+ {
+ return panelMarkup;
+ }
+
+ // Find the markup for the child component
+ IMarkupFragment childMarkup = panelMarkup.find(child.getId());
+ if (childMarkup != null)
+ {
+ return childMarkup;
+ }
+
+ return findMarkupInAssociatedFileHeader(markup, child);
+ }
+
+ /**
+ * Search for <wicket:panel ...> on the same level.
+ *
+ * @param markup
+ * @param name
+ * @return null, if not found
+ */
+ private final IMarkupFragment findPanelTag(final IMarkupFragment markup)
+ {
+ MarkupStream stream = new MarkupStream(markup);
+
+ while (stream.skipUntil(ComponentTag.class))
+ {
+ ComponentTag tag = stream.getTag();
+ if (tag.isOpen() || tag.isOpenClose())
+ {
+ if (tag instanceof WicketTag)
+ {
+ WicketTag wtag = (WicketTag)tag;
+ if (wtag.isPanelTag())
+ {
+ return
stream.getMarkupFragment();
+ }
+ }
+ stream.skipToMatchingCloseTag(tag);
+ }
+
+ stream.next();
+ }
+
+ return null;
}
}
Modified:
wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/html/form/CheckGroupDisabledTestPage.html
URL:
http://svn.apache.org/viewvc/wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/html/form/CheckGroupDisabledTestPage.html?rev=909562&r1=909561&r2=909562&view=diff
==============================================================================
---
wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/html/form/CheckGroupDisabledTestPage.html
(original)
+++
wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/html/form/CheckGroupDisabledTestPage.html
Fri Feb 12 19:01:25 2010
@@ -4,7 +4,7 @@
<!-- In addition test that chars are not converted from upper to lower
and vice versa -->
<FORM wicket:id="form">
<span wicket:id="group">
- <input type="checkbox" wicket:id="check1">check1</input>
+ <Input type="checkbox" wicket:id="check1">check1</input>
<span wicket:id="container">
<input type="checkbox"
wicket:id="check2">check2</input>
</span>
Modified:
wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/html/form/CheckGroupDisabledTestPage_expected.html
URL:
http://svn.apache.org/viewvc/wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/html/form/CheckGroupDisabledTestPage_expected.html?rev=909562&r1=909561&r2=909562&view=diff
==============================================================================
---
wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/html/form/CheckGroupDisabledTestPage_expected.html
(original)
+++
wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/html/form/CheckGroupDisabledTestPage_expected.html
Fri Feb 12 19:01:25 2010
@@ -4,7 +4,7 @@
<!-- In addition test that chars are not converted from upper to lower
and vice versa -->
<FORM wicket:id="form" id="form4" method="post"
action="?wicket:interface=:0:form::IFormSubmitListener::"><div
style="display:none"><input type="hidden" name="form4_hf_0" id="form4_hf_0"
/></div>
<span wicket:id="group">
- <input type="checkbox" wicket:id="check1"
id="group1-check12" name="group" value="check1" checked="checked"
disabled="disabled">check1</input>
+ <Input type="checkbox" wicket:id="check1"
id="group1-check12" name="group" value="check1" checked="checked"
disabled="disabled">check1</input>
<span wicket:id="container">
<input type="checkbox" wicket:id="check2"
id="group1-check23" name="group" value="check2" checked="checked"
disabled="disabled">check2</input>
</span>
Modified:
wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/html/form/CheckGroupTestPage1.html
URL:
http://svn.apache.org/viewvc/wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/html/form/CheckGroupTestPage1.html?rev=909562&r1=909561&r2=909562&view=diff
==============================================================================
---
wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/html/form/CheckGroupTestPage1.html
(original)
+++
wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/html/form/CheckGroupTestPage1.html
Fri Feb 12 19:01:25 2010
@@ -4,7 +4,7 @@
<!-- In addition test that chars are not converted from upper to lower
and vice versa -->
<FORM wicket:id="form">
<span wicket:id="group">
- <input type="checkbox" wicket:id="check1">check1</input>
+ <Input type="checkbox" wicket:id="check1">check1</input>
<span wicket:id="container">
<input type="checkbox"
wicket:id="check2">check2</input>
</span>
Modified:
wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/html/form/CheckGroupTestPage1_expected.html
URL:
http://svn.apache.org/viewvc/wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/html/form/CheckGroupTestPage1_expected.html?rev=909562&r1=909561&r2=909562&view=diff
==============================================================================
---
wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/html/form/CheckGroupTestPage1_expected.html
(original)
+++
wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/html/form/CheckGroupTestPage1_expected.html
Fri Feb 12 19:01:25 2010
@@ -4,7 +4,7 @@
<!-- In addition test that chars are not converted from upper to lower
and vice versa -->
<FORM wicket:id="form" id="form4" method="post"
action="?wicket:interface=:0:form::IFormSubmitListener::"><div
style="display:none"><input type="hidden" name="form4_hf_0" id="form4_hf_0"
/></div>
- <input type="checkbox" wicket:id="check1"
id="group1-check12" name="group" value="check1">check1</input>
+ <Input type="checkbox" wicket:id="check1"
id="group1-check12" name="group" value="check1">check1</input>
<span wicket:id="container">
<input type="checkbox" wicket:id="check2"
id="group1-check23" name="group" value="check2">check2</input>
</span>