Example usage for org.apache.wicket.extensions.ajax.markup.html.autocomplete AutoCompleteTextField AutoCompleteTextField

List of usage examples for org.apache.wicket.extensions.ajax.markup.html.autocomplete AutoCompleteTextField AutoCompleteTextField

Introduction

In this page you can find the example usage for org.apache.wicket.extensions.ajax.markup.html.autocomplete AutoCompleteTextField AutoCompleteTextField.

Prototype

public AutoCompleteTextField(final String id, final IAutoCompleteRenderer<T> renderer) 

Source Link

Document

Constructor using the given renderer.

Usage

From source file:by.parfen.disptaxi.webapp.etc.AutoComplitePage.java

License:Apache License

/**
 * Constructor.//from w  w  w. ja  v a 2 s.  co  m
 */
public AutoComplitePage() {
    Injector.get().inject(this);

    sampleEvent = new SampleEvent();
    // selectedCity = cityService.get(15L);
    sampleEvent.setCityById(60L);
    streetsList = sampleEvent.getStreets();
    // pointsList = sampleEvent.getPointsList();

    final FeedbackPanel feedback = new FeedbackPanel("feedback");
    feedback.setOutputMarkupId(true);
    add(feedback);

    Form<Void> form = new Form<Void>("form");
    add(form);

    final AutoCompleteTextField<String> field = new AutoCompleteTextField<String>("acStreet",
            new Model<String>("")) {
        @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>(MAX_AUTO_COMPLETE_ELEMENTS);

            for (final Street streetItem : streetsList) {
                final String streetName = streetItem.getName();

                if (streetName.toUpperCase().startsWith(input.toUpperCase())) {
                    choices.add(streetName);
                    if (choices.size() == MAX_AUTO_COMPLETE_ELEMENTS) {
                        break;
                    }
                }
            }

            return choices.iterator();
        }
    };

    final AutoCompleteTextField<String> fieldPoint = new AutoCompleteTextField<String>("acPoint",
            new Model<String>("")) {
        @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>(MAX_AUTO_COMPLETE_ELEMENTS);

            for (final Point pointItem : sampleEvent.getPointsList()) {
                final String pointName = pointItem.getName();

                if (pointName.toUpperCase().startsWith(input.toUpperCase())) {
                    choices.add(pointName);
                    if (choices.size() == MAX_AUTO_COMPLETE_ELEMENTS) {
                        break;
                    }
                }
            }

            return choices.iterator();
        }
    };

    final ItemPanel itemPanel = new ItemPanel("itemPanel");
    add(itemPanel);

    add(new Link<Void>("linkItemInfo") {

        @Override
        public void onClick() {
            info("onSubmit");
            info(itemPanel.getItemInfo());
        }

    });

    final Label label = new Label("label", form.getDefaultModel()) {

        @Override
        public void onEvent(IEvent<?> event) {
            Object payload = event.getPayload();
            if (payload instanceof SampleEvent) {
                SampleEvent sampelEvent = (SampleEvent) payload;
                setDefaultModel(Model
                        .of(sampelEvent.getSelectedStreetName() + ", " + sampelEvent.getSelectedPointName()));
                sampelEvent.getTarget().add(this);
            }
        }

    };

    label.setOutputMarkupId(true);
    add(label);

    form.add(field);
    form.add(fieldPoint);

    field.add(new AjaxFormSubmitBehavior(form, "onchange") {
        @Override
        protected void onSubmit(AjaxRequestTarget target) {
            sampleEvent.setTarget(target);
            sampleEvent.setSelectedStreetName(field.getDefaultModelObjectAsString());
            sampleEvent.setSelectedPointName("");
            send(getPage(), Broadcast.BREADTH, sampleEvent);
        }

        @Override
        protected void onError(AjaxRequestTarget target) {
        }
    });

    fieldPoint.add(new AjaxFormSubmitBehavior(form, "onchange") {
        @Override
        protected void onSubmit(AjaxRequestTarget target) {
            sampleEvent.setTarget(target);
            sampleEvent.setSelectedPointName(fieldPoint.getDefaultModelObjectAsString());
            send(getPage(), Broadcast.BREADTH, sampleEvent);
        }

        @Override
        protected void onError(AjaxRequestTarget target) {
        }
    });
}

From source file:by.parfen.disptaxi.webapp.etc.ChoicePage.java

License:Apache License

/**
 * Constructor./*from   ww  w  .  j a v a  2 s .  c  o  m*/
 */
public ChoicePage() {
    final City city = cityService.get(15L);
    List<Street> streetsList;
    streetsList = streetService.getAllByCity(city);
    for (Street streetItem : streetsList) {
        List<Point> pointsList = pointService.getAllByStreet(streetItem);
        List<String> pointNames = new ArrayList<String>();
        for (Point pointItem : pointsList) {
            pointNames.add(pointItem.getName());
        }
        pointsMap.put(streetItem.getName(), pointNames);
    }
    // pointsMap.put("", Arrays.asList("12", "22", "34"));
    // pointsMap.put("", Arrays.asList("2", "4", "45", "13", "78"));
    // pointsMap.put("", Arrays.asList("10", "12", "22", "4", "6"));

    IModel<List<? extends String>> makeChoices = new AbstractReadOnlyModel<List<? extends String>>() {
        @Override
        public List<String> getObject() {
            return new ArrayList<String>(pointsMap.keySet());
        }

    };

    IModel<List<? extends String>> modelChoices = new AbstractReadOnlyModel<List<? extends String>>() {
        @Override
        public List<String> getObject() {
            List<String> points = pointsMap.get(selectedStreetName);
            if (points == null) {
                points = Collections.emptyList();
            }
            return points;
        }

    };

    Form<Void> form = new Form<Void>("form");
    add(form);

    final DropDownChoice<String> streets = new DropDownChoice<String>("streets",
            new PropertyModel<String>(this, "selectedStreetName"), makeChoices);

    final DropDownChoice<String> points = new DropDownChoice<String>("points", new Model<String>(),
            modelChoices);
    points.setOutputMarkupId(true);

    form.add(streets);
    form.add(points);

    final FeedbackPanel feedback = new FeedbackPanel("feedback");
    feedback.setOutputMarkupId(true);
    add(feedback);

    form.add(new AjaxButton("go") {
        @Override
        protected void onAfterSubmit(AjaxRequestTarget target, Form<?> form) {
            super.onAfterSubmit(target, form);
            info(" : " + streets.getModelObject() + " "
                    + points.getModelObject());
            target.add(feedback);
        }
    });

    streets.add(new AjaxFormComponentUpdatingBehavior("change") {
        @Override
        protected void onUpdate(AjaxRequestTarget target) {
            target.add(points);
        }
    });

    Form<Void> ajaxForm = new Form<Void>("ajaxForm");
    add(ajaxForm);

    final AutoCompleteTextField<String> field = new AutoCompleteTextField<String>("ac", new Model<String>("")) {
        @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>(10);

            List<Street> streetsList = streetService.getAllByCity(city);

            for (final Street streetItem : streetsList) {
                final String streetName = streetItem.getName();

                if (streetName.toUpperCase().startsWith(input.toUpperCase())) {
                    choices.add(streetName);
                    if (choices.size() == 10) {
                        break;
                    }
                }
            }

            return choices.iterator();
        }
    };

    ajaxForm.add(field);

    final Label label = new Label("selectedValue", field.getDefaultModel());
    label.setOutputMarkupId(true);
    ajaxForm.add(label);

    field.add(new AjaxFormSubmitBehavior(ajaxForm, "onchange") {
        @Override
        protected void onSubmit(AjaxRequestTarget target) {
            target.add(label);
            List<Street> streetList = streetService.getAllByCityAndName(city,
                    label.getDefaultModelObjectAsString());
            if (streetList.size() == 1) {
                setSelectedStreet(streetList.get(0));
            }
        }

        @Override
        protected void onError(AjaxRequestTarget target) {
        }
    });
}

From source file:gr.abiss.calipso.wicket.CustomFieldsFormPanel.java

License:Open Source License

@SuppressWarnings("serial")
private void addComponents(final CompoundPropertyModel model, final Metadata metadata, final List<Field> fields,
        final Map<String, FileUploadField> fileUploadFields) {
    //final AbstractItem item = (AbstractItem) model.getObject();
    List<FieldGroup> fieldGroupsList = metadata.getFieldGroups();
    @SuppressWarnings("unchecked")
    ListView fieldGroups = new ListView("fieldGroups", fieldGroupsList) {

        @Override// ww w .j  av  a  2s . c  o  m
        protected void populateItem(ListItem listItem) {
            FieldGroup fieldGroup = (FieldGroup) listItem.getModelObject();
            listItem.add(new Label("fieldGroupLabel", fieldGroup.getName()));
            List<Field> groupFields = fieldGroup.getFields();
            List<Field> editableGroupFields = new LinkedList<Field>();

            if (CollectionUtils.isNotEmpty(groupFields)) {
                for (Field field : groupFields) {
                    // is editable?
                    if (fields.contains(field)) {
                        editableGroupFields.add(field);
                    }
                }
            }
            ListView listView = new ListView("fields", editableGroupFields) {

                @Override
                @SuppressWarnings("deprecation")
                protected void populateItem(ListItem listItem) {
                    boolean preloadExistingValue = true;
                    final Field field = (Field) listItem.getModelObject();
                    // preload custom attribute
                    if (field.getCustomAttribute() == null) {
                        field.setCustomAttribute(getCalipso().loadItemCustomAttribute(getCurrentSpace(),
                                field.getName().getText()));
                    }
                    // preload value?
                    if (preloadExistingValue) {
                        AbstractItem history = (AbstractItem) model.getObject();
                        history.setValue(field.getName(), item.getValue(field.getName()));
                    }
                    // return the value for the field (see abstract item getCustomValue method)
                    Object fieldLastCustomValue = null;

                    String i18nedFieldLabelResourceKey = item.getSpace()
                            .getPropertyTranslationResourceKey(field.getName().getText());

                    if (item != null && !editMode) {
                        if (field.getName().isFile()) {
                            Set<Attachment> tmpAttachments = item.getAttachments();
                            if (tmpAttachments != null && tmpAttachments.size() > 0) {
                                for (Attachment attachment : tmpAttachments) {
                                    if (field.getLabel()
                                            .equals(AttachmentUtils.getBaseName(attachment.getFileName()))) {
                                        fieldLastCustomValue = attachment.getFileName();
                                        break;
                                    }
                                }
                            }

                        } else {
                            fieldLastCustomValue = item.getValue(field.getName());
                        }

                    }

                    // Decide whether the field is mandatory

                    boolean valueRequired = false;
                    //logger.info("fieldLastCustomValue for field " + field.getLabel() +": "+fieldLastCustomValue);
                    if (field.getMask() == State.MASK_MANDATORY
                            || (field.getMask() == State.MASK_MANDATORY_IF_EMPTY
                                    && (fieldLastCustomValue == null
                                            || StringUtils.isBlank(fieldLastCustomValue.toString())))) {
                        valueRequired = true; // value required
                    }

                    // go over custom fields
                    WebMarkupContainer labelContainer = new WebMarkupContainer("labelContainer");
                    listItem.add(labelContainer);

                    SimpleFormComponentLabel label = null;
                    if (field.getName().isDropDownType()) {
                        String autoValue;
                        final Map<String, String> options = field.getOptions();
                        if (field.getFieldType().equals(Field.FIELD_TYPE_DROPDOWN_HIERARCHICAL)) {
                            Fragment f = new Fragment("field", "treeField", CustomFieldsFormPanel.this);
                            // add HTML description through velocity
                            addVelocityTemplatePanel(f, "htmlDescriptionContainer", "htmlDescription",
                                    field.getCustomAttribute().getHtmlDescription(), null, true);
                            ItemFieldCustomAttribute customAttribute = field.getCustomAttribute();
                            //                        if(customAttribute == null){
                            //                           customAttribute = getCalipso().loadCustomAttribute(getCurrentSpace(), field.getName().getText());
                            //                           field.setCustomAttribute(customAttribute);
                            //                        }

                            // preload existing value
                            if (field.getCustomAttribute() != null && customAttribute.getLookupValue() == null
                                    && item.getCustomValue(field) != null) {
                                logger.info("preloading custom attribute for field: " + field.getLabel());
                                customAttribute.setLookupValue(getCalipso().loadCustomAttributeLookupValue(
                                        NumberUtils.createLong(item.getCustomValue(field).toString())));
                                customAttribute.setAllowedLookupValues(
                                        getCalipso().findActiveLookupValuesByCustomAttribute(customAttribute));
                            } else {
                                logger.info(
                                        "SKIPPED preloading custom attribute for field: " + field.getLabel());
                                customAttribute.setAllowedLookupValues(
                                        getCalipso().findActiveLookupValuesByCustomAttribute(customAttribute));
                            }
                            TreeChoice choice = new TreeChoice("field",
                                    new PropertyModel<CustomAttributeLookupValue>(field,
                                            "customAttribute.lookupValue"),
                                    customAttribute.getAllowedLookupValues(), customAttribute);

                            // TODO: temp, make configurable in space field form for 1520
                            int attrId = customAttribute.getId().intValue();
                            choice.setVisibleMenuLinks(
                                    attrId == 3 || attrId == 4 || attrId == 16 || attrId == 17);
                            //choice.setType(Long.class);
                            choice.setRequired(valueRequired);
                            // i18n
                            choice.setLabel(new ResourceModel(i18nedFieldLabelResourceKey));
                            WebMarkupContainer border = new WebMarkupContainer("border");
                            f.add(border);
                            //border.add(new ErrorHighlighter(choice));
                            border.add(choice);
                            //choice.setModel(model.bind(field.getName().getText()));
                            //border.add(model.bind(choice, field.getName().getText()));
                            listItem.add(f.setRenderBodyOnly(true));
                            label = new SimpleFormComponentLabel("label", choice);
                        }
                        // get the type of component that will render the choices
                        else if (field.getFieldType().equals(Field.FIELD_TYPE_AUTOSUGGEST)) {

                            renderAutoSuggest(model, listItem, field, i18nedFieldLabelResourceKey,
                                    valueRequired, options);

                        } else {
                            // normal drop down
                            label = renderDropDown(model, listItem, field, i18nedFieldLabelResourceKey,
                                    valueRequired, options);

                        }

                    } else if (field.getName().equals(Field.Name.ASSIGNABLE_SPACES)) {
                        Fragment f = new Fragment("field", "dropDown", CustomFieldsFormPanel.this);

                        // add HTML description through velocity
                        addVelocityTemplatePanel(f, "htmlDescriptionContainer", "htmlDescription",
                                field.getCustomAttribute().getHtmlDescription(), null, true);

                        List assignableSpaces = loadAssignableSpaces(field);
                        final Map options = new LinkedHashMap();

                        // Replace value from space id to space description for
                        // reasons of appearance.
                        for (int i = 0; i < assignableSpaces.size(); i++) {
                            Space space = (Space) assignableSpaces.get(i);
                            if (!space.equals(getCurrentSpace())) {
                                options.put(space.getId(), localize(space.getNameTranslationResourceKey()));
                            } // if
                        } // for

                        final List keys = new ArrayList(options.keySet());

                        AssignableSpacesDropDownChoice choice = new AssignableSpacesDropDownChoice("field",
                                keys, new IChoiceRenderer() {
                                    @Override
                                    public Object getDisplayValue(Object o) {
                                        return o;
                                    };

                                    @Override
                                    public String getIdValue(Object o, int i) {
                                        return o.toString();
                                    };
                                });

                        choice.setNullValid(true);
                        // i18n
                        choice.setLabel(new ResourceModel(i18nedFieldLabelResourceKey));

                        choice.setRequired(valueRequired);
                        choice.add(new Behavior() {
                            @Override
                            public void renderHead(Component component, IHeaderResponse response) {
                                response.renderJavaScript(new JavaScripts().setAssignableSpacesId.asString(),
                                        "setAssignableSpacesId");
                            }
                        });
                        choice.add(new AjaxFormComponentUpdatingBehavior("onChange") {
                            @Override
                            protected void onUpdate(AjaxRequestTarget target) {
                                if (statusChoice != null
                                        && !statusChoice.getDefaultModelObjectAsString().equals("")
                                        && !statusChoice.getDefaultModelObjectAsString().equals("-1")) {
                                    // if
                                    // (statusChoice.getValue().equals(String.valueOf(State.MOVE_TO_OTHER_SPACE))){
                                    // assignedToChoice.setChoices(getAssignableSpaceUsers());
                                    // assignedToChoice.setNullValid(false);
                                    // assignedToChoice.setVisible(true);
                                    // }//if
                                } // if
                                target.appendJavaScript("assignableSpacesId=" + "'"
                                        + assignableSpacesDropDownChoice.getMarkupId() + "';");
                                // This can happen at the creation of a new item
                                // where makes no sense to be moved to other space
                                if (assignedToChoice != null) {
                                    target.addComponent(assignedToChoice);
                                }
                            }// onUpdate

                            @Override
                            protected void onError(AjaxRequestTarget arg0, RuntimeException arg1) {
                                // Do nothing.
                                // It happens only if the choice be set to NULL by
                                // the user.
                                // The exception occurs because the model binds to
                                // space id that is from (primitive) type
                                // long and its value can not be set to NULL.
                            }

                        });

                        choice.setOutputMarkupId(true);
                        assignableSpacesDropDownChoice = choice;

                        if (itemViewFormPanel != null) {
                            itemViewFormPanel.getItemViewForm()
                                    .setAssignableSpacesDropDownChoice(assignableSpacesDropDownChoice);
                        } // if

                        WebMarkupContainer border = new WebMarkupContainer("border");
                        f.add(border);
                        border.add(new ErrorHighlighter(choice));
                        // Set field name explicitly to avoid runtime error
                        //border.add(model.bind(choice, field.getName() + ".id"));
                        choice.setModel(model.bind(field.getName() + ".id"));
                        border.add(choice);
                        listItem.add(f.setRenderBodyOnly(true));
                        border.setVisible(!CustomFieldsFormPanel.this.editMode);
                        label = new SimpleFormComponentLabel("label", choice);
                    } else if (field.getName().getType() == 6) {
                        // date picker
                        Fragment fragment = new Fragment("field", "dateFragment", CustomFieldsFormPanel.this);
                        // add HTML description through velocity
                        addVelocityTemplatePanel(fragment, "htmlDescriptionContainer", "htmlDescription",
                                field.getCustomAttribute().getHtmlDescription(), null, true);

                        if (item.getId() == 0 && item.getValue(field.getName()) == null
                                && field.getDefaultValueExpression() != null
                                && field.getDefaultValueExpression().equalsIgnoreCase("now")) {
                            item.setValue(field.getName(), new Date());
                        }
                        DateField calendar = new DateField("field",
                                preloadExistingValue
                                        ? new PropertyModel(model.getObject(), field.getName().getText())
                                        : new PropertyModel(model, field.getName().getText())) {

                            @Override
                            protected String getDateFormat() {
                                // TODO Auto-generated method stub
                                return metadata.getDateFormats().get(Metadata.DATE_FORMAT_SHORT);
                            }

                        };
                        calendar.setRequired(valueRequired);
                        // i8n
                        calendar.setLabel(new ResourceModel(i18nedFieldLabelResourceKey));

                        fragment.add(calendar);
                        listItem.add(fragment.setRenderBodyOnly(true));
                        label = new SimpleFormComponentLabel("label", calendar);

                    }
                    // TODO: Creating new space item - users custom field
                    else if (field.getName().isOrganization()) { // is organization
                        // Get users list
                        Fragment f = new Fragment("field", "dropDownFragment", CustomFieldsFormPanel.this);
                        // add HTML description through velocity
                        addVelocityTemplatePanel(f, "htmlDescriptionContainer", "htmlDescription",
                                field.getCustomAttribute().getHtmlDescription(), null, true);

                        Organization organization = (Organization) item.getValue(field.getName());
                        // logger.debug("Item organization field has value: "+organization);
                        final List<Organization> allOrganizationsList = getCalipso().findAllOrganizations();
                        DropDownChoice organizationChoice = new DropDownChoice("field", allOrganizationsList,
                                new IChoiceRenderer() {
                                    // user's choice renderer
                                    // display value user's name
                                    @Override
                                    public Object getDisplayValue(Object object) {
                                        return ((Organization) object).getName();
                                    }

                                    @Override
                                    public String getIdValue(Object object, int index) {
                                        // id value user's id
                                        return index + "";
                                    }
                                });

                        organizationChoice.add(new ErrorHighlighter());

                        organizationChoice.setRequired(valueRequired);
                        // i18n
                        organizationChoice.setLabel(new ResourceModel(i18nedFieldLabelResourceKey));
                        //f.add(model.bind(organizationChoice, field.getName().getText()));
                        organizationChoice.setModel(model.bind(field.getName().getText()));
                        f.add(organizationChoice);
                        listItem.add(f.setRenderBodyOnly(true));
                        label = new SimpleFormComponentLabel("label", organizationChoice);
                    }

                    else if (field.getName().isFile()) {
                        // File
                        addFileInputField(model, fileUploadFields, listItem, field, i18nedFieldLabelResourceKey,
                                valueRequired);

                    }
                    // TODO: Creating new space item - organizations custom field
                    else if (field.getName().isUser()) { // is user

                        Fragment f = new Fragment("field", "dropDownFragment", CustomFieldsFormPanel.this);
                        // add HTML description through velocity
                        addVelocityTemplatePanel(f, "htmlDescriptionContainer", "htmlDescription",
                                field.getCustomAttribute().getHtmlDescription(), null, true);

                        // find organization id from field's options

                        String strOrgId = field.getOptions().get("organizationId");
                        Long orgId = Long.valueOf(strOrgId);
                        // load organization from database

                        Organization selectedOrg = getCalipso().loadOrganization(orgId);
                        // TODO: load all users from organization
                        // add new list of selected organizations
                        List<Organization> selectedOrganization = new ArrayList<Organization>();
                        // add selected organization
                        selectedOrganization.add(selectedOrg);

                        final List<User> usersFromOrganization = getCalipso()
                                .findUsersInOrganizations(selectedOrganization);

                        // TODO: dropdown of all organization

                        DropDownChoice usersFromOrganizationChoice = new DropDownChoice("field",
                                usersFromOrganization, new UserChoiceRenderer());
                        usersFromOrganizationChoice.setNullValid(false);
                        usersFromOrganizationChoice.setRequired(valueRequired);
                        // i18n
                        usersFromOrganizationChoice.setLabel(new ResourceModel(i18nedFieldLabelResourceKey));
                        //f.add(model.bind(usersFromOrganizationChoice, field.getName().getText()));
                        usersFromOrganizationChoice.setModel(model.bind(field.getName().getText()));
                        f.add(usersFromOrganizationChoice);
                        listItem.add(f.setRenderBodyOnly(true));
                        label = new SimpleFormComponentLabel("label", usersFromOrganizationChoice);

                    } else if (field.getName().isCountry()) {
                        // organization fragment holds a dropDown of countries
                        final List<Country> allCountriesList = getCalipso().findAllCountries();
                        Fragment f = new Fragment("field", "dropDownFragment", CustomFieldsFormPanel.this);
                        // add HTML description through velocity
                        addVelocityTemplatePanel(f, "htmlDescriptionContainer", "htmlDescription",
                                field.getCustomAttribute().getHtmlDescription(), null, true);

                        listItem.add(f.setRenderBodyOnly(true));
                        DropDownChoice countryChoice = getCountriesDropDown("field", allCountriesList);
                        countryChoice.add(new ErrorHighlighter());

                        countryChoice.setRequired(valueRequired);
                        // i18n
                        countryChoice.setLabel(new ResourceModel(i18nedFieldLabelResourceKey));

                        //f.add(model.bind(countryChoice, field.getName().getText()));
                        countryChoice.setModel(model.bind(field.getName().getText()));
                        f.add(countryChoice);
                        label = new SimpleFormComponentLabel("label", countryChoice);

                    }

                    else {
                        if (logger.isDebugEnabled())
                            logger.debug("model.getObject(): " + model.getObject());
                        if (logger.isDebugEnabled())
                            logger.debug(
                                    "model.getObject().getClass(): " + model.getObject().getClass().getName());
                        if (logger.isDebugEnabled())
                            logger.debug("field.getName().getText(): " + field.getName().getText());
                        //if(logger.isDebugEnabled()) logger.debug("((Item)model.getObject()).getCusStr01(): "+((Item)model.getObject()).getCusStr01());
                        FormComponent textField;
                        Fragment f;

                        if (field.isMultivalue()) {
                            f = new Fragment("field", "multipleValuesTextField", CustomFieldsFormPanel.this);
                            // add HTML description through velocity
                            addVelocityTemplatePanel(f, "htmlDescriptionContainer", "htmlDescription",
                                    field.getCustomAttribute().getHtmlDescription(), null, true);

                            if (logger.isDebugEnabled())
                                logger.debug("model.getObject(): " + model.getObject());
                            if (logger.isDebugEnabled())
                                logger.debug("field.getName().getText(): " + field.getName().getText());
                            textField = preloadExistingValue
                                    ? new MultipleValuesTextField("field",
                                            new PropertyModel(model.getObject(), field.getName().getText()),
                                            field.getXmlConfig())
                                    : new MultipleValuesTextField("field", field.getXmlConfig());
                        } else if (field.getLineCount() == 1) {
                            f = new Fragment("field", "textField", CustomFieldsFormPanel.this);
                            // add HTML description through velocity
                            addVelocityTemplatePanel(f, "htmlDescriptionContainer", "htmlDescription",
                                    field.getCustomAttribute().getHtmlDescription(), null, true);
                            textField = preloadExistingValue
                                    ? new TextField("field",
                                            new PropertyModel(model.getObject(), field.getName().getText()))
                                    : new TextField("field");
                        } else {
                            f = new Fragment("field", "textareaField", CustomFieldsFormPanel.this);
                            // add HTML description through velocity
                            addVelocityTemplatePanel(f, "htmlDescriptionContainer", "htmlDescription",
                                    field.getCustomAttribute().getHtmlDescription(), null, true);
                            textField = preloadExistingValue ? new TextArea("field",
                                    new PropertyModel(model.getObject(), field.getName().getText())) {
                                @Override
                                protected void onComponentTag(ComponentTag tag) {
                                    super.onComponentTag(tag);
                                    tag.put("rows", field.getLineCount().toString());
                                }
                            } : new TextArea("field") {
                                @Override
                                protected void onComponentTag(ComponentTag tag) {
                                    super.onComponentTag(tag);
                                    tag.put("rows", field.getLineCount().toString());
                                }
                            };
                        }

                        // any validations for this field?
                        ValidationExpression validationExpression = getCalipso()
                                .loadValidationExpression(field.getValidationExpressionId());
                        if (validationExpression != null) {
                            textField.add(new ValidationExpressionValidator(validationExpression));
                        }

                        // TODO: do we need these two?
                        if (field.getName().getType() == 4) {
                            textField.setType(Double.class);
                        } else if (field.getName().isDecimalNumber()) {
                            textField.add(new PositiveNumberValidator());
                        }

                        textField.add(new ErrorHighlighter());
                        textField.setRequired(valueRequired);
                        // i18n
                        textField.setLabel(new ResourceModel(i18nedFieldLabelResourceKey));
                        if (preloadExistingValue) {
                            f.add(textField);
                        } else {
                            //f.add(model.bind(textField, field.getName().getText()));
                            textField.setModel(model.bind(field.getName().getText()));
                            f.add(textField);
                        }
                        // f.add(textField);
                        listItem.add(f.setRenderBodyOnly(true));
                        label = new SimpleFormComponentLabel("label", textField);

                        // styles
                        FieldUtils.appendFieldStyles(field.getXmlConfig(), textField);
                    }

                    // add label
                    labelContainer.add(label != null ? label : new Label("label", ""));
                    if (field.getCustomAttribute() != null
                            && StringUtils.isBlank(field.getCustomAttribute().getHtmlDescription())) {
                        labelContainer.add(new SimpleAttributeModifier("class", "labelContainer"));
                    }
                    // mandatory?

                    // mark as mandatory in the UI?
                    labelContainer
                            .add(new Label("star", valueRequired ? "* " : " ").setEscapeModelStrings(false));
                }

                private SimpleFormComponentLabel renderAutoSuggest(final IModel model, ListItem listItem,
                        final Field field, String i18nedFieldLabelResourceKey, boolean valueRequired,
                        final Map<String, String> options) {
                    SimpleFormComponentLabel label = null;
                    Fragment f = new Fragment("field", "autoCompleteFragment", CustomFieldsFormPanel.this);
                    // add HTML description through velocity
                    addVelocityTemplatePanel(f, "htmlDescriptionContainer", "htmlDescription",
                            field.getCustomAttribute().getHtmlDescription(), null, true);

                    final List<String> autoKeys = new ArrayList<String>(
                            options != null ? new ArrayList<String>(options.keySet())
                                    : new ArrayList<String>());

                    // the autocomplet textField
                    // TODO: fix to render values instead of integer
                    AbstractAutoCompleteRenderer autoRenderer = new AbstractAutoCompleteRenderer() {

                        @Override
                        protected String getTextValue(Object object) {
                            // TODO Auto-generated method stub
                            return object.toString();
                        }

                        @Override
                        protected void renderChoice(Object object, Response response, String criteria) {
                            response.write(object.toString());
                        }

                    };

                    autoTextField = new AutoCompleteTextField("field",
                            new PropertyModel(field, "customAttribute.lookupValue")) {

                        // TODO: the list
                        @Override
                        protected Iterator<String> getChoices(String input) {

                            if (Strings.isEmpty(input)) {
                                List<String> emptyList = Collections.emptyList();
                                return emptyList.iterator();
                            }
                            List<String> searchResults = new ArrayList<String>();

                            for (String s : options.values()) {
                                if (s.startsWith(input)) {
                                    searchResults.add(s);
                                }
                            }
                            return searchResults.iterator();
                        }

                    };
                    autoTextField.add(new AjaxFormComponentUpdatingBehavior("onchange") {

                        @Override
                        protected void onUpdate(AjaxRequestTarget target) {
                            // TODO Auto-generated method stub
                            List<String> searchResults = new ArrayList<String>();
                            for (String s : options.values()) {
                                if (s.startsWith((String) autoTextField.getModelObject())) {
                                    searchResults.add(s);
                                }
                            }
                            target.addComponent(autoTextField);
                        }
                    });
                    // i18n
                    autoTextField.setLabel(new ResourceModel(i18nedFieldLabelResourceKey));
                    String componentValue = (String) ((autoTextField != null
                            && autoTextField.getModelObject() != null) ? autoTextField.getModelObject() : null);

                    autoTextField.setRequired(valueRequired);
                    WebMarkupContainer border = new WebMarkupContainer("border");
                    f.add(border);
                    border.add(new ErrorHighlighter(autoTextField));
                    autoTextField.setModel(new PropertyModel(model.getObject(), field.getName().getText()));
                    //border.add(model.bind(autoTextField, field.getName().getText()));
                    border.add(autoTextField);
                    if (logger.isDebugEnabled() && autoTextField != null
                            && autoTextField.getDefaultModelObjectAsString() != null) {
                        if (logger.isDebugEnabled())
                            logger.debug(
                                    "Auto complete value is :" + autoTextField.getDefaultModelObjectAsString());
                    }
                    listItem.add(f.setRenderBodyOnly(true));
                    label = new SimpleFormComponentLabel("label", autoTextField);
                    return label;

                    // -------------------------
                }

                private SimpleFormComponentLabel addFileInputField(final CompoundPropertyModel model,
                        final Map<String, FileUploadField> fileUploadFields, ListItem listItem,
                        final Field field, String i18nedFieldLabelResourceKey, boolean valueRequired) {
                    SimpleFormComponentLabel label = null;
                    Fragment f = new Fragment("field", "fileField", CustomFieldsFormPanel.this);
                    // add HTML description through velocity
                    addVelocityTemplatePanel(f, "htmlDescriptionContainer", "htmlDescription",
                            field.getCustomAttribute().getHtmlDescription(), null, true);

                    FileUploadField fileField = new FileUploadField("field");
                    fileUploadFields.put(field.getLabel(), fileField);
                    fileField.add(new ErrorHighlighter());

                    fileField.setRequired(valueRequired);
                    // i18n
                    fileField.setLabel(new ResourceModel(
                            StringUtils.isNotBlank(i18nedFieldLabelResourceKey) ? i18nedFieldLabelResourceKey
                                    : Field.FIELD_TYPE_SIMPLE_ATTACHEMENT));//field.getName().getText().equalsIgnoreCase(Field.FIELD_TYPE_SIMPLE_ATTACHEMENT) ? Field.FIELD_TYPE_SIMPLE_ATTACHEMENT : i18nedFieldLabelResourceKey));

                    //f.add(model.bind(fileField, field.getName().getText()));
                    fileField.setModel(new Model());
                    // List<FileUpload> fileUploads = new LinkedList<FileUpload>();
                    f.add(fileField);
                    listItem.add(f.setRenderBodyOnly(true));
                    label = new SimpleFormComponentLabel("label", fileField);
                    return label;
                }

                /**
                 * @param model
                 * @param listItem
                 * @param field
                 * @param i18nedFieldLabelResourceKey
                 * @param valueRequired
                 * @param options
                 */
                private SimpleFormComponentLabel renderDropDown(final IModel model, ListItem listItem,
                        final Field field, String i18nedFieldLabelResourceKey, boolean valueRequired,
                        final Map<String, String> options) {
                    SimpleFormComponentLabel label = null;
                    /*
                     final List<CustomAttributeLookupValue> lookupValues = getCalipso().findLookupValuesByCustomAttribute(field.getCustomAttribute());
                          TreeChoice choice = new TreeChoice("field", new PropertyModel(field, "customAttribute.lookupValue"), lookupValues);
                          choice.setType(CustomAttributeLookupValue.class);
                          //choice.setType(Long.class);
                          choice.setRequired(valueRequired);
                          // i18n
                          choice.setLabel(new ResourceModel(i18nedFieldLabelResourceKey));
                          WebMarkupContainer border = new WebMarkupContainer("border");
                          f.add(border);
                          //border.add(new ErrorHighlighter(choice));
                          border.add(choice);
                                  
                     */

                    // drop down list
                    final Fragment fragment = new Fragment("field", "dropDown", CustomFieldsFormPanel.this);
                    if (field.getCustomAttribute() == null) {
                        field.setCustomAttribute(getCalipso().loadItemCustomAttribute(getCurrentSpace(),
                                field.getName().getText()));
                    }
                    // add HTML description through velocity
                    logger.info("field name:" + field.getName() + ", custom atribute: "
                            + field.getCustomAttribute());
                    addVelocityTemplatePanel(fragment, "htmlDescriptionContainer", "htmlDescription",
                            field.getCustomAttribute() != null ? field.getCustomAttribute().getHtmlDescription()
                                    : "",
                            null, true);

                    final List<CustomAttributeLookupValue> lookupValues = getCalipso()
                            .findActiveLookupValuesByCustomAttribute(field.getCustomAttribute());
                    // preselect previous user choice from DB if available
                    Object preselected = item.getValue(field.getName());
                    if (preselected != null) {
                        String sPreselectedId = preselected.toString();
                        if (CollectionUtils.isNotEmpty(lookupValues)) {
                            for (CustomAttributeLookupValue value : lookupValues) {
                                if ((value.getId() + "").equals(sPreselectedId)) {
                                    field.getCustomAttribute().setLookupValue(value);
                                    break;
                                }
                            }
                        }
                    }
                    // else set using the default string value instead, if any
                    // TODO: move this into a LookupValueDropDownChoice class
                    else {
                        String defaultStringValue = field.getCustomAttribute() != null
                                ? field.getCustomAttribute().getDefaultStringValue()
                                : null;
                        if (defaultStringValue != null && CollectionUtils.isNotEmpty(lookupValues)) {
                            for (CustomAttributeLookupValue value : lookupValues) {
                                if (value.getValue().equals(defaultStringValue)) {
                                    field.getCustomAttribute().setLookupValue(value);
                                    break;
                                }
                            }
                        }
                    }
                    DropDownChoice choice = new DropDownChoice("field",
                            new PropertyModel(field, "customAttribute.lookupValue"), lookupValues,
                            new IChoiceRenderer<CustomAttributeLookupValue>() {
                                @Override
                                public Object getDisplayValue(CustomAttributeLookupValue o) {
                                    return fragment.getString(o.getNameTranslationResourceKey());
                                }

                                @Override
                                public String getIdValue(CustomAttributeLookupValue o, int index) {
                                    return String.valueOf(index);
                                }
                            });
                    choice.setNullValid(true);

                    // i18n
                    choice.setLabel(new ResourceModel(i18nedFieldLabelResourceKey));
                    choice.setRequired(valueRequired);
                    WebMarkupContainer border = new WebMarkupContainer("border");
                    fragment.add(border);
                    border.add(new ErrorHighlighter(choice));
                    //border.add(model.bind(choice, field.getName().getText()));
                    border.add(choice);
                    listItem.add(fragment.setRenderBodyOnly(true));
                    label = new SimpleFormComponentLabel("label", choice);
                    return label;
                }

                /**
                 * @param model
                 * @param listItem
                 * @param field
                 * @param i18nedFieldLabelResourceKey
                 * @param valueRequired
                 * @param options
                 */
                private SimpleFormComponentLabel renderPeriodPartDropDown(final CompoundPropertyModel model,
                        ListItem listItem, final Field field, String i18nedFieldLabelResourceKey,
                        boolean valueRequired, final List<Date> options) {
                    SimpleFormComponentLabel label = null;
                    // drop down list
                    Fragment f = new Fragment("field", "dropDown", CustomFieldsFormPanel.this);

                    // add HTML description through velocity
                    addVelocityTemplatePanel(f, "htmlDescriptionContainer", "htmlDescription",
                            field.getCustomAttribute().getHtmlDescription(), null, true);

                    DropDownChoice choice = new DropDownChoice("field", options, new IChoiceRenderer() {
                        @Override
                        public Object getDisplayValue(Object o) {
                            return DateUtils.format((Date) o);
                        };

                        @Override
                        public String getIdValue(Object o, int i) {
                            return String.valueOf(i);
                        };
                    });
                    choice.setNullValid(true);
                    // i18n
                    choice.setLabel(new ResourceModel(i18nedFieldLabelResourceKey));
                    choice.setRequired(valueRequired);
                    WebMarkupContainer border = new WebMarkupContainer("border");
                    f.add(border);
                    border.add(new ErrorHighlighter(choice));
                    //border.add(model.bind(choice, field.getName().getText()));
                    choice.setModel(model.bind(field.getName().getText()));
                    border.add(choice);
                    listItem.add(f.setRenderBodyOnly(true));
                    label = new SimpleFormComponentLabel("label", choice);
                    return label;
                }
            };
            if (editableGroupFields.isEmpty()) {
                listItem.setVisible(false);
            }
            listView.setReuseItems(true);
            listItem.add(listView.setRenderBodyOnly(true));

        }

    };
    add(fieldGroups.setReuseItems(true));

    // 
}

From source file:net.tirasa.hct.editor.wicket.markup.html.AjaxTextFieldPanel.java

License:Apache License

public AjaxTextFieldPanel(final String id, final String name, final IModel<String> model,
        final boolean active) {

    super(id, name, model, active);

    field = new AutoCompleteTextField<String>("textField", model) {

        private static final long serialVersionUID = -6648767303091874219L;

        @Override/*from w  ww .jav  a 2s  .  c  o m*/
        protected Iterator<String> getChoices(final String input) {
            final Pattern pattern = Pattern.compile(Pattern.quote(input) + ".*", Pattern.CASE_INSENSITIVE);

            final List<String> result = new ArrayList<String>();

            for (String choice : choices) {
                if (pattern.matcher(choice).matches()) {
                    result.add(choice);
                }
            }

            return result.iterator();
        }
    };

    add(field.setLabel(new Model(name)).setOutputMarkupId(true));

    if (active) {
        field.add(new AjaxFormComponentUpdatingBehavior("onchange") {

            private static final long serialVersionUID = -1107858522700306810L;

            @Override
            protected void onUpdate(final AjaxRequestTarget art) {
                // nothing to do
            }
        });
    }
}

From source file:org.apache.jetspeed.portlets.site.PortalSiteManager.java

License:Apache License

public PortalSiteManager() {
    super();//w  w w. j  a v  a  2s .co  m
    List<ITab> tabList = new ArrayList<ITab>();
    DefaultMutableTreeNode rootNode = populateTree();
    populateDocument(getInitSiteTreeNode());
    PortalTree siteTree = new PortalTree("siteTree", new PropertyModel(this, "treeRoot"));
    siteTree.getTreeState().expandNode(rootNode);
    tabPanel = new AjaxTabbedPanel("tabs", tabList);
    tabPanel.setOutputMarkupId(true);
    add(siteTree);
    Form treeForm = new Form("treeForm");
    treeForm.add(new AutoCompleteTextField<String>("userFolder", new PropertyModel(this, "userFolder")) {

        @Override
        protected Iterator<String> getChoices(String input) {
            if (Strings.isEmpty(input) || input.length() < 1) {
                List<String> emptyList = Collections.emptyList();
                return emptyList.iterator();
            }
            List<String> choices = new ArrayList<String>(10);
            List<String> userNames = null;
            try {
                userNames = getServiceLocator().getUserManager().getUserNames(input);
            } catch (SecurityException e) {
                log.error("Failed to retrieve user names.", e);
            }
            if (userNames == null) {
                List<String> emptyList = Collections.emptyList();
                return emptyList.iterator();
            }
            if (userNames.size() > 10) {
                return userNames.subList(0, 10).iterator();
            } else {
                return userNames.iterator();
            }
        }
    }.setRequired(true));
    treeForm.add(new Button("userFolderButton") {

        @Override
        public void onSubmit() {
            ((LinkTree) getPage().get("siteTree")).getTreeState().expandNode(populateUserTree(userFolder));
        }
    });
    treeForm.add(new Button("portalFolderButton") {

        @Override
        public void onSubmit() {
            setUserFolder("");
            ((LinkTree) getPage().get("siteTree")).getTreeState().expandNode(populateTree());
        }
    });
    add(new FeedbackPanel("feedback"));
    add(treeForm);
    add(tabPanel);
    controlTabs();

    setVisibilitiesOfChildComponentsByPreferences("component.visibility.", true);
}

From source file:org.bosik.diacomp.web.frontend.wicket.components.mealeditor.picker.food.FoodPicker.java

License:Open Source License

@Override
protected void onInitialize() {
    super.onInitialize();

    Form<Void> form = new Form<>("form");
    add(form);//from  w w w  .  ja va  2s . c  o  m

    field = new AutoCompleteTextField<String>("picker", model) {
        private static final long serialVersionUID = 1L;

        @Override
        protected Iterator<String> getChoices(String input) {
            List<String> choices = new ArrayList<>();
            int userId = userInfoService.getCurrentUserId();
            List<Versioned<FoodItem>> list = foodService.findAny(userId, input);

            for (final Versioned<FoodItem> item : list) {
                choices.add(item.getData().getName());
            }

            return choices.iterator();
        }
    };
    field.add(new AjaxFormSubmitBehavior(form, "onchange") {
        private static final long serialVersionUID = 1L;

        @Override
        protected void onSubmit(AjaxRequestTarget target) {
            String name = field.getModelObject();
            int userId = userInfoService.getCurrentUserId();
            Versioned<FoodItem> food = foodService.findOne(userId, name);
            if (food != null) {
                Food item = food.getData();
                onSelected(target, Model.of(item));
            }
        }

        @Override
        protected void onError(AjaxRequestTarget target) {
        }
    });
    field.setOutputMarkupId(true);
    form.add(field);
}

From source file:org.brixcms.demo.web.tile.ajax.AjaxDemoPanel.java

License:Apache License

public AjaxDemoPanel(String id) {
    super(id);/*from  w ww  .  ja v a 2s  . c  om*/

    Form<Void> form = new Form<>("form");
    add(form);

    final IModel<String> model = new IModel<String>() {
        private String value = null;

        @Override
        public String getObject() {
            return value;
        }

        @Override
        public void setObject(String object) {
            value = object;

            values.append("\n");
            values.append(value);
        }

        @Override
        public void detach() {
        }
    };

    final AutoCompleteTextField<String> field = new AutoCompleteTextField<String>("ac", model) {
        @Override
        protected Iterator<String> getChoices(String input) {
            if (Strings.isEmpty(input)) {
                List<String> emptyList = Collections.emptyList();
                return emptyList.iterator();
            }

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

            Locale[] locales = Locale.getAvailableLocales();

            for (final Locale locale : locales) {
                final String country = locale.getDisplayCountry();

                if (country.toUpperCase().startsWith(input.toUpperCase())) {
                    choices.add(country);
                    if (choices.size() == 10) {
                        break;
                    }
                }
            }

            return choices.iterator();
        }
    };
    form.add(field);

    final MultiLineLabel label = new MultiLineLabel("history", new PropertyModel<String>(this, "values"));
    label.setOutputMarkupId(true);
    form.add(label);

    field.add(new AjaxFormSubmitBehavior(form, "change") {
        @Override
        protected void onSubmit(AjaxRequestTarget target) {
            target.add(label);
        }

        @Override
        protected void onError(AjaxRequestTarget target) {
        }
    });
}

From source file:org.cipango.ims.hss.web.publicid.PublicIdBrowserPage.java

License:Apache License

@SuppressWarnings("unchecked")
private void addSearchField(String search) {
    Form form = new Form("form");
    add(form);// w ww .ja  v a2s.  c om

    AutoCompleteTextField<String> field = new AutoCompleteTextField<String>("searchInput",
            new Model<String>(search)) {
        @Override
        protected Iterator<String> getChoices(String input) {
            if (input == null || input.length() < 2 && input.trim().length() < 2) {
                List<String> emptyList = Collections.emptyList();
                return emptyList.iterator();
            }

            List<String> choices = _dao.findLike("%" + input + "%", 10);
            return choices.iterator();
        }
    };
    form.add(field);

    form.add(new Button("search") {
        @Override
        public void onSubmit() {
            String id = (String) getForm().get("searchInput").getDefaultModelObject();
            if (!Strings.isEmpty(id)) {
                PublicIdentity publicIdentity = _dao.findById(id);
                if (publicIdentity == null)
                    setResponsePage(PublicIdBrowserPage.class, new PageParameters("search=" + id));
                else if (publicIdentity instanceof PSI)
                    setResponsePage(EditPsiPage.class, new PageParameters("id=" + id));
                else
                    setResponsePage(EditPublicUserIdPage.class, new PageParameters("id=" + id));
            }
        }
    });
}

From source file:org.cipango.ims.hss.web.spt.HeaderSptPanel.java

License:Apache License

public HeaderSptPanel(String id, IModel<SPT> sptModel) {
    super(id, sptModel);
    add(new AutoCompleteTextField<String>("header", String.class) {

        @Override/*from w w w  .  j a  v a 2s  .c  om*/
        protected Iterator<String> getChoices(String input) {
            if (Strings.isEmpty(input)) {
                return Headers.ALL_HEADERS.iterator();
            }
            input = input.trim().toLowerCase();
            List<String> headers = new ArrayList<String>();
            Iterator<String> it = Headers.ALL_HEADERS.iterator();
            while (it.hasNext()) {
                String name = (String) it.next();
                if (name.toLowerCase().startsWith(input))
                    headers.add(name);
            }
            return headers.iterator();
        }

        @SuppressWarnings("unchecked")
        public boolean isRequired() {
            return EditSptsPage.isRequired((Form) findParent(Form.class));
        }

    }.add(new EditSptsPage.SptUpdatingBehaviour()));
    add(new ConditionalTextField("content"));
}

From source file:org.geoserver.qos.web.OperationAnomalyFeedPanel.java

License:Open Source License

public OperationAnomalyFeedPanel(String id, IModel<ReferenceType> model) {
    super(id, model);
    anomalyFeedModel = model;/*  ww  w . j  a  v a2s  .co m*/

    ReferenceType anomalyFeed = model.getObject();
    if (anomalyFeed.getAbstracts() == null) {
        anomalyFeed.setAbstracts(
                new ArrayList<OwsAbstract>(Arrays.asList(new OwsAbstract[] { new OwsAbstract("") })));
    }

    final WebMarkupContainer div = new WebMarkupContainer("anomalyDiv");
    div.setOutputMarkupId(true);
    add(div);

    TextField<String> hrefField = new TextField<String>("href", new PropertyModel<>(anomalyFeedModel, "href")) {
    };
    div.add(hrefField);

    TextField<String> abstractField = new TextField<String>("abstract",
            new PropertyModel<>(anomalyFeedModel, "abstractOne")) {
    };
    div.add(abstractField);

    final AutoCompleteTextField<String> formatField = new AutoCompleteTextField<String>("format",
            new PropertyModel<>(anomalyFeedModel, "format")) {

        @Override
        protected Iterator<String> getChoices(String input) {
            if (StringUtils.isEmpty(input) || StringUtils.isEmpty(input.trim())) {
                return Collections.emptyIterator();
            }
            return MimeTypes.getMimeTypeValuesStream().filter(m -> m.startsWith(input)).limit(10).iterator();
        }
    };
    //        TextField<String> formatField =
    //                new TextField<String>("format", new PropertyModel<>(anomalyFeed,
    // "format")) {};
    div.add(formatField);

    final AjaxSubmitLink deleteLink = new AjaxSubmitLink("deleteLink") {
        @Override
        public void onAfterSubmit(AjaxRequestTarget target, Form<?> form) {
            delete(target);
        }
    };
    div.add(deleteLink);
}