| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
package net.sf.beanform; |
| 16 |
|
|
| 17 |
|
import java.util.List; |
| 18 |
|
|
| 19 |
|
import net.sf.beanform.prop.BeanProperty; |
| 20 |
|
import net.sf.beanform.validator.CachingValidatorFactory; |
| 21 |
|
|
| 22 |
|
import org.apache.hivemind.ApplicationRuntimeException; |
| 23 |
|
import org.apache.tapestry.IComponent; |
| 24 |
|
import org.apache.tapestry.form.IPropertySelectionModel; |
| 25 |
|
import org.apache.tapestry.form.validator.Validator; |
| 26 |
|
|
| 27 |
|
|
| 28 |
|
|
| 29 |
|
|
| 30 |
|
|
| 31 |
|
|
| 32 |
|
|
| 33 |
19 |
public abstract class BeanFormField extends BeanFormRowComponent { |
| 34 |
|
|
| 35 |
|
public final static String PROPERTYSELECTION_FIELD_ID = "propertySelection"; |
| 36 |
|
public final static String TEXTFIELD_FIELD_ID = "textField"; |
| 37 |
|
public final static String TEXTAREA_FIELD_ID = "textArea"; |
| 38 |
|
public final static String CHECKBOX_FIELD_ID = "checkbox"; |
| 39 |
|
public final static String DATEPICKER_FIELD_ID = "datePicker"; |
| 40 |
|
public final static String UPLOAD_FIELD_ID = "upload"; |
| 41 |
|
public final static String INSERT_FIELD_ID = "insert"; |
| 42 |
|
|
| 43 |
|
final static String PROPERTYSELECTION_BLOCK_ID = "propertySelectionBlock"; |
| 44 |
|
final static String CUSTOM_BLOCK_ID = "customBlock"; |
| 45 |
|
final static String TEXTFIELD_BLOCK_ID = "textFieldBlock"; |
| 46 |
|
final static String TEXTAREA_BLOCK_ID = "textAreaBlock"; |
| 47 |
|
final static String CHECKBOX_BLOCK_ID = "checkboxBlock"; |
| 48 |
|
final static String DATEPICKER_BLOCK_ID = "datePickerBlock"; |
| 49 |
|
final static String UPLOAD_BLOCK_ID = "uploadBlock"; |
| 50 |
|
final static String INSERT_BLOCK_ID = "insertBlock"; |
| 51 |
|
|
| 52 |
|
public abstract CachingValidatorFactory getValidatorFactory(); |
| 53 |
|
|
| 54 |
|
public IComponent getFieldBlock() { |
| 55 |
7 |
BeanProperty property = this.getProperty(); |
| 56 |
7 |
if( this.hasPropertySelectionModel( property, true ) ) return this.getComponent( PROPERTYSELECTION_BLOCK_ID ); |
| 57 |
7 |
else if( this.hasCustomField( property ) ) return this.getComponent( CUSTOM_BLOCK_ID ); |
| 58 |
7 |
else if( property.usesTextField() ) return this.getComponent( TEXTFIELD_BLOCK_ID ); |
| 59 |
6 |
else if( property.usesTextArea() ) return this.getComponent( TEXTAREA_BLOCK_ID ); |
| 60 |
5 |
else if( property.usesCheckbox() ) return this.getComponent( CHECKBOX_BLOCK_ID ); |
| 61 |
4 |
else if( property.usesDatePicker() ) return this.getComponent( DATEPICKER_BLOCK_ID ); |
| 62 |
3 |
else if( property.usesUpload() ) return this.getComponent( UPLOAD_BLOCK_ID ); |
| 63 |
2 |
else if( property.usesInsert() ) return this.getComponent( INSERT_BLOCK_ID ); |
| 64 |
|
else { |
| 65 |
1 |
String msg = BeanFormMessages.cantFindFieldForProperty( property ); |
| 66 |
1 |
throw new ApplicationRuntimeException( msg ); |
| 67 |
|
} |
| 68 |
|
} |
| 69 |
|
|
| 70 |
|
public String getFieldId() { |
| 71 |
1 |
String id = this.getProperty().getName(); |
| 72 |
1 |
id = id.replace( '.', '_' ); |
| 73 |
1 |
return id; |
| 74 |
|
} |
| 75 |
|
|
| 76 |
|
public Object getValue() { |
| 77 |
1 |
BeanProperty property = this.getProperty(); |
| 78 |
1 |
if( property.isReadable() == false ) return null; |
| 79 |
1 |
property.setBean( this.getBean() ); |
| 80 |
1 |
return property.getValue(); |
| 81 |
|
} |
| 82 |
|
|
| 83 |
|
public void setValue( Object value ) { |
| 84 |
1 |
BeanProperty property = this.getProperty(); |
| 85 |
1 |
property.setBean( this.getBean() ); |
| 86 |
1 |
property.setValue( value ); |
| 87 |
1 |
} |
| 88 |
|
|
| 89 |
|
public boolean getDisabled() { |
| 90 |
2 |
return ( this.getProperty().isWriteable() == false ); |
| 91 |
|
} |
| 92 |
|
|
| 93 |
|
public List<Validator> getValidators() { |
| 94 |
1 |
BeanProperty property = this.getProperty(); |
| 95 |
1 |
CachingValidatorFactory factory = this.getValidatorFactory(); |
| 96 |
1 |
List<Validator> validators = factory.constructValidatorList( this, property ); |
| 97 |
1 |
return validators; |
| 98 |
|
} |
| 99 |
|
|
| 100 |
|
public IPropertySelectionModel getPropertySelectionModel() { |
| 101 |
3 |
BeanProperty property = this.getProperty(); |
| 102 |
3 |
return this.getPropertySelectionModel( property, true ); |
| 103 |
|
} |
| 104 |
|
|
| 105 |
|
} |