2 * Copyright 2005-2010 the original author or authors.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package org.wamblee.wicket.behavior;
18 import java.util.ArrayList;
19 import java.util.Arrays;
20 import java.util.List;
22 import org.apache.wicket.Application;
23 import org.apache.wicket.Component;
24 import org.apache.wicket.Response;
25 import org.apache.wicket.behavior.IBehavior;
26 import org.apache.wicket.markup.ComponentTag;
27 import org.apache.wicket.markup.html.IHeaderContributor;
28 import org.apache.wicket.markup.html.IHeaderResponse;
29 import org.apache.wicket.markup.html.internal.HeaderResponse;
32 * Composite behavior that allows combining a sequence of behaviors in one. This
33 * behavior return true by default for {@link #getStatelessHint(Component)}. It
34 * also returns false by default for {@link #isTemporary()}.
36 public class CompositeBehavior implements IBehavior, IHeaderContributor {
38 private List<IBehavior> behaviors;
41 * Constructs the behvavior
46 public CompositeBehavior(IBehavior... aBehaviors) {
47 behaviors = new ArrayList<IBehavior>(Arrays.asList(aBehaviors));
56 public void add(IBehavior aBehavior) {
57 behaviors.add(aBehavior);
61 public void bind(Component aComponent) {
62 for (IBehavior behavior : behaviors) {
63 behavior.bind(aComponent);
68 public void detach(Component aComponent) {
69 for (IBehavior behavior : behaviors) {
70 behavior.detach(aComponent);
75 public void exception(Component aComponent, RuntimeException aException) {
76 for (IBehavior behavior : behaviors) {
77 behavior.exception(aComponent, aException);
82 public void onComponentTag(Component aComponent, ComponentTag aTag) {
83 for (IBehavior behavior : behaviors) {
84 behavior.onComponentTag(aComponent, aTag);
89 public void renderHead(IHeaderResponse aResponse) {
90 for (IBehavior behavior : behaviors) {
91 if (behavior instanceof IHeaderContributor) {
92 ((IHeaderContributor) behavior).renderHead(aResponse);
98 public void beforeRender(Component aComponent) {
99 for (IBehavior behavior : behaviors) {
100 behavior.beforeRender(aComponent);
105 public void afterRender(Component aComponent) {
106 for (IBehavior behavior : behaviors) {
107 behavior.afterRender(aComponent);
112 public boolean getStatelessHint(Component aComponent) {
117 public boolean isEnabled(Component aComponent) {
118 for (IBehavior behavior : behaviors) {
119 if (!behavior.isEnabled(aComponent)) {
127 public boolean isTemporary() {