Class FormComponentPanel<T>

Type Parameters:
T - The model object type
All Implemented Interfaces:
Serializable, Iterable<Component>, IEventSink, IEventSource, IFeedbackContributor, IConverterLocator, IGenericComponent<T,FormComponent<T>>, IMetadataContext<Serializable,Component>, IQueueRegion, IFormModelUpdateListener, IFormVisitorParticipant, ILabelProvider<String>, IHeaderContributor, IRequestableComponent, IHierarchical<Component>, IClusterable
Direct Known Subclasses:
LocalDateTimeField, MultiFileUploadField, Palette, TimeField, ZonedDateTimeField

public abstract class FormComponentPanel<T> extends FormComponent<T> implements IQueueRegion
Panel (has it's own markup, defined between <wicket:panel> tags), that can act as a form component. It typically wouldn't receive any input yourself, and often you can get by with nesting form components in panels proper. However, using this panel can help you with building components act to the outside world as one component, but internally uses separate components. This component would then use these nested components to handle it's internal state, and would use that internal state to get to one model object.

It is recommended that you override FormComponent.convertInput() and let it set the value that represents the compound value of the nested components. Often, this goes hand-in-hand with overriding FormComponent.onBeforeRender(), where you would analyze the model value, break it up and distribute the appropriate values over the child components.

Here is a simple example of a panel with two components that multiplies and sets that as the master model object. Note that for this simple example, setting the model value wouldn't make sense, as the lhs and rhs cannot be known.

 public class Multiply extends FormComponentPanel
 {
        private TextField left;
        private int lhs = 0;
        private int rhs = 0;
        private TextField right;
 
        public Multiply(String id)
        {
                super(id);
                init();
        }
 
        public Multiply(String id, IModel model)
        {
                super(id, model);
                init();
        }
 
        protected void convertInput()
        {
                Integer lhs = (Integer)left.getConvertedInput();
                Integer rhs = (Integer)right.getConvertedInput();
                setConvertedInput(lhs * rhs);
        }
 
        private void init()
        {
                add(left = new TextField("left", new PropertyModel(this, "lhs"), Integer.class));
                add(right = new TextField("right", new PropertyModel(this, "rhs"), Integer.class));
                left.setRequired(true);
                right.setRequired(true);
        }
 }
 
With this markup:
   <wicket:panel>
     <input type="text" wicket:id="left" size="2" /> * <input type="text" wicket:id="right" size="2" />
   </wicket:panel>
 
Which could be used, for example as:
   add(new Multiply("multiply"), new PropertyModel(m, "multiply")));
   add(new Label("multiplyLabel", new PropertyModel(m, "multiply")));
 
and:
   <span wicket:id="multiply">[multiply]</span>
   = <span wicket:id="multiplyLabel">[result]</span>
 

Author:
eelcohillenius
See Also: