diff options
author | Johannes Dahlström <johannesd@vaadin.com> | 2015-03-31 15:41:46 +0300 |
---|---|---|
committer | Johannes Dahlström <johannesd@vaadin.com> | 2015-04-07 15:21:50 +0300 |
commit | 8664c97c7bb6fb36b2ebbe3849b51ec00e052e24 (patch) | |
tree | 31451d8bf956cb2bfb686857f27f12e54703f67d /server/src/com/vaadin/ui/AbstractSingleComponentContainer.java | |
parent | 0f1dcd23a0bffae76fc312d95d7b64bf7861df88 (diff) | |
download | vaadin-framework-8664c97c7bb6fb36b2ebbe3849b51ec00e052e24.tar.gz vaadin-framework-8664c97c7bb6fb36b2ebbe3849b51ec00e052e24.zip |
Fix declarative support for Window (#17314)
Change-Id: If89a46a4c08ec1491eb00a2f2b8580fb3ef785fc
Diffstat (limited to 'server/src/com/vaadin/ui/AbstractSingleComponentContainer.java')
-rw-r--r-- | server/src/com/vaadin/ui/AbstractSingleComponentContainer.java | 33 |
1 files changed, 25 insertions, 8 deletions
diff --git a/server/src/com/vaadin/ui/AbstractSingleComponentContainer.java b/server/src/com/vaadin/ui/AbstractSingleComponentContainer.java index 244feb3bb9..767ae66515 100644 --- a/server/src/com/vaadin/ui/AbstractSingleComponentContainer.java +++ b/server/src/com/vaadin/ui/AbstractSingleComponentContainer.java @@ -19,6 +19,7 @@ import java.util.Collections; import java.util.Iterator; import org.jsoup.nodes.Element; +import org.jsoup.select.Elements; import com.vaadin.server.ComponentSizeValidator; import com.vaadin.server.VaadinService; @@ -288,17 +289,33 @@ public abstract class AbstractSingleComponentContainer extends public void readDesign(Element design, DesignContext designContext) { // process default attributes super.readDesign(design, designContext); - // handle child element, checking that the design specifies at most one - // child - int childCount = design.children().size(); - if (childCount > 1) { + readDesignChildren(design.children(), designContext); + } + + /** + * Reads the content component from the list of child elements of a design. + * The list must be empty or contain a single element; if the design + * contains multiple child elements, a DesignException is thrown. This + * method should be overridden by subclasses whose design may contain + * non-content child elements. + * + * @param children + * the child elements of the design that is being read + * @param context + * the DesignContext instance used to parse the design + * + * @throws DesignException + * if there are multiple child elements + * @throws DesignException + * if a child element could not be parsed as a Component + */ + protected void readDesignChildren(Elements children, DesignContext context) { + if (children.size() > 1) { throw new DesignException("The container of type " + getClass().toString() + " can have only one child component."); - } else if (childCount == 1) { - Element childElement = design.children().get(0); - Component newChild = designContext.readDesign(childElement); - setContent(newChild); + } else if (children.size() == 1) { + setContent(context.readDesign(children.first())); } } |