1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package net.sf.beanform;
16
17 import net.sf.beanform.prop.BeanProperty;
18
19 import org.apache.hivemind.ApplicationRuntimeException;
20 import org.apache.tapestry.IRequestCycle;
21 import org.apache.tapestry.components.Block;
22 import org.apache.tapestry.form.IFormComponent;
23
24 /***
25 * Superclass for low level BeanForm components which must be wrapped by
26 * a {@link BeanFormRows} component.
27 *
28 * @see BeanFormLabel
29 * @see BeanFormField
30 *
31 * @author Daniel Gredler
32 */
33 public abstract class BeanFormRowComponent extends BeanFormComponent {
34
35 public Object getBean() {
36 return this.getBeanFormRows().getBeanForm().getBeanSafely();
37 }
38
39 public BeanProperty getProperty() {
40 return this.getBeanFormRows().getProperty();
41 }
42
43 public String getDisplayName() {
44 String name = this.getProperty().getName();
45 return this.getPage().getMessages().getMessage( name );
46 }
47
48 protected void addExtraBindings( IFormComponent field ) {
49 this.getBeanFormRows().addExtraBindings( field );
50 }
51
52 private BeanFormRows getBeanFormRows() {
53 IRequestCycle cycle = this.getPage().getRequestCycle();
54 BeanFormRows rows = (BeanFormRows) cycle.getAttribute( BeanFormRows.BEAN_FORM_ROWS_ATTRIBUTE );
55 if( rows == null ) throw new ApplicationRuntimeException( BeanFormMessages.noBeanFormRows( this ) );
56 return rows;
57 }
58
59 public Block getCustomFieldBlock() {
60 return this.getCustomFieldBlock( this.getProperty() );
61 }
62
63 public IFormComponent getCustomField() {
64 return this.getCustomField( this.getProperty() );
65 }
66
67 }