001/* 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017package org.apache.wicket.markup.renderStrategy; 018 019import org.apache.wicket.Component; 020import org.apache.wicket.MarkupContainer; 021import org.apache.wicket.markup.html.internal.HtmlHeaderContainer; 022import org.apache.wicket.util.lang.Args; 023import org.apache.wicket.util.visit.IVisit; 024import org.apache.wicket.util.visit.IVisitor; 025 026/** 027 * This has been Wicket's default header render strategy before WICKET 1.5 which uses 028 * {@link MarkupContainer#visitChildren(org.apache.wicket.util.visit.IVisitor)} to traverse the hierarchy to 029 * render the children headers. 030 * 031 * Since child contributions are added to the markup after the parent contributions, children may 032 * replace / modify existing settings. Which is not good. Instead the parent (container) should be 033 * in control (see <a href="https://issues.apache.org/jira/browse/WICKET-2693">WICKET-2693</a>). 034 * 035 * @author Juergen Donnerstag 036 */ 037public class ParentFirstHeaderRenderStrategy extends AbstractHeaderRenderStrategy 038{ 039 /** 040 * Construct. 041 */ 042 public ParentFirstHeaderRenderStrategy() 043 { 044 } 045 046 @Override 047 protected void renderChildHeaders(final HtmlHeaderContainer headerContainer, 048 final Component rootComponent) 049 { 050 Args.notNull(headerContainer, "headerContainer"); 051 Args.notNull(rootComponent, "rootComponent"); 052 053 // Only MarkupContainer can have children. Component's don't 054 if (rootComponent instanceof MarkupContainer) 055 { 056 // Visit the children with parent first, than children 057 ((MarkupContainer)rootComponent).visitChildren(new IVisitor<Component, Void>() 058 { 059 @Override 060 public void component(final Component component, final IVisit<Void> visit) 061 { 062 if (component.isVisibleInHierarchy()) 063 { 064 component.internalRenderHead(headerContainer); 065 } 066 else 067 { 068 visit.dontGoDeeper(); 069 } 070 } 071 }); 072 } 073 } 074}