org.chenillekit.tapestry.core.components.prototype_ui.AutoComplete

This AutoComplete component based on Prototype-UI's autocomplete widget.

[JavaDoc]

Component Parameters

Name Type Flags Default Default Prefix Description
label String Required, NOT Allow Null literal this parameter contains the name of the object property, that should display to user in the item list and the box of selected items.
selected java.util.List Required, NOT Allow Null prop The value to read or update.
translate org.apache.tapestry5.FieldTranslator Required, NOT Allow Null translate The object which will perform translation between server-side and client-side representations. If not specified, a value will usually be generated based on the type of the value parameter.

There are many possible parameters for the javascript widgets, that dont considered by default. If you need some/all of that please feel free to create your own component that extdends from AutoComplete like this:

extending ...

        
public class MyAutoComplete extends AutoComplete
{
  @Override
  protected void configure(JSONObject options)
  {
    options.put("delay", 0.2f);		// Delay before running ajax request
    options.put("highlight", true);	// Highlight search string in list
  }
}

      

Examples

This example describe how to use the AutoComplete component.

MyPage.tml

          
<html xmlns:t="http://tapestry.apache.org/schema/tapestry_5_0_0.xsd">
    <body>
    <t:form>
      <input t:id="autoComplete" type="text"/>
      <br/>
      <input type="submit"/>
    </t:form>
    </body>
</html>

        

MyPage.java

          
public class MyPage
{
  @Property
  @Inject
  private MusicLibrary musicLibrary;

  @Persist
  @Property
  private List<Track> selectedTracks;

	@Component(parameters = {"selected=selectedTracks", "translate=prop:translator", "label=title"})
	private AutoComplete autoComplete;

  /**
   * Tapestry render phase method.
   * Initialize temporary instance variables here.
   */
  void setupRender()
  {
    if (selectedTracks == null)
      selectedTracks = CollectionFactory.newList();
  }

  public List<Track> onProvidecompletionsFromAutoComplete(String partialValue)
  {
    return musicLibrary.findByMatchingTitle(partialValue);
  }

  public FieldTranslator getTranslator()
  {
    return new FieldTranslator<Track>()
    {
      public String toClient(Track value)
      {
        String clientValue = "0";
        if (value != null)
          clientValue = String.valueOf(value.getId());

        return clientValue;
      }

      public void render(MarkupWriter writer) { }

      public Class<Track> getType() { return Track.class; }

      public Track parse(String clientValue) throws ValidationException
      {
        Track serverValue = null;

        if (clientValue != null && clientValue.length() > 0 && !clientValue.equals("0"))
          serverValue = musicLibrary.getById(new Long(clientValue));

        return serverValue;
      }
    };
  }
}

        

Back to index