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 net.sf.beanform.prop.BeanProperty; 018 019 import org.apache.hivemind.ApplicationRuntimeException; 020 import org.apache.tapestry.IRequestCycle; 021 import org.apache.tapestry.components.Block; 022 import org.apache.tapestry.form.IFormComponent; 023 024 /** 025 * Superclass for low level BeanForm components which must be wrapped by 026 * a {@link BeanFormRows} component. 027 * 028 * @see BeanFormLabel 029 * @see BeanFormField 030 * 031 * @author Daniel Gredler 032 */ 033 public abstract class BeanFormRowComponent extends BeanFormComponent { 034 035 public Object getBean() { 036 return this.getBeanFormRows().getBeanForm().getBeanSafely(); 037 } 038 039 public BeanProperty getProperty() { 040 return this.getBeanFormRows().getProperty(); 041 } 042 043 public String getDisplayName() { 044 String name = this.getProperty().getName(); 045 return this.getPage().getMessages().getMessage( name ); 046 } 047 048 protected void addExtraBindings( IFormComponent field ) { 049 this.getBeanFormRows().addExtraBindings( field ); 050 } 051 052 private BeanFormRows getBeanFormRows() { 053 IRequestCycle cycle = this.getPage().getRequestCycle(); 054 BeanFormRows rows = (BeanFormRows) cycle.getAttribute( BeanFormRows.BEAN_FORM_ROWS_ATTRIBUTE ); 055 if( rows == null ) throw new ApplicationRuntimeException( BeanFormMessages.noBeanFormRows( this ) ); 056 return rows; 057 } 058 059 public Block getCustomFieldBlock() { 060 return this.getCustomFieldBlock( this.getProperty() ); 061 } 062 063 public IFormComponent getCustomField() { 064 return this.getCustomField( this.getProperty() ); 065 } 066 067 }