org.apache.tapestry.dojo.form
Class DefaultAutocompleteModel

java.lang.Object
  extended by org.apache.tapestry.dojo.form.DefaultAutocompleteModel
All Implemented Interfaces:
IPrimaryKeyConverter, IAutocompleteModel

public class DefaultAutocompleteModel
extends Object
implements IAutocompleteModel

Default simple implementation of IAutocompleteModel. This class relies on the java beans specification to resolve key fields of an incoming List.

If you had an object type of User, with the primary/unique id of each User object stored as a member with a name of id you would pass something like this into the model(don't forget that javabeans syntax requires a corresponding getId() for members):

  IAutocompleteModel model = new DefaultAutocompleteModel(List users, "id", "name");
 

Author:
jkuhnert
See Also:
"http://jakarta.apache.org/commons/beanutils/commons-beanutils-1.6.1/docs/api/org/apache/commons/beanutils/PropertyUtils.html"

Constructor Summary
DefaultAutocompleteModel(List values, String keyField, String labelField)
          Create a new model using java beans syntax to access the key/label for the list using the specified bean expressions.
 
Method Summary
 String getLabelFor(Object value)
          For the given value, provide a user friendly label that will be presented in a drop down selection list in the browser ui.
 Object getPrimaryKey(Object value)
          Returns the primary key of the given value.
 Object getValue(Object primaryKey)
          Returns the value corresponding the given primary key.
 List getValues(String match)
          Expected to return a list of all possible values, filtering out values that match the specified String in the label representation of the value.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DefaultAutocompleteModel

public DefaultAutocompleteModel(List values,
                                String keyField,
                                String labelField)
Create a new model using java beans syntax to access the key/label for the list using the specified bean expressions.

Parameters:
values - The list of values to manage.
keyField - The java beans expression for getting the primary key of each object in the list. getPrimaryKey(Object).
labelField - The java beans expression for getting the label of each object in the list. getLabelFor(Object).
Method Detail

getValues

public List getValues(String match)
Expected to return a list of all possible values, filtering out values that match the specified String in the label representation of the value.

Specified by:
getValues in interface IAutocompleteModel
Parameters:
match - The string to use to filter the values based on the label representation of objects.
Returns:
A filtered list of values. Expected to be in the full object form such that IPrimaryKeyConverter.getPrimaryKey(Object) can be called on each returned value.

getLabelFor

public String getLabelFor(Object value)
For the given value, provide a user friendly label that will be presented in a drop down selection list in the browser ui.

Specified by:
getLabelFor in interface IAutocompleteModel
Parameters:
value - The object to retrieve a label for.
Returns:
The label to use for the given value.

getPrimaryKey

public Object getPrimaryKey(Object value)
Returns the primary key of the given value.

Specified by:
getPrimaryKey in interface IPrimaryKeyConverter
Returns:
the primary key of the value

getValue

public Object getValue(Object primaryKey)
Returns the value corresponding the given primary key.

Specified by:
getValue in interface IPrimaryKeyConverter
Returns:
the generated value corresponding to the given primary key


Copyright © 2006-2008 Apache Software Foundation. All Rights Reserved.