Search code examples
javaautocompletewicketpanels

Using panels instead of String in Autocompletetextfield


I am using Wicket to build an ui for a searchengine on a website. As the user is typing the results are shown in a dropdown. As I have a lot of different objects (with each a different display structure) I want to define several panels. So for each found item in the db, it gets the right panel and right structure. So for example : if the searchengine finds a user, it should show only name. When a picture is found, a thumbnail and a description, etc...

Right now I am using the AutocompleteTextField but it only takes strings. I thought about adding html in the string and show it like that. But as that is not really a clean solution, I am thinking of using panels.

So, anyone know how I can use panels instead of the strings in a AutoCompleteTextField?


Solution

  • Create your own Component. Use a ListView, put it into a WebMarkupContainer. Show the WebMarkupContainer based on the TextField input and refresh the ListView in the OnChangeAjaxBehavior attached to the TextField.

    This way you have full control over what you want to achieve.

    Example code for the ListView:

       private ListView getLv(){
          ListView lv = new ListView(PANEL, new PropertyModel(this, "someList")) {
             @Override
             protected void populateItem(ListItem item) {
                Integer type = item.getModelObject().getType();
                if (type == 1) {
                   item.add(new PanelType1("panel", item.getModelObject().someIdMaybe));
                } else if (type == 2) {
                   item.add(new PanelType2("panel", item.getModelObject().someIdMaybe));
                }
             }
          };
          return lv;
       }