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
 Map filterValues(String match)
          Used to filter a potentially large list of objects.
 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.
 
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

filterValues

public Map filterValues(String match)
Used to filter a potentially large list of objects.

Specified by:
filterValues in interface IAutocompleteModel
Parameters:
match - The given partial string that should be matched against object labels in the model being managed.
Returns:
A Map containing key/value pairs matching the given input label string. The map should contain a key compatible with IPrimaryKeyConverter.getPrimaryKey(Object) and value compatible with IAutocompleteModel.getLabelFor(Object).

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 Apache Software Foundation. All Rights Reserved.