net.sf.click.extras.cayenne
Class PropertySelect

java.lang.Object
  extended bynet.sf.click.control.AbstractControl
      extended bynet.sf.click.control.Field
          extended bynet.sf.click.control.Select
              extended bynet.sf.click.extras.cayenne.PropertySelect
All Implemented Interfaces:
Control, Serializable

public class PropertySelect
extends Select

Provides a DataObject property Select control:   <select></select>.

Property Select
The PropertySelect provides a Select control for DataObject relationship properties (properties which are also DataObjects). For properties which are not DataObjects use the QuerySelect control.

The PropertySelect control will only work inside a CayenneForm as it obtains meta data about DataObject property from the parent form.

Currently this control only supports selecting a single element.

PropertySelect Example

For example given a Pet DataObject which has a PetType DataObject property.
 public class Pet implements DataObject {
     public PetType getType() {
         ..
     }

     public void setType(PetType value) {
         ..
     }
 }

 public class PetType implements DataObject {
     public String getName() {
         ..
     }
 } 
You would use the PropertySelect in a CayenneForm to edit the Pet type property. In this example the PetType name property is rendered as the select options label.
 CayenneForm form = new CayenneForm("form", Pet.class);

 PropertySelect typeSelect = new PropertySelect("type", true);
 typeSelect.setOptionLabel("name");
 form.add(typeSelect); 
In this example no query is specified and the control will create a simple SelectQuery based on the property class. However, generally you should use a named query (configured in the Cayenne Modeler) or an explicity set SelectQuery.

Note when using a named query ensure that it will return DataObjects and not DataRows.

Also note that the CayenneForm is not able to determine whether a property is required, so you must set the PropertySelect required status manually.

Author:
Malcolm Edgar
See Also:
CayenneForm, QuerySelect, Serialized Form

Field Summary
protected  Decorator decorator
          The option label rendering decorator.
protected  org.apache.cayenne.query.NamedQuery namedQuery
          The option list Cayenne NamedQuery.
protected  boolean optional
          The flag indicating whether the option list includes an empty option value.
protected  String optionLabel
          The data object property to render as the option label.
protected  org.apache.cayenne.query.Ordering ordering
          The select query ordering.
protected  boolean orderingApplied
          The flag indicating whether the ordering has been applied.
protected  String queryName
          The name of the configured select query.
protected  org.apache.cayenne.query.SelectQuery selectQuery
          The option list Cayenne SelectQuery.
protected  org.apache.cayenne.DataObject valueObject
          The property value object.
 
Fields inherited from class net.sf.click.control.Select
multiple, optionList, selectedValues, size, VALIDATE_SELECT_FUNCTION
 
Fields inherited from class net.sf.click.control.Field
disabled, error, focus, form, help, label, readonly, required, tabindex, title, validate, value
 
Fields inherited from class net.sf.click.control.AbstractControl
actionListener, attributes, listener, listenerMethod, messages, name, parent, styles
 
Fields inherited from interface net.sf.click.Control
CONTROL_MESSAGES
 
Constructor Summary
PropertySelect()
          Create a PropertySelect field with no name defined, please note the control's name must be defined before it is valid.
PropertySelect(String name)
          Create a PropertySelect field with the given name.
PropertySelect(String name, boolean required)
          Create a PropertySelect field with the given name and required status.
PropertySelect(String name, String label)
          Create a PropertySelect field with the given name and label.
PropertySelect(String name, String label, boolean required)
          Create a PropertySelect field with the given name, label and required status.
 
Method Summary
 void bindRequestValue()
          Bind the request value to the control, looking up the DataObject based on the submitted primary key value and setting this object as the Select valueObject.
 Decorator getDecorator()
          Return the option label rendering decorator.
 org.apache.cayenne.query.NamedQuery getNamedQuery()
          Return the NamedQuery to populate the options list with.
 String getOptionLabel()
          Return the DataObject property to render as the option label.
 org.apache.cayenne.query.Ordering getOrdering()
          Return the select query ordering.
 String getQueryName()
          Return the name of the configured query to populate the options list with.
 org.apache.cayenne.query.SelectQuery getSelectQuery()
          Return the SelectQuery to populate the options list with.
 Object getValueObject()
          Return the property DataObject value, or null if value was not defined.
 boolean isMultiple()
          Return true if multiple options can be selected.
 boolean isOptional()
          Return true if the option list includes an empty option value.
protected  void loadOptionList()
          Load the Select options list.
 void onDestroy()
          Clear the cached valueObject.
 void render(HtmlStringBuffer buffer)
          Render the HTML representation of the PropertySelect.
 void setDecorator(Decorator decorator)
          Set the decorator to render the option labels.
 void setMultiple(boolean value)
          Set the multiple options can be selected flag.
 void setNamedQuery(org.apache.cayenne.query.NamedQuery namedQuery)
          Set the NamedQuery to populate the options list with.
 void setOptional(boolean value)
          Set whether the option list includes an empty option value.
 void setOptionLabel(String optionLabel)
          Set the DataObject property to render as the option label.
 void setOrdering(org.apache.cayenne.query.Ordering ordering)
          Set the select query ordering.
 void setQueryName(String queryName)
          Set the name of the configured query to populate the options list with.
 void setSelectQuery(org.apache.cayenne.query.SelectQuery selectQuery)
          Set the SelectQuery to populate the options list with.
 void setValueObject(Object object)
          Set the valueObject with the given DataObject and the select value to the DataObject primary key value.
 
Methods inherited from class net.sf.click.control.Select
add, add, add, addAll, addAll, addAll, addAll, getControlSizeEst, getMultipleValues, getOptionList, getSelectedValues, getSize, getTag, getValidationJavaScript, setInitialValue, setMultipleValues, setOptionList, setSelectedValues, setSize, validate
 
Methods inherited from class net.sf.click.control.Field
getError, getErrorLabel, getFocus, getFocusJavaScript, getForm, getHelp, getId, getLabel, getRequestValue, getTabIndex, getTextAlign, getTitle, getValidate, getValue, getWidth, isDisabled, isHidden, isReadonly, isRequired, isValid, onInit, onProcess, setDisabled, setError, setErrorMessage, setErrorMessage, setErrorMessage, setErrorMessage, setFocus, setForm, setHelp, setLabel, setListener, setParent, setReadonly, setRequired, setTabIndex, setTextAlign, setTitle, setValidate, setValue, setWidth
 
Methods inherited from class net.sf.click.control.AbstractControl
addStyleClass, appendAttributes, getActionListener, getAttribute, getAttributes, getContext, getHtmlImports, getMessage, getMessage, getMessage, getMessages, getName, getPage, getParent, getStyle, getStyles, hasAttribute, hasAttributes, hasStyles, onDeploy, onRender, registerActionEvent, removeStyleClass, renderTagBegin, renderTagEnd, setActionListener, setAttribute, setId, setName, setStyle, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

decorator

protected Decorator decorator
The option label rendering decorator.


queryName

protected String queryName
The name of the configured select query.


namedQuery

protected org.apache.cayenne.query.NamedQuery namedQuery
The option list Cayenne NamedQuery.


optional

protected boolean optional
The flag indicating whether the option list includes an empty option value. By default the list does not include an empty option value.


ordering

protected org.apache.cayenne.query.Ordering ordering
The select query ordering. By default the property select will be ordered by the optionLabel property in ascending order.


orderingApplied

protected boolean orderingApplied
The flag indicating whether the ordering has been applied.


optionLabel

protected String optionLabel
The data object property to render as the option label.


selectQuery

protected org.apache.cayenne.query.SelectQuery selectQuery
The option list Cayenne SelectQuery.


valueObject

protected org.apache.cayenne.DataObject valueObject
The property value object.

Constructor Detail

PropertySelect

public PropertySelect(String name)
Create a PropertySelect field with the given name.

Parameters:
name - the name of the field

PropertySelect

public PropertySelect(String name,
                      String label)
Create a PropertySelect field with the given name and label.

Parameters:
name - the name of the field
label - the label of the field

PropertySelect

public PropertySelect(String name,
                      boolean required)
Create a PropertySelect field with the given name and required status.

Parameters:
name - the name of the field
required - the field required status

PropertySelect

public PropertySelect(String name,
                      String label,
                      boolean required)
Create a PropertySelect field with the given name, label and required status.

Parameters:
name - the name of the field
label - the label of the field
required - the field required status

PropertySelect

public PropertySelect()
Create a PropertySelect field with no name defined, please note the control's name must be defined before it is valid.

No-args constructors are provided for Java Bean tools support and are not intended for general use. If you create a control instance using a no-args constructor you must define its name before adding it to its parent.

Method Detail

getDecorator

public Decorator getDecorator()
Return the option label rendering decorator.

Returns:
the option label rendering decorator

setDecorator

public void setDecorator(Decorator decorator)
Set the decorator to render the option labels.

Parameters:
decorator - the decorator to render the select option labels

getQueryName

public String getQueryName()
Return the name of the configured query to populate the options list with.

Returns:
the name of the configured query to populate the options list with

setQueryName

public void setQueryName(String queryName)
Set the name of the configured query to populate the options list with.

Parameters:
queryName - the name of the configured query to populate the options list with

isMultiple

public boolean isMultiple()
Return true if multiple options can be selected.

Returns:
false
See Also:
Select.isMultiple()

setMultiple

public void setMultiple(boolean value)
Set the multiple options can be selected flag.

Parameters:
value - the multiple options can be selected flag
See Also:
Select.setMultiple(boolean)

getNamedQuery

public org.apache.cayenne.query.NamedQuery getNamedQuery()
Return the NamedQuery to populate the options list with.

Returns:
the NamedQuery to populate the options list with

setNamedQuery

public void setNamedQuery(org.apache.cayenne.query.NamedQuery namedQuery)
Set the NamedQuery to populate the options list with.

Parameters:
namedQuery - to populate the options list with

isOptional

public boolean isOptional()
Return true if the option list includes an empty option value.

Returns:
true if the option list includes an empty option value

setOptional

public void setOptional(boolean value)
Set whether the option list includes an empty option value.

Parameters:
value - set whether the option list includes an empty option value

getOptionLabel

public String getOptionLabel()
Return the DataObject property to render as the option label.

Returns:
optionLabel the DataObject property to render as the option label

setOptionLabel

public void setOptionLabel(String optionLabel)
Set the DataObject property to render as the option label.

Parameters:
optionLabel - the DataObject property to render as the option label

getSelectQuery

public org.apache.cayenne.query.SelectQuery getSelectQuery()
Return the SelectQuery to populate the options list with.

Returns:
the SelectQuery to populate the options list with

getOrdering

public org.apache.cayenne.query.Ordering getOrdering()
Return the select query ordering. By default the property select will be ordered by the label property in ascending order.

Note this ordering will not be applied by named queries, as named queries the ordering should be specified in the query definition.

Returns:
the select query ordering

setOrdering

public void setOrdering(org.apache.cayenne.query.Ordering ordering)
Set the select query ordering.

Note this ordering will not be applied by named queries, as named queries the ordering should be specified in the query definition.

Parameters:
ordering - the select query ordering

setSelectQuery

public void setSelectQuery(org.apache.cayenne.query.SelectQuery selectQuery)
Set the SelectQuery to populate the options list with.

Parameters:
selectQuery - the SelectQuery to populate the options list with

getValueObject

public Object getValueObject()
Return the property DataObject value, or null if value was not defined.

Returns:
the property DataObject value
See Also:
Field.getValueObject()

setValueObject

public void setValueObject(Object object)
Set the valueObject with the given DataObject and the select value to the DataObject primary key value.

Parameters:
object - the object value to set
See Also:
Field.setValueObject(Object)

bindRequestValue

public void bindRequestValue()
Bind the request value to the control, looking up the DataObject based on the submitted primary key value and setting this object as the Select valueObject.

See Also:
Select.bindRequestValue()

render

public void render(HtmlStringBuffer buffer)
Render the HTML representation of the PropertySelect.

If the Select option list is empty this method will load option list so that it can be rendered.

Parameters:
buffer - the specified buffer to render the control's output to
See Also:
AbstractControl.toString()

onDestroy

public void onDestroy()
Clear the cached valueObject.

See Also:
Control.onDestroy()

loadOptionList

protected void loadOptionList()
Load the Select options list. This method will attempt to select the options using the following techniques.
  1. if a SelectQuery is defined load options from SelectQuery
  2. if a query name is defined load options from configured named query
  3. else create a SelectQuery based on the property class