org.apache.click.extras.cayenne
Class PropertySelect

java.lang.Object
  extended by org.apache.click.control.AbstractControl
      extended by org.apache.click.control.Field
          extended by org.apache.click.control.Select
              extended by org.apache.click.extras.cayenne.PropertySelect
All Implemented Interfaces:
Serializable, Control, Stateful

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 explicitly 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.

OptionList Caching in Stateful Pages

Note the PropertySelect will cache its optionList in a stateful page. If you need the optionList refreshed in each page view you will need to clear the option list. For example:
 public void onDestroy() {
     customerSelect.getOptionList().clear();
     super.onDestroy();
 } 

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 org.apache.click.control.Select
dataProvider, defaultOption, multiple, optionList, selectedValues, size, VALIDATE_SELECT_FUNCTION
 
Fields inherited from class org.apache.click.control.Field
disabled, error, focus, form, help, label, labelStyle, labelStyleClass, parentStyleClassHint, parentStyleHint, readonly, required, tabindex, title, trim, validate, value
 
Fields inherited from class org.apache.click.control.AbstractControl
actionListener, attributes, behaviors, headElements, listener, listenerMethod, messages, name, parent, styles
 
Fields inherited from interface org.apache.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
 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 loadDataObject()
          Load the DataObject based on the submitted primary key value and setting this object as the Select valueObject.
protected  void loadOptionList()
          Load the Select options list.
 void onDestroy()
          Clear the cached valueObject.
 boolean onProcess()
          Process the page request returning true to continue processing or false otherwise.
 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.
 void validate()
          Validate the QuerySelect request submission.
 
Methods inherited from class org.apache.click.control.Select
add, add, add, add, addAll, addAll, addAll, addAll, bindRequestValue, getControlSizeEst, getDataProvider, getDefaultOption, getDefaultOptionValue, getMultipleValues, getOptionList, getSelectedValues, getSize, getState, getTag, getValidationJavaScript, onRender, setDataProvider, setDefaultOption, setInitialValue, setMultipleValues, setOptionList, setSelectedValues, setSize, setState
 
Methods inherited from class org.apache.click.control.Field
getError, getErrorLabel, getFocus, getFocusJavaScript, getForm, getHelp, getId, getLabel, getLabelStyle, getLabelStyleClass, getParentStyleClassHint, getParentStyleHint, getRequestValue, getTabIndex, getTextAlign, getTitle, getValidate, getValue, getWidth, isDisabled, isHidden, isReadonly, isRequired, isTrim, isValid, removeState, renderTagBegin, restoreState, saveState, setDisabled, setError, setErrorMessage, setErrorMessage, setFocus, setForm, setHelp, setLabel, setLabelStyle, setLabelStyleClass, setListener, setParent, setParentStyleClassHint, setParentStyleHint, setReadonly, setRequired, setTabIndex, setTextAlign, setTitle, setTrim, setValidate, setValue, setWidth
 
Methods inherited from class org.apache.click.control.AbstractControl
addBehavior, addStyleClass, appendAttributes, dispatchActionEvent, getActionListener, getAttribute, getAttributes, getBehaviors, getContext, getHeadElements, getHtmlImports, getMessage, getMessage, getMessages, getName, getPage, getParent, getStyle, getStyles, hasAttribute, hasAttributes, hasBehaviors, hasStyles, isAjaxTarget, onDeploy, onInit, removeBehavior, removeStyleClass, 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.

Overrides:
isMultiple in class Select
Returns:
false
See Also:
Select.isMultiple()

setMultiple

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

Overrides:
setMultiple in class Select
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.

Overrides:
getValueObject in class Field
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.

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

onProcess

public boolean onProcess()
Process the page request returning true to continue processing or false otherwise.

This method delegates to loadDataObject() to load the DataObject.

Specified by:
onProcess in interface Control
Overrides:
onProcess in class Field
Returns:
true to continue Page event processing or false otherwise
See Also:
Field.onProcess()

onDestroy

public void onDestroy()
Clear the cached valueObject.

Specified by:
onDestroy in interface Control
Overrides:
onDestroy in class AbstractControl
See Also:
Control.onDestroy()

validate

public void validate()
Validate the QuerySelect request submission.

Overrides:
validate in class Select
See Also:
Select.validate()

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.

Specified by:
render in interface Control
Overrides:
render in class Select
Parameters:
buffer - the specified buffer to render the control's output to
See Also:
AbstractControl.toString()

loadDataObject

protected void loadDataObject()
Load the DataObject based on the submitted primary key value and setting this object as the Select valueObject.


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