Using panels instead of String in Autocompletetextfield

a 夏天 提交于 2019-12-11 10:29:53

问题


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?


回答1:


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;
   }



回答2:


The AutoCompleteTextField uses the newAutoCompleteBehavior-hookmethod to create the behavior doing the display of the choices. This hookmethod takes an IAutoCompleteRenderer as an argument. This renderer's actually doing the displaying part. So you could either pass your own renderer to the AutoCompleteTextField (there's a constructor accepting one) or subclass the AutoCompleteTextField to override the factory method. Either way you'll have to come up with your own implementation of IAutoCompleteRenderer since there is no such implementation in wicket and the renderer itself will be heavily influenced by your current application design.




回答3:


I don't think it is possible to use panels, because a panel is a component, and itself could be anything. It will be too difficult to support any panel as a part of autocomplete list. It would be fun to have an autocomplete element as a form with autocomplete field;)

So, that's why there is IAutoCompleteRenderer interface to allow you generate any html markup for elements, but not as a panels.

As an option, maybe it is possible to have kind of modal pop up ajax dialog window using ModalWindow.



来源:https://stackoverflow.com/questions/15480544/using-panels-instead-of-string-in-autocompletetextfield

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!