Wicket 7-自动完成的文本字段-具有onSelect方法

时间:2018-10-01 12:08:39

标签: wicket

我们想实现AutoCompleteTextField字段,一旦用户从AutoComplete结果中选择了该字段,则系统将在其他文本字段上自动填充,我使用了AjaxFormComponentUpdatingBehavior组件(模糊),但这将对每个文本输入生效从AutoCompleteTextField字段中获取,但是如果我更改为AjaxFormComponentUpdatingBehavior(更改),则无法使用。

下面是示例代码:

    AutoCompleteTextField<String> field_postcode = new AutoCompleteTextField<String>("field_postcode",
            new PropertyModel<String>(getModelObject(), "wAdditionalInfo.postal"), autoCompleteRenderer) {
        private static final long serialVersionUID = 1L;

        @Override
        protected Iterator<String> getChoices(String input) {
            if (Strings.isEmpty(input)) {
                List<String> emptyList = Collections.emptyList();
                return emptyList.iterator();
            }

            List<String> choices = new ArrayList<String>();

            List<Postcode> postcodeList = getProfileManager().findAllPostcodeByPostcode(input);

            for (Postcode p : postcodeList) {
                String postcode = p.getPostcode();

                if (postcode.startsWith(input)) {
                    choices.add(p.getPostcode());
                    if (choices.size() == 10) {
                        break;
                    }
                }
            }
            return choices.iterator();
        }

    };
    field_postcode.setRequired(true);


    field_postcode.add(new AjaxFormComponentUpdatingBehavior("blur"){
          private static final long serialVersionUID=-1107858522700306810L;


          @Override protected void onUpdate( AjaxRequestTarget target){

              Postcode postcode = getProfileManager().findPostcodeByPostcode(field_postcode.getInput());
                if (postcode != null) {
                    City city = postcode.getCity();
                    State state = city.getState();
                    field_city.setModelObject(city.getCity());
                    ddl_state.setModelObject(state);
                    if (isDisplayTip) {

                    //isDisplayTip true mean is from widrawal webform

                        isReadonly = true;
                    } else {
                        field_city.setEnabled(false);
                    }
                    ddl_state.setEnabled(false);

                } else {
                    if (isDisplayTip) {
                        isReadonly = false;
                    } else {
                        field_city.setEnabled(true);
                    }
                    ddl_state.setEnabled(true);
                }
                target.add(field_city, ddl_state);

          }
        }
    );

检票口是否有任何api可以实现这一目标?当用户从“自动完成”中选择选项时,我们需要一些东西,然后仅使用AjaxFormComponentUpdatingBehavior的onUpdate方法