com.taursys.xml
Class Parameter

java.lang.Object
  extended bycom.taursys.xml.Component
      extended bycom.taursys.xml.Parameter
All Implemented Interfaces:
MapperComponent
Direct Known Subclasses:
AbstractField, Attribute, TextNode

public class Parameter
extends Component

A Component which receives parameter values. A Parameter, unlike a TextField, is not a DocumentComponent. It cannot be bound to the XML document to render its value. It is intended as a way to gather parameters needed for opening a form (example accountNumber to open an account).

A Parameter receives its values before a TextField. Values are dispatched to Parameters immediately before the openForm method of the ServletForm is invoked, whereas values are dispatched to a TextField immediately after the openForm method.

This component has one required property. It is the parameter property. This identifies the name of the value which it should listen for and respond to in the request.

By default, this component uses an internal DefaultTextModel with a VariantValueHolder and a default data type of String. You can specify a different data type when you invoke the constructor of this component.

The following is an example of a Parameter which receives a birthdate:

   Parameter birthdate = new Parameter(DataTypes.TYPE_DATE);
   ...
   private void jbInit() throws Exception {
     birthdate.setParameter("birthdate");
     birthdate.setFormat(java.text.SimpleDateFormat.getInstance());
     birthdate.setFormatPattern("MM/dd/yyyy");
     ...
     this.add(birthdate);
   }

   protected void openForm() throws Exception {
     // search for record by birthdate
     PersonVO person = delegate.findByBirthdate(
         (Date)birthdate.getValue());
   }
 

This component can also be bound to an external ValueHolder. An external ValueHolder can be shared by multiple components. The propertyName specifies which property in the ValueHolder will be bound to this component. To bind this component, set the valueHolder and propertyName properties. You do not need to specify a data type when you bind to a ValueHolder. The following is an example of binding:

   Parameter latitude = new Parameter();
   Parameter longitude = new Parameter();
   VOValueHolder holder = new VOValueHolder();

   private void jbInit() throws Exception {
     holder.setValueObjectClass(LocationVO.class);

     latitude.setParameter("latitude");
     latitude.setValueHolder(holder);
     latitude.setPropertyName("physicalLatitude");

     longitude.setParameter("longitude");
     longitude.setValueHolder(holder);
     longitude.setPropertyName("physicalLongitude");
     ...
     this.add(latitude);
     this.add(longitude);
   }

   void showOnMapButton_actionPerformed(TriggerEvent e) throws Exception {
     OutputStream map = delegate.getMap((LocationVO)holder.getValueObject());
     ...
   }
 

See Also:
ValueHolder, TextField

Constructor Summary
Parameter()
          Constructs a new Parameter with a DefaultTextModel and a VariantValueHolder for a String data type.
Parameter(int javaDataType)
          Constructs a new Parameter with a DefaultTextModel and a VariantValueHolder for the given data type.
 
Method Summary
protected  TextModel createDefaultModel()
          Creates the default model used by this component
protected  TextModel createDefaultModel(int javaDataType)
          Creates the default model of given data type used by this component
 java.lang.String getDefaultValue()
          Get the defaultValue to be used if no input is received.
 java.text.Format getFormat()
          Returns the Format of the TextModel.
 java.lang.String getFormatPattern()
          Returns the Format pattern of the TextModel.
 TextModel getModel()
          Returns the model for this component
 java.lang.String getParameter()
          Returns the name of the parameter this components listens for
 java.lang.String getPropertyName()
          Returns the propertyName in the valueHolder where the model stores the value.
 java.lang.String getText()
          Returns the model value as a String (using Format if defined).
 java.lang.Object getValue()
          Returns the value of within the ValueHolder of the Model.
 ValueHolder getValueHolder()
          Returns the valueHolder for the model.
protected  void processParameterEvent(ParameterEvent e)
          Store value and fires parameter event if event has correct parameter name.
 void setDefaultValue(java.lang.String newDefaultValue)
          Set the defaultValue to be used if no input is received.
 void setFormat(java.text.Format format)
          Sets the Format of the TextModel.
 void setFormatPattern(java.lang.String newPattern)
          Sets the Format patten of the TextModel.
 void setModel(TextModel newModel)
          Sets the model used by this component.
 void setParameter(java.lang.String newParameter)
          Sets the name of the parameter this components listens for.
 void setPropertyName(java.lang.String newPropertyName)
          Sets the propertyName in the valueHolder where the model stores the value.
 void setText(java.lang.String text)
          Sets the model value from the given String (using Format if defined).
 void setValue(java.lang.Object value)
          Sets the value within the ValueHolder of the Model.
 void setValueHolder(ValueHolder newValueHolder)
          Sets the valueHolder for the model.
 java.lang.String toString()
          Returns a string representation of this object.
 
Methods inherited from class com.taursys.xml.Component
addEventType, addInputListener, addNotify, addParameterListener, addRecycleListener, addRenderListener, addTriggerListener, dispatchEvent, fireActionPerformed, fireInputReceived, fireParameterReceived, fireRecycle, fireRender, getEventTypeList, getParent, isNotifySet, isVisible, lazyAddNotify, lazyRemoveNotify, processEvent, processInputEvent, processRecycleEvent, processRenderEvent, processTriggerEvent, removeEventType, removeInputListener, removeNotify, removeParameterListener, removeRecycleListener, removeRenderListener, removeTriggerListener, setVisible
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Parameter

public Parameter()
Constructs a new Parameter with a DefaultTextModel and a VariantValueHolder for a String data type. The default model, a DefaultTextModel, is created via the createDefaultModel method. By default, the DefaultTextModel creates and uses a VariantValueHolder of type String.


Parameter

public Parameter(int javaDataType)
Constructs a new Parameter with a DefaultTextModel and a VariantValueHolder for the given data type. To specify the data type, use one of the TYPE_xxx constants defined in DataTypes.

Parameters:
javaDataType - data type for new model
See Also:
DataTypes
Method Detail

getModel

public TextModel getModel()
Returns the model for this component


setModel

public void setModel(TextModel newModel)
Sets the model used by this component. If the given model does not have a defined format, the format and pattern are copied from the old model.

Parameters:
newModel - to be used by this component.

createDefaultModel

protected TextModel createDefaultModel()
Creates the default model used by this component


createDefaultModel

protected TextModel createDefaultModel(int javaDataType)
Creates the default model of given data type used by this component

Parameters:
javaDataType - data type for new model
See Also:
for defined data type constants TYPE_XXX.

getText

public java.lang.String getText()
                         throws ModelException
Returns the model value as a String (using Format if defined). This method simply calls the getText method in the model.

Throws:
ModelException

setText

public void setText(java.lang.String text)
             throws ModelException
Sets the model value from the given String (using Format if defined). This method simply calls the setText method in the model.

Throws:
ModelException

getValue

public java.lang.Object getValue()
                          throws ModelException
Returns the value of within the ValueHolder of the Model. This method simply invokes the getPropertyValue of the model's valueHolder.

Throws:
ModelException

setValue

public void setValue(java.lang.Object value)
              throws ModelException
Sets the value within the ValueHolder of the Model. This method simply invokes the setPropertyValue of the model's valueHolder.

Throws:
ModelException

processParameterEvent

protected void processParameterEvent(ParameterEvent e)
                              throws java.lang.Exception
Store value and fires parameter event if event has correct parameter name.

Overrides:
processParameterEvent in class Component
Throws:
java.lang.Exception

setParameter

public void setParameter(java.lang.String newParameter)
Sets the name of the parameter this components listens for.


getParameter

public java.lang.String getParameter()
Returns the name of the parameter this components listens for


setFormat

public void setFormat(java.text.Format format)
Sets the Format of the TextModel.


getFormat

public java.text.Format getFormat()
Returns the Format of the TextModel.


setFormatPattern

public void setFormatPattern(java.lang.String newPattern)
Sets the Format patten of the TextModel.


getFormatPattern

public java.lang.String getFormatPattern()
Returns the Format pattern of the TextModel.


setValueHolder

public void setValueHolder(ValueHolder newValueHolder)
Sets the valueHolder for the model. The valueHolder is the object which holds the Object where the model stores the value. The default valueHolder is a VariantValueHolder with a javaDataType of String.


getValueHolder

public ValueHolder getValueHolder()
Returns the valueHolder for the model. The valueHolder is the object which holds the Object where the model stores the value. The default valueHolder is a VariantValueHolder with a javaDataType of String.


setPropertyName

public void setPropertyName(java.lang.String newPropertyName)
Sets the propertyName in the valueHolder where the model stores the value. This name is ignored if you are using the default model (A DefaultTextModel with a VariantValueHolder).


getPropertyName

public java.lang.String getPropertyName()
Returns the propertyName in the valueHolder where the model stores the value. This name is ignored if you are using the default model (A DefaultTextModel with a VariantValueHolder).


setDefaultValue

public void setDefaultValue(java.lang.String newDefaultValue)
Set the defaultValue to be used if no input is received. If this property is not null, it will be used during parameter dispatching whenever the expected parameter is NOT present in the input. In that case, it will be used as the value for the InputEvent.

Parameters:
newDefaultValue - to be used if no input is received.

getDefaultValue

public java.lang.String getDefaultValue()
Get the defaultValue to be used if no input is received. If this property is not null, it will be used during parameter dispatching whenever the expected parameter is NOT present in the input. In that case, it will be used as the value for the InputEvent.

Returns:
default value to be used if no input is received.

toString

public java.lang.String toString()
Returns a string representation of this object. This contains the object identity and state information.

Overrides:
toString in class Component
Returns:
a string representation of this object


Copyright © 2007 Martin T Phelan. All Rights Reserved.