001 // Copyright 2006-2007 Daniel Gredler
002 //
003 // Licensed under the Apache License, Version 2.0 (the "License");
004 // you may not use this file except in compliance with the License.
005 // You may obtain a copy of the License at
006 //
007 // http://www.apache.org/licenses/LICENSE-2.0
008 //
009 // Unless required by applicable law or agreed to in writing, software
010 // distributed under the License is distributed on an "AS IS" BASIS,
011 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
012 // See the License for the specific language governing permissions and
013 // limitations under the License.
014
015 package net.sf.beanform;
016
017 import java.util.List;
018 import java.util.Map;
019
020 import net.sf.beanform.binding.DualBinding;
021 import net.sf.beanform.prop.BeanProperty;
022
023 import org.apache.tapestry.IBinding;
024 import org.apache.tapestry.IMarkupWriter;
025 import org.apache.tapestry.IRequestCycle;
026 import org.apache.tapestry.form.IFormComponent;
027
028 /**
029 * A low level BeanForm component that generates the rows for all the properties.
030 * This component must be wrapped by a {@link BeanForm} component.
031 *
032 * @author Daniel Gredler
033 */
034 public abstract class BeanFormRows extends BeanFormComponent {
035
036 public final static String BEAN_FORM_ROWS_ATTRIBUTE = BeanFormRows.class.getName();
037
038 private BeanProperty property;
039 private Map<String, IBinding> fieldBindings;
040
041 public BeanProperty getProperty() {
042 return this.property;
043 }
044
045 public void setProperty( BeanProperty property ) {
046 this.property = property;
047 this.fieldBindings = this.getBeanForm().getFieldBindingsFor( property );
048 }
049
050 public List<BeanProperty> getProperties() {
051 return this.getBeanForm().getBeanProperties();
052 }
053
054 @Override
055 protected void renderComponent( IMarkupWriter writer, IRequestCycle cycle ) {
056 Object old = cycle.getAttribute( BEAN_FORM_ROWS_ATTRIBUTE );
057 cycle.setAttribute( BEAN_FORM_ROWS_ATTRIBUTE, this );
058 super.renderComponent( writer, cycle );
059 cycle.setAttribute( BEAN_FORM_ROWS_ATTRIBUTE, old );
060 }
061
062 protected void addExtraBindings( IFormComponent field ) {
063 DualBinding.addCustomBindings( field, this.fieldBindings, true );
064 }
065
066 }