com.taursys.xml
Class AttributeField

java.lang.Object
  extended bycom.taursys.xml.Component
      extended bycom.taursys.xml.Parameter
          extended bycom.taursys.xml.AbstractField
              extended bycom.taursys.xml.AttributeField
All Implemented Interfaces:
DocumentComponent, Element, MapperComponent
Direct Known Subclasses:
HTMLAnchorURL, HTMLInputText

public class AttributeField
extends AbstractField

A component which can receive input and/or render a value to an XML document element. This component can function in three different ways, depending on the properties you set:

When used for output, the value is rendered in the XML document element as a attribute by default. You can also render values to the additional element attributes. This can be done by invoking the setAttributeValue method. The following example illustrates this:

 private AttributeField projectStatus = new AttributeField();

 private void jbInit() throws Exception {
   projectStatus.setId("projectStatus");
   ...
   this.add(projectStatus);
 }

 protected void openForm() throws Exception {
   ...
   projectStatus.setValue("on-schedule");
   projectStatus.setAttributeValue("style","background: green;");
   ...
 }
 

After rendering the HTML document would appear as follows:

 ...
 <input type="text" id="projectStatus" style="background: green;" value="on-schedule" >
     ...
 

When used for input, this component receives its value from the InputDispatcher AFTER the openForm method of the ServletForm by default. If you want this component to receive its input earlier (at the same time as Parameters), set the earlyInputNotify property to true.

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. Below is an example:

   AttributeField salary = new AttributeField(DataTypes.TYPE_BIGDECIMAL);
 

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:

   AttributeField personId = new AttributeField(DataTypes.TYPE_INT);
   AttributeField lastName = new AttributeField();
   AttributeField city = new AttributeField();
   VOValueHolder holder = new VOValueHolder();

   private void jbInit() throws Exception {
     holder.setValueObjectClass(PersonVO.class);
     ...
     personId.setParameter("personId");
     personId.setId("personId");
     personId.setEarlyInputNotify(true);
     ...
     lastName.setId("lastName");
     lastName.setValueHolder(holder);
     lastName.setPropertyName("lastName");
     ...
     city.setId("city");
     city.setValueHolder(holder);
     city.setPropertyName("address.city");
     ...
     this.add(lastName);
     this.add(city);
   }

   protected void openForm() throws java.lang.Exception {
     holder.setValueObject(
         delegate.getPerson((Integer)personId.getValue());
     ...
   }
 

Notes: In the above example, the personId field is used as a parameter and display field. By setting its earlyInputNotify property to true, it will have its value available when the openForm method is invoked. It is not bound to the holder. The lastName field functions as a display only field. It is not configured as an input field. The same is true of the city field. Note the city field's property name: "address.city". The PersonVO has an "address" property of type AddressVO. The AddressVO in turn has a "city" property. The dot notation supports multiple levels of indirection.

See Also:
ValueHolder, Parameter

Constructor Summary
AttributeField()
          Constructs a new AttributeField with a default model and renderer.
AttributeField(int javaDataType)
          Creates a new AttributeField with a DefaultTextModel and VariantValueHolder of the given type.
 
Method Summary
protected  VisibleRenderer createDefaultRenderer()
          Deprecated. The TextFieldRender is no longer used. A TextField now contains a TextNode which uses a TextNodeRenderer.
 java.lang.String getAttributeName()
          Returns the name of the Element's attribute where the value should be rendered.
 VisibleRenderer getRenderer()
          Deprecated. The TextFieldRender is no longer used. A TextField now contains a TextNode which uses a TextNodeRenderer.
 void processRenderEvent(RenderEvent e)
          Responds to a render event for this component.
 void setAttributeName(java.lang.String newAttributeName)
          Sets the name of the Element's attribute where the value should be rendered.
 void setRenderer(VisibleRenderer newRenderer)
          Deprecated. The TextFieldRender is no longer used. A TextField now contains a TextNode which uses a TextNodeRenderer.
 
Methods inherited from class com.taursys.xml.AbstractField
addAttribute, addNotify, addTextNode, createAttribute, createAttribute, createAttribute, createBoundAttribute, createBoundTextNode, createTextNode, createTextNode, createTextNode, getAttribute, getAttributeText, getAttributeValue, getElementDelegate, getId, getTextNode, getTextNodeText, getTextNodeValue, isEarlyInputNotify, processInputEvent, removeAttribute, removeAttribute, removeNotify, removeTextNode, removeTextNode, setAttributeText, setAttributeValue, setEarlyInputNotify, setId, setTextNodeText, setTextNodeValue, setValueHolder, toString
 
Methods inherited from class com.taursys.xml.Parameter
createDefaultModel, createDefaultModel, getDefaultValue, getFormat, getFormatPattern, getModel, getParameter, getPropertyName, getText, getValue, getValueHolder, processParameterEvent, setDefaultValue, setFormat, setFormatPattern, setModel, setParameter, setPropertyName, setText, setValue
 
Methods inherited from class com.taursys.xml.Component
addEventType, addInputListener, addParameterListener, addRecycleListener, addRenderListener, addTriggerListener, dispatchEvent, fireActionPerformed, fireInputReceived, fireParameterReceived, fireRecycle, fireRender, getEventTypeList, getParent, isNotifySet, isVisible, lazyAddNotify, lazyRemoveNotify, processEvent, processRecycleEvent, processTriggerEvent, removeEventType, removeInputListener, removeParameterListener, removeRecycleListener, removeRenderListener, removeTriggerListener, setVisible
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

AttributeField

public AttributeField()
Constructs a new AttributeField with a default model and renderer. The default model, a VariantTextModel, is created via the createDefaultModel method in the Parameter superclass.


AttributeField

public AttributeField(int javaDataType)
Creates a new AttributeField with a DefaultTextModel and VariantValueHolder of the given type. See com.taursys.util.DataTypes for defined data type constants TYPE_XXXXXX.

Method Detail

setAttributeName

public void setAttributeName(java.lang.String newAttributeName)
Sets the name of the Element's attribute where the value should be rendered. The default is "value".

Overrides:
setAttributeName in class AbstractField

getAttributeName

public java.lang.String getAttributeName()
Returns the name of the Element's attribute where the value should be rendered. The default is "value".

Overrides:
getAttributeName in class AbstractField

createDefaultRenderer

protected VisibleRenderer createDefaultRenderer()
Deprecated. The TextFieldRender is no longer used. A TextField now contains a TextNode which uses a TextNodeRenderer.

Creates the default VisibleRenderer for this component. By Default this method returns a new VisibleRenderer. Override this method to define your own VisibleRenderer.


processRenderEvent

public void processRenderEvent(RenderEvent e)
                        throws RenderException
Responds to a render event for this component. This method simply notifies any RenderListeners of the event.

Specified by:
processRenderEvent in class AbstractField
Parameters:
e - the current render event message
Throws:
RenderException - if problem rendering value to document

setRenderer

public void setRenderer(VisibleRenderer newRenderer)
Deprecated. The TextFieldRender is no longer used. A TextField now contains a TextNode which uses a TextNodeRenderer.

Sets the renderer subcomponent used to render the value to the Document.


getRenderer

public VisibleRenderer getRenderer()
Deprecated. The TextFieldRender is no longer used. A TextField now contains a TextNode which uses a TextNodeRenderer.

Returns the renderer subcomponent used to render the value to the Document.



Copyright © 2007 Martin T Phelan. All Rights Reserved.