You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Madasamy mcruncher <ma...@mcruncher.com> on 2012/12/01 03:09:00 UTC
Re: select2 integration -Duplicate(selected) value are appear in drop
down box
FooProvider implementation is
public class FooProvider extends TextChoiceProvider<Foo>
{
FooService fooService=new FooService();
@Override
protected String getDisplayText(Foo fooChoice) {
return fooChoice.getName();
}
@Override
protected Object getId(Foo fooChoice) {
return fooChoice.getName;
}
@Override
public void query(String term, int page, Response<Foo> response) {
response.addAll(queryMatches(term, page, 10));
response.setHasMore(response.size() == 10);
}
@Override
public Collection<Foo> toChoices(Collection<String> ids) {
ArrayList<Foo> foos = new ArrayList<Foo>();
for (String id : ids) {
foos.add(fooService.findFooByName(id));
}
return foos;
}
}
private List<Foo> queryMatches(String term, int page, int pageSize) {
List<Foo> result = new ArrayList<Foo>();
term = term.toUpperCase();
final int offset = page * pageSize;
int matched = 0;
for ( Foo foo : getAllFoos()) {
if (result.size() == pageSize) {
break;
}
if (foo.getName().toUpperCase().contains(term)) {
matched++;
if (matched > offset) {
result.add(foo);
}
}
}
return result;
}
public List<Foo> getAllFoos()
{
//return all foos
return fooService.findAll();
}
Re: select2 integration -Duplicate(selected) value are appear in drop down box
Posted by Thomas Götz <to...@decoded.de>.
I can't detect anything wrong with your implementation on first sight. Is it possible that you can reproduce the described behavior in a Quickstart?
-Tom
On 01.12.2012, at 03:09, Madasamy mcruncher <ma...@mcruncher.com> wrote:
> FooProvider implementation is
>
> public class FooProvider extends TextChoiceProvider<Foo>
> {
>
> FooService fooService=new FooService();
> @Override
> protected String getDisplayText(Foo fooChoice) {
> return fooChoice.getName();
> }
>
> @Override
> protected Object getId(Foo fooChoice) {
> return fooChoice.getName;
> }
>
> @Override
> public void query(String term, int page, Response<Foo> response) {
> response.addAll(queryMatches(term, page, 10));
> response.setHasMore(response.size() == 10);
>
> }
>
> @Override
> public Collection<Foo> toChoices(Collection<String> ids) {
> ArrayList<Foo> foos = new ArrayList<Foo>();
> for (String id : ids) {
> foos.add(fooService.findFooByName(id));
> }
> return foos;
> }
> }
>
> private List<Foo> queryMatches(String term, int page, int pageSize) {
>
> List<Foo> result = new ArrayList<Foo>();
> term = term.toUpperCase();
> final int offset = page * pageSize;
> int matched = 0;
> for ( Foo foo : getAllFoos()) {
> if (result.size() == pageSize) {
> break;
> }
>
> if (foo.getName().toUpperCase().contains(term)) {
> matched++;
> if (matched > offset) {
> result.add(foo);
> }
> }
> }
> return result;
> }
>
> public List<Foo> getAllFoos()
> {
> //return all foos
> return fooService.findAll();
> }
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org