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.model; 018 019import org.apache.wicket.Component; 020 021/** 022 * Models that wish to substitute themselves with a wrapper when they are bound to a component 023 * (either through IModel parameter in a constructor or via a call to 024 * {@link Component#setDefaultModel(IModel)}) should implement this interface. One reason for a 025 * model to want to do this is if it needs to be aware of the component it is bound to. 026 * 027 * The algorithm wicket employs is similar to this: 028 * 029 * <pre> 030 * void Component.setModel(IModel model) 031 * { 032 * if (model instanceof IComponentAssignedModel) 033 * { 034 * this.model = ((IComponentAssignedModel)model).wrapOnAssignment(this); 035 * } 036 * else 037 * { 038 * this.model = model; 039 * } 040 * } 041 * </pre> 042 * 043 * For an example see {@link ResourceModel} 044 * 045 * @author jcompagner 046 * @author Igor Vaynberg (ivaynberg) 047 * @param <T> 048 * The model data type 049 */ 050public interface IComponentAssignedModel<T> extends IModel<T> 051{ 052 /** 053 * This method is called when the component gets its model assigned. 054 * 055 * WARNING: Because the model can be assigned in the constructor of component this method can 056 * also be called with a 'this' of a component that is not fully constructed yet. 057 * 058 * @param component 059 * @return The WrapModel that wraps this model 060 */ 061 IWrapModel<T> wrapOnAssignment(Component component); 062}