Allow Access to AutoCompleteTextField AutoCompleteBehavior
----------------------------------------------------------
Key: WICKET-1736
URL: https://issues.apache.org/jira/browse/WICKET-1736
Project: Wicket
Issue Type: Bug
Components: wicket
Affects Versions: 1.4-M2, 1.3.4
Environment: N/A
Reporter: Will Hoover
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:
{code}
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);
}
});
}
{code}
One solution to this is to extract the creation of the AutoCompleteBehavior to
a method:
{code}
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 =
getAutoCompleteBehavior(renderer, settings);
if (autoCompleteBehavior == null) {
throw new NullPointerException("Auto complete behavior
cannot be null");
}
add(autoCompleteBehavior);
}
protected AutoCompleteChoiceBehavior getAutoCompleteBehavior(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);
}
}
{code}
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.