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.list;
018
019import java.util.List;
020
021import org.apache.wicket.model.CompoundPropertyModel;
022import org.apache.wicket.model.IModel;
023
024
025/**
026 * Simple ListVew subclass that wraps its item models in a {@link CompoundPropertyModel}. Useful for
027 * lists where the item components will be mapped through property expressions.
028 * 
029 * @author Nathan Hamblen
030 * 
031 * @param <T>
032 *            type of elements contained in the model's list
033 */
034public abstract class PropertyListView<T> extends ListView<T>
035{
036        /**
037         * 
038         */
039        private static final long serialVersionUID = 1L;
040
041        /**
042         * Construct without model, assume bound externally.
043         * 
044         * @param id
045         *            Wicket id
046         */
047        public PropertyListView(final String id)
048        {
049                super(id);
050        }
051
052        /**
053         * Construct with a model.
054         * 
055         * @param id
056         *            Wicket id
057         * @param model
058         *            wrapping a List
059         */
060        public PropertyListView(final String id, final IModel<? extends List<T>> model)
061        {
062                super(id, model);
063        }
064
065        /**
066         * Construct with a "small," unmodeled List. The object can not be detached and will reside in
067         * the session, but is convenient for lists of a limited size.
068         * 
069         * @param id
070         *            Wicket id
071         * @param list
072         *            unmodeled List
073         */
074        public PropertyListView(final String id, final List<T> list)
075        {
076                super(id, list);
077        }
078
079        /**
080         * Wraps a ListItemModel in a CompoundPropertyModel.
081         * 
082         * @param model
083         * @param index
084         * @return a CompoundPropertyModel wrapping a ListItemModel
085         */
086        @Override
087        protected IModel<T> getListItemModel(final IModel<? extends List<T>> model, final int index)
088        {
089                return new CompoundPropertyModel<T>(super.getListItemModel(model, index));
090        }
091}