Buhake Sindi
Buhake Sindi

Reputation: 89169

Allowing UIComponent to be rendered inside a specific UIComponent

Let's take a simple scenario of HTML5 tag. A <html> tag can only permit one <head> and one <body> tag. Suppose we have a HTMLUIComponent, HTMLHeadUIComponent, HTMLBodyUIComponent represent each HTML tags specified above respectively, how would I allow that the HTMLHeadUIComponent and HTMLBodyUIComponent be rendered only inside a HTMLUIComponent and not in other component?

Upvotes: 1

Views: 182

Answers (1)

BalusC
BalusC

Reputation: 1108782

Easiest way would be to just do something like this during encodeBegin():

if (!(component.getParent() instanceof HTMLUIComponent)) {
    throw new IllegalArgumentException("HTMLHeadUIComponent must have a parent of type HTMLUIComponent");
}

If you need to do this during view build time (instead of view render time), then you can't go around creating and adding a tag handler for the component and do the check over there in apply() method.

Upvotes: 1

Related Questions