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.html.border; 018 019import org.apache.wicket.MarkupContainer; 020import org.apache.wicket.markup.IMarkupFragment; 021import org.apache.wicket.markup.html.WebMarkupContainer; 022import org.apache.wicket.model.IModel; 023import org.apache.wicket.util.lang.Args; 024 025/** 026 * This is a simple Container component which can be used to build Border like components. 027 * <p> 028 * Example: 029 * 030 * <pre> 031 * <u>Panel Markup:</u> 032 * .. 033 * <div wicket:id="myPanel"> 034 * My Panels body 035 * </div> 036 * .. 037 * 038 * <u>Panel associated Markup:</u> 039 * <wicket:panel> 040 * .. 041 * <div wicket:id="myBody"/> 042 * .. 043 * </wicket:panel> 044 * 045 * <u>Panel Java code:</u> 046 * class MyPanel extends Panel 047 * { 048 * .. 049 * public MyPanel(String id) 050 * { 051 * add(new Body("myBody", this); 052 * } 053 * .. 054 * } 055 * </pre> 056 * 057 * There can be any number of containers between the Panel and Body. You must only remember to 058 * provide the correct markup provider to the Body. 059 * 060 * @author Juergen Donnerstag 061 */ 062public class Body extends WebMarkupContainer 063{ 064 private static final long serialVersionUID = 1L; 065 066 private final MarkupContainer markupProvider; 067 068 /** 069 * Construct. 070 * 071 * @param id 072 * @param model 073 * @param markupProvider 074 * Usually a Panel 075 */ 076 public Body(final String id, final IModel<?> model, final MarkupContainer markupProvider) 077 { 078 super(id, model); 079 080 Args.notNull(markupProvider, "markupProvider"); 081 this.markupProvider = markupProvider; 082 } 083 084 /** 085 * Construct. 086 * 087 * @param id 088 * @param markupProvider 089 */ 090 public Body(String id, final MarkupContainer markupProvider) 091 { 092 this(id, null, markupProvider); 093 } 094 095 @Override 096 public IMarkupFragment getMarkup() 097 { 098 // Panel.getMarkup() returns the "calling" markup. Which is what we want. We do not want the 099 // <wicket:panel> markup. 100 return markupProvider.getMarkup(); 101 } 102}