net.sf.click.extras.cayenne
Class QuerySelect

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.QuerySelect
All Implemented Interfaces:
Control, Serializable

public class QuerySelect
extends Select

Provides a Cayenne Query Select control:   <select></select>.

Query Select
The QuerySelect provides a Select control with the options automatically populated from a Cayenne query. This control supports both named queries, which are configured in the Cayenne Modeler, and SelectQuery and NamedQuery objects which can be defined in code.

All Cayenne queries are executed using the thread local DataContext obtained via DataContext.getThreadDataContext(), and are executed as required by the onProcess() and toString() methods.

QuerySelect has no dependency on CayenneForm and can be used separately in other forms or controls.

QuerySelect Examples

The QuerySelect below executes a Cayenne Modeler defined named query called "system.titles". This pre configured query returns a list of DataRow objects containing "VALUE" and "LABEL" values, which are rendered as the option values and labels.
 QuerySelect title = new QuerySelect("title");
 title.setQueryValueLabel("system.titles", "VALUE", "LABEL");
 form.add(title); 
The example below uses a SelectQuery defined in code and renders the Delivery object type and description properties and the option values and labels.
 QuerySelect delivery = new QuerySelect("delivery", true);
 delivery.setSelectQuery(new SelectQuery(Delivery.class));
 delivery.setOptionValue("type");
 delivery.setOptionLabel("description");
 form.add(delivery); 
The last example uses a Decorator to render the select options label.
 QuerySelect userSelect = new QuerySelect("user", true);
 userSelect.setSelectQuery(new SelectQuery(User.class));
 userSelect.setOptionValue("username");
 userSelect.setDecorator(new Decorator() {
     public String render(Object object, Context context) {
         User user = (User) object;
         return user.getFirstName() + " " + user.getLastName();
     }
 });
 form.add(userSelect); 

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

Field Summary
protected  Decorator decorator
          The option label rendering decorator.
protected  boolean expireCache
          The flag specifying whether the cache should be ignored.
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 query result property to render as the option label.
protected  String optionValue
          The query result property to render as the option value.
protected  String queryName
          The name of the configured select query.
protected  org.apache.cayenne.query.SelectQuery selectQuery
          The option list Cayenne SelectQuery.
 
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
QuerySelect()
          Create a QuerySelect field with no name defined, please note the control's name must be defined before it is valid.
QuerySelect(String name)
          Create a QuerySelect field with the given name.
QuerySelect(String name, boolean required)
          Create a QuerySelect field with the given name and required status.
QuerySelect(String name, String label)
          Create a QuerySelect field with the given name and label.
QuerySelect(String name, String label, boolean required)
          Create a QuerySelect field with the given name, label and required status.
 
Method Summary
 void bindRequestValue()
          Bind the request value to the control.
 Decorator getDecorator()
          Return the option label rendering decorator.
 boolean getExpireCache()
          Return true if the query should expire the cache.
 org.apache.cayenne.query.NamedQuery getNamedQuery()
          Return the NamedQuery to populate the options list with.
 String getOptionLabel()
          Return the query result property to render as the option label.
 String getOptionValue()
          Return the query result property to render as the option value.
 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.
 boolean isOptional()
          Return true if the option list includes an empty option value.
protected  void loadOptionList()
          Load the Select options list.
 void render(HtmlStringBuffer buffer)
          Render the HTML representation of the QuerySelect.
 void setDecorator(Decorator decorator)
          Set the decorator to render the option labels.
 void setExpireCache(boolean expireCache)
          Set the query should expire cache parameter.
 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 query result property to render as the option label.
 void setOptionValue(String optionValue)
          Set the query result property to render as the option value.
 void setQueryName(String queryName)
          Set the name of the configured query to populate the options list with.
 void setQueryValueLabel(String queryName, String optionValue, String optionLabel)
          Set the configured queryName to execute, the property to render as the option value, and the property to render as the option label.
 void setSelectQuery(org.apache.cayenne.query.SelectQuery selectQuery)
          Set the SelectQuery to populate the options list with.
 
Methods inherited from class net.sf.click.control.Select
add, add, add, addAll, addAll, addAll, addAll, getControlSizeEst, getMultipleValues, getOptionList, getSelectedValues, getSize, getTag, getValidationJavaScript, isMultiple, setInitialValue, setMultiple, 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, getValueObject, 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, setValueObject, 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, onDestroy, 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.


expireCache

protected boolean expireCache
The flag specifying whether the cache should be ignored.


namedQuery

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


queryName

protected String queryName
The name of the configured select query.


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.


optionLabel

protected String optionLabel
The query result property to render as the option label.


optionValue

protected String optionValue
The query result property to render as the option value.


selectQuery

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

Constructor Detail

QuerySelect

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

Parameters:
name - the name of the field

QuerySelect

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

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

QuerySelect

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

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

QuerySelect

public QuerySelect(String name,
                   String label,
                   boolean required)
Create a QuerySelect 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

QuerySelect

public QuerySelect()
Create a QuerySelect 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

getExpireCache

public boolean getExpireCache()
Return true if the query should expire the cache.

Returns:
true if the query should expire the cache

setExpireCache

public void setExpireCache(boolean expireCache)
Set the query should expire cache parameter.

Parameters:
expireCache - the query should expire cache parameter

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

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

setQueryValueLabel

public void setQueryValueLabel(String queryName,
                               String optionValue,
                               String optionLabel)
Set the configured queryName to execute, the property to render as the option value, and the property to render as the option label.

Parameters:
queryName - the configured named query to execute
optionValue - the property to render as the option value
optionLabel - the property to render as the option label

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 query result property to render as the option label.

If the query returns DataRow this property will be accessed via dataRow.get(getOptionLabel()). If the query returns DataObject the property will be accessed using its getter method.

Returns:
the query result property to render as the option label.

setOptionLabel

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

Parameters:
optionLabel - the query result property to render as the option label

getOptionValue

public String getOptionValue()
Return the query result property to render as the option value.

If the query returns DataRow this property will be accessed via dataRow.get(getOptionValue()). If the query returns DataObject the property will be accessed using its getter method.

Returns:
the query result property to render as the option label.

setOptionValue

public void setOptionValue(String optionValue)
Set the query result property to render as the option value.

Parameters:
optionValue - the query result property to render as the option value

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

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

bindRequestValue

public void bindRequestValue()
Bind the request value to the control.

See Also:
Select.bindRequestValue()

render

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

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()

loadOptionList

protected void loadOptionList()
Load the Select options list.