use of org.apache.myfaces.view.facelets.tag.ComponentContainerHandler in project myfaces by apache.
the class CompositeComponentResourceTagHandler method applyNextHandlerIfNotApplied.
@SuppressWarnings("unchecked")
protected void applyNextHandlerIfNotApplied(FaceletContext ctx, UIComponent c) throws IOException {
// Apply all facelets not applied yet.
CompositeComponentBeanInfo beanInfo = (CompositeComponentBeanInfo) c.getAttributes().get(UIComponent.BEANINFO_KEY);
BeanDescriptor beanDescriptor = beanInfo.getBeanDescriptor();
boolean insertChildrenUsed = (beanDescriptor.getValue(InsertChildrenHandler.INSERT_CHILDREN_USED) != null);
List<String> insertFacetList = (List<String>) beanDescriptor.getValue(InsertFacetHandler.INSERT_FACET_USED);
if (nextHandler instanceof jakarta.faces.view.facelets.CompositeFaceletHandler) {
for (FaceletHandler handler : ((jakarta.faces.view.facelets.CompositeFaceletHandler) nextHandler).getHandlers()) {
if (handler instanceof jakarta.faces.view.facelets.FacetHandler) {
if (insertFacetList == null || !insertFacetList.contains(((jakarta.faces.view.facelets.FacetHandler) handler).getFacetName(ctx))) {
handler.apply(ctx, c);
}
} else if (handler instanceof InsertFacetHandler) {
if (insertFacetList == null || !insertFacetList.contains(((InsertFacetHandler) handler).getFacetName(ctx))) {
handler.apply(ctx, c);
}
} else if (insertChildrenUsed) {
if (!(handler instanceof jakarta.faces.view.facelets.ComponentHandler || handler instanceof ComponentContainerHandler || handler instanceof TextHandler)) {
handler.apply(ctx, c);
}
} else {
handler.apply(ctx, c);
}
}
} else {
if (nextHandler instanceof jakarta.faces.view.facelets.FacetHandler) {
if (insertFacetList == null || !insertFacetList.contains(((jakarta.faces.view.facelets.FacetHandler) nextHandler).getFacetName(ctx))) {
nextHandler.apply(ctx, c);
}
} else if (nextHandler instanceof InsertFacetHandler) {
if (insertFacetList == null || !insertFacetList.contains(((InsertFacetHandler) nextHandler).getFacetName(ctx))) {
nextHandler.apply(ctx, c);
}
} else if (insertChildrenUsed) {
if (!(nextHandler instanceof jakarta.faces.view.facelets.ComponentHandler || nextHandler instanceof ComponentContainerHandler || nextHandler instanceof TextHandler)) {
nextHandler.apply(ctx, c);
}
} else {
nextHandler.apply(ctx, c);
}
}
// Check for required facets
Map<String, PropertyDescriptor> facetPropertyDescriptorMap = (Map<String, PropertyDescriptor>) beanDescriptor.getValue(UIComponent.FACETS_KEY);
if (facetPropertyDescriptorMap != null) {
List<String> facetsRequiredNotFound = null;
for (Map.Entry<String, PropertyDescriptor> entry : facetPropertyDescriptorMap.entrySet()) {
ValueExpression requiredExpr = (ValueExpression) entry.getValue().getValue("required");
if (requiredExpr != null) {
Boolean required = (Boolean) requiredExpr.getValue(ctx.getFacesContext().getELContext());
if (Boolean.TRUE.equals(required)) {
initFacetHandlersMap(ctx);
if (!_facetHandlersMap.containsKey(entry.getKey())) {
if (facetsRequiredNotFound == null) {
facetsRequiredNotFound = new ArrayList(facetPropertyDescriptorMap.size());
}
facetsRequiredNotFound.add(entry.getKey());
}
}
}
}
if (facetsRequiredNotFound != null && !facetsRequiredNotFound.isEmpty()) {
throw new TagException(getTag(), "The following facets are required by the component: " + facetsRequiredNotFound);
}
}
}
Aggregations