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.repeater; 018 019import java.util.Iterator; 020 021import org.apache.wicket.Component; 022import org.apache.wicket.model.IModel; 023 024 025/** 026 * <p> 027 * A repeater view that renders all of its children, using its body markup, in the order they were 028 * added. 029 * 030 * </p> 031 * Example: 032 * <p> 033 * <u>Java:</u> 034 * 035 * <pre> 036 * RepeatingView view = new RepeatingView("repeater"); 037 * view.add(new Label(view.newChildId(), "hello")); 038 * view.add(new Label(view.newChildId(), "goodbye")); 039 * view.add(new Label(view.newChildId(), "good morning")); 040 * add(view); 041 * </pre> 042 * 043 * </p> 044 * <p> 045 * <u>Markup:</u> 046 * 047 * <pre> 048 * <ul><li wicket:id="repeater"></li></ul> 049 * </pre> 050 * 051 * </p> 052 * <p> 053 * <u>Yields:</u> 054 * 055 * <pre> 056 * <ul><li>hello</li><li>goodbye</li><li>good morning</li></ul> 057 * </pre> 058 * 059 * To expand a bit: the repeater itself produces no markup, instead every direct child inherits the 060 * entire markup of the repeater. In the example above repeaters's markup is: 061 * 062 * <pre> 063 * <li wicket:id="repeater"></li> 064 * </pre> 065 * 066 * and so this is the markup that is available to the direct children - the Label components. So as 067 * each label renders it produces a line of the output that has the <code>li</code>tag. 068 * 069 * @author Igor Vaynberg ( ivaynberg ) 070 */ 071public class RepeatingView extends AbstractRepeater 072{ 073 private static final long serialVersionUID = 1L; 074 075 /** Counter used for generating unique child component ids. */ 076 private long childIdCounter = 0; 077 078 /** @see Component#Component(String) */ 079 public RepeatingView(String id) 080 { 081 super(id); 082 } 083 084 /** @see Component#Component(String, IModel) */ 085 public RepeatingView(String id, IModel<?> model) 086 { 087 super(id, model); 088 } 089 090 /** 091 * Generates a unique id string. This makes it easy to add items to be rendered w/out having to 092 * worry about generating unique id strings in your code. 093 * 094 * @return unique child id 095 */ 096 public String newChildId() 097 { 098 childIdCounter++; 099 return String.valueOf(childIdCounter).intern(); 100 } 101 102 /** 103 * @see org.apache.wicket.markup.repeater.AbstractRepeater#renderIterator() 104 */ 105 @Override 106 protected Iterator<? extends Component> renderIterator() 107 { 108 return iterator(); 109 } 110 111 /** 112 * @see org.apache.wicket.markup.repeater.AbstractRepeater#onPopulate() 113 */ 114 @Override 115 protected void onPopulate() 116 { 117 // noop - population of this repeater is manual 118 } 119}