Wicket
  1. Wicket
  2. WICKET-1736

Allow Access to AutoCompleteTextField AutoCompleteBehavior

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 1.3.4, 1.4-M2
    • Fix Version/s: 1.3.5, 1.4-RC1
    • Component/s: wicket
    • Labels:
      None
    • Environment:
      N/A

      Description

      Currently there is no easy way to access the AutoCompleteBehavior of the AutoCompleteTextField. This is useful when dynamically enabling/disabling the behavior (among other reasons).

      The current code is:

      	public AutoCompleteTextField(String id, IModel model, Class type,
      		IAutoCompleteRenderer renderer, AutoCompleteSettings settings)
      	{
      		super(id, model, type);
      		// this disables Firefox autocomplete
      		add(new SimpleAttributeModifier("autocomplete", "off"));
      
      		add(new AutoCompleteBehavior(renderer, settings)
      		{
      
      			private static final long serialVersionUID = 1L;
      
      			protected Iterator getChoices(String input)
      			{
      				return AutoCompleteTextField.this.getChoices(input);
      			}
      
      		});
      	}
      

      One solution to this is to extract the creation of the AutoCompleteBehavior to a method:

      	public AutoCompleteTextField(final String id, final IModel model, final Class<?> type, final IAutoCompleteRenderer renderer, final AutoCompleteSettings settings) {
      		super(id, model, type);
      		// this disables Firefox autocomplete
      		add(new SimpleAttributeModifier("autocomplete", "off"));
      
      		final AutoCompleteBehavior autoCompleteBehavior = createAutoCompleteBehavior(renderer, settings);
      		if (autoCompleteBehavior == null) {
      			throw new NullPointerException("Auto complete behavior cannot be null");
      		}
      		add(autoCompleteBehavior);
      	}
      
      	protected AutoCompleteChoiceBehavior createAutoCompleteBehavior(final IAutoCompleteRenderer renderer, final AutoCompleteSettings settings) {
      		return new AutoCompleteChoiceBehavior(renderer, settings);
      	}
      
      	public class AutoCompleteChoiceBehavior extends AutoCompleteBehavior {
      		public AutoCompleteChoiceBehavior(final IAutoCompleteRenderer renderer, final AutoCompleteSettings settings) {
      			super(renderer, settings);
      		}
      		protected final Iterator<?> getChoices(final String input) {
      			return AbstractAutoCompleteTextField.this.getChoices(input);
      		}
      	}
      

        Activity

        There are no comments yet on this issue.

          People

          • Assignee:
            Igor Vaynberg
            Reporter:
            Will Hoover
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development