Reputation: 525
I need an AutoCompleteTextField
for Wicket which can handle several autocomplete items separated by a comma.
Something like this: http://digitarald.de/project/autocompleter/1-1/showcase/delicious-tags/
Upvotes: 0
Views: 1977
Reputation: 525
I could resolve the problem by Ajax in wicket as the following
TextArea partnersDB = new TextArea("partnersDB");
String partnerKeeper;
public String getPartnerKeeper() {
return partnerKeeper;
}
public void setPartnerKeeper(String partnerKeeper) {
this.partnerKeeper = partnerKeeper;
}
public String getMessageTypeKeeper() {
return messageTypeKeeper;
}
public void setMessageTypeKeeper(String messageTypeKeeper) {
this.messageTypeKeeper = messageTypeKeeper;
}
private void makePartnersAutoCompleter() {
final List<String> allPartners = auditDAO.findAllPartnerIds();
IAutoCompleteRenderer partnerRenderer = new AbstractAutoCompleteRenderer() {
@Override
protected String getTextValue(Object obj) {
return getPartnerKeeper() + ((String) obj);
}
@Override
protected void renderChoice(Object obj, Response r, String str) {
r.write((String) obj);
}
};
AutoCompleteBehavior autoCompleteBehavior = new AutoCompleteBehavior(partnerRenderer) {
@Override
protected Iterator<String> getChoices(String input) {
int lastCommaIndex = input.lastIndexOf(';');
String realInput = "";
if (lastCommaIndex == -1) {
setPartnerKeeper("");
realInput = input;
} else {
setPartnerKeeper(input.substring(0, lastCommaIndex) + ";");
realInput = input.substring(lastCommaIndex + 1);
}
List<String> completions = new ArrayList<String>();
for (int i = 0; i < allPartners.size(); i++) {
String partner = allPartners.get(i);
if (partner.startsWith(realInput.toUpperCase()) || partner.startsWith(realInput.toLowerCase())) {
completions.add(partner + ";");
}
}
return completions.iterator();
}
};
partnersDB.add(autoCompleteBehavior);
}
Upvotes: 0
Reputation: 17533
Also see https://github.com/wicketstuff/core/tree/master/jdk-1.5-parent/autocomplete-tagit-parent
Upvotes: 1
Reputation: 27880
Wicket-extensions provides autocomplete features.
Add an AutoCompleteBehavior
to the TextArea
in the same fashion AutoCompleteTextField
uses it.
For instance:
TextArea t = new TextArea("area", new Model());
AutoCompleteBehavior<String> b = new AutoCompleteBehavior<String>(
StringAutoCompleteRenderer.INSTANCE){
@Override
protected Iterator<String> getChoices(String input) {
return getMyListElements().iterator();
}
};
t.setOutputMarkupId(true);
t.add(b);
add(t);
If you are using Maven, just add the following dependency to start using wicket-extensions:
<dependency>
<groupId>org.apache.wicket</groupId>
<artifactId>wicket-extensions</artifactId>
<version>${wicket.version}</version>
</dependency>
EDIT Seeing that the question is about Multi autocomplete textfields, like the one in this example, you might find the following link useful: Wicket auto-complete text fields. There are a couple of components in there that seem to do just what you need.
You might also find this discussion and this one in the Apache Wicket User list useful. You'll find a couple of links there to projects that seem to also have this component: interwicket and WicketHub
Upvotes: 5