Search in sources :

Example 6 with AjaxTextFieldPanel

use of org.apache.syncope.client.console.wicket.markup.html.form.AjaxTextFieldPanel in project syncope by apache.

the class AjaxTextFieldITCase method emptyInputConvertedToNull.

@Test
public void emptyInputConvertedToNull() {
    TestPage<String, AjaxTextFieldPanel> testPage = new TestPage.Builder<String, AjaxTextFieldPanel>().build(new AjaxTextFieldPanel(TestPage.FIELD, TestPage.FIELD, TEXT_MODEL));
    TESTER.startPage(testPage);
    FormTester formTester = TESTER.newFormTester(testPage.getForm().getId());
    formTester.setValue("field:textField", "");
    formTester.submit();
    assertNull(testPage.getFieldPanel().getField().getDefaultModelObject());
}
Also used : AjaxTextFieldPanel(org.apache.syncope.client.console.wicket.markup.html.form.AjaxTextFieldPanel) FormTester(org.apache.wicket.util.tester.FormTester) Test(org.junit.jupiter.api.Test)

Example 7 with AjaxTextFieldPanel

use of org.apache.syncope.client.console.wicket.markup.html.form.AjaxTextFieldPanel in project syncope by apache.

the class AjaxTextFieldITCase method valueAttribute.

@Test
public void valueAttribute() {
    TestPage<String, AjaxTextFieldPanel> testPage = new TestPage.Builder<String, AjaxTextFieldPanel>().build(new AjaxTextFieldPanel(TestPage.FIELD, TestPage.FIELD, TEXT_MODEL));
    String text = "sometext";
    TEXT_MODEL.setObject(text);
    TESTER.startPage(testPage);
    assertTrue(TESTER.getLastResponseAsString().contains(Strings.escapeMarkup(text)));
}
Also used : AjaxTextFieldPanel(org.apache.syncope.client.console.wicket.markup.html.form.AjaxTextFieldPanel) Test(org.junit.jupiter.api.Test)

Example 8 with AjaxTextFieldPanel

use of org.apache.syncope.client.console.wicket.markup.html.form.AjaxTextFieldPanel in project syncope by apache.

the class ParametersCreateWizardAttrStep method getFieldPanel.

@SuppressWarnings({ "rawtypes", "unchecked" })
private Panel getFieldPanel(final String id, final AttrTO attrTO, final PlainSchemaTO plainSchemaTO) {
    final String valueHeaderName = getString("values");
    final FieldPanel panel;
    switch(plainSchemaTO.getType()) {
        case Date:
            final String dataPattern = plainSchemaTO.getConversionPattern() == null ? SyncopeConstants.DEFAULT_DATE_PATTERN : plainSchemaTO.getConversionPattern();
            if (dataPattern.contains("H")) {
                panel = new AjaxDateTimeFieldPanel(id, valueHeaderName, new Model<>(), dataPattern);
            } else {
                panel = new AjaxDateFieldPanel("panel", valueHeaderName, new Model<>(), dataPattern);
            }
            break;
        case Boolean:
            panel = new AjaxDropDownChoicePanel<>(id, valueHeaderName, new Model<>(), false);
            ((AjaxDropDownChoicePanel<String>) panel).setChoices(Arrays.asList("true", "false"));
            if (!attrTO.getValues().isEmpty()) {
                ((AjaxDropDownChoicePanel) panel).setChoiceRenderer(new IChoiceRenderer<String>() {

                    private static final long serialVersionUID = -3724971416312135885L;

                    @Override
                    public String getDisplayValue(final String value) {
                        return value;
                    }

                    @Override
                    public String getIdValue(final String value, final int i) {
                        return value;
                    }

                    @Override
                    public String getObject(final String id, final IModel<? extends List<? extends String>> choices) {
                        return id;
                    }
                });
            }
            ((AjaxDropDownChoicePanel<String>) panel).setNullValid(false);
            break;
        case Enum:
            panel = new AjaxDropDownChoicePanel<>(id, valueHeaderName, new Model<>(), false);
            ((AjaxDropDownChoicePanel<String>) panel).setChoices(SchemaUtils.getEnumeratedValues(plainSchemaTO));
            if (!attrTO.getValues().isEmpty()) {
                ((AjaxDropDownChoicePanel) panel).setChoiceRenderer(new IChoiceRenderer<String>() {

                    private static final long serialVersionUID = -3724971416312135885L;

                    @Override
                    public String getDisplayValue(final String value) {
                        return value;
                    }

                    @Override
                    public String getIdValue(final String value, final int i) {
                        return value;
                    }

                    @Override
                    public String getObject(final String id, final IModel<? extends List<? extends String>> choices) {
                        return id;
                    }
                });
            }
            ((AjaxDropDownChoicePanel<String>) panel).setNullValid("true".equalsIgnoreCase(plainSchemaTO.getMandatoryCondition()));
            break;
        case Long:
            panel = new AjaxSpinnerFieldPanel.Builder<Long>().build(id, valueHeaderName, Long.class, new Model<Long>());
            break;
        case Double:
            panel = new AjaxSpinnerFieldPanel.Builder<Double>().build(id, valueHeaderName, Double.class, new Model<Double>());
            break;
        case Binary:
            panel = new BinaryFieldPanel(id, valueHeaderName, new Model<>(), plainSchemaTO.getMimeType(), schema.getModelObject());
            break;
        case Encrypted:
            panel = new EncryptedFieldPanel(id, valueHeaderName, new Model<>(), true);
            break;
        default:
            panel = new AjaxTextFieldPanel(id, valueHeaderName, new Model<>(), false);
    }
    if (plainSchemaTO.isMultivalue()) {
        return new MultiFieldPanel.Builder<>(new PropertyModel<>(attrTO, "values")).build(id, valueHeaderName, panel);
    } else {
        panel.setNewModel(attrTO.getValues());
    }
    panel.setRequired("true".equalsIgnoreCase(plainSchemaTO.getMandatoryCondition()));
    return panel;
}
Also used : AjaxTextFieldPanel(org.apache.syncope.client.console.wicket.markup.html.form.AjaxTextFieldPanel) MultiFieldPanel(org.apache.syncope.client.console.wicket.markup.html.form.MultiFieldPanel) AjaxDateFieldPanel(org.apache.syncope.client.console.wicket.markup.html.form.AjaxDateFieldPanel) PropertyModel(org.apache.wicket.model.PropertyModel) AjaxDropDownChoicePanel(org.apache.syncope.client.console.wicket.markup.html.form.AjaxDropDownChoicePanel) EncryptedFieldPanel(org.apache.syncope.client.console.wicket.markup.html.form.EncryptedFieldPanel) IModel(org.apache.wicket.model.IModel) Model(org.apache.wicket.model.Model) LoadableDetachableModel(org.apache.wicket.model.LoadableDetachableModel) PropertyModel(org.apache.wicket.model.PropertyModel) BinaryFieldPanel(org.apache.syncope.client.console.wicket.markup.html.form.BinaryFieldPanel) FieldPanel(org.apache.syncope.client.console.wicket.markup.html.form.FieldPanel) AjaxSpinnerFieldPanel(org.apache.syncope.client.console.wicket.markup.html.form.AjaxSpinnerFieldPanel) EncryptedFieldPanel(org.apache.syncope.client.console.wicket.markup.html.form.EncryptedFieldPanel) AjaxTextFieldPanel(org.apache.syncope.client.console.wicket.markup.html.form.AjaxTextFieldPanel) AjaxDateTimeFieldPanel(org.apache.syncope.client.console.wicket.markup.html.form.AjaxDateTimeFieldPanel) AjaxDateFieldPanel(org.apache.syncope.client.console.wicket.markup.html.form.AjaxDateFieldPanel) MultiFieldPanel(org.apache.syncope.client.console.wicket.markup.html.form.MultiFieldPanel) BinaryFieldPanel(org.apache.syncope.client.console.wicket.markup.html.form.BinaryFieldPanel) AjaxDateTimeFieldPanel(org.apache.syncope.client.console.wicket.markup.html.form.AjaxDateTimeFieldPanel)

Example 9 with AjaxTextFieldPanel

use of org.apache.syncope.client.console.wicket.markup.html.form.AjaxTextFieldPanel in project syncope by apache.

the class BeanPanel method buildSinglePanel.

@SuppressWarnings({ "unchecked", "rawtypes" })
private FieldPanel buildSinglePanel(final Serializable bean, final Class<?> type, final String fieldName, final String id) {
    FieldPanel result = null;
    PropertyModel model = new PropertyModel(bean, fieldName);
    if (ClassUtils.isAssignable(Boolean.class, type)) {
        result = new AjaxCheckBoxPanel(id, fieldName, model);
    } else if (ClassUtils.isAssignable(Number.class, type)) {
        result = new AjaxSpinnerFieldPanel.Builder<>().build(id, fieldName, (Class<Number>) ClassUtils.resolvePrimitiveIfNecessary(type), model);
    } else if (Date.class.equals(type)) {
        result = new AjaxDateTimeFieldPanel(id, fieldName, model, SyncopeConstants.DEFAULT_DATE_PATTERN);
    } else if (type.isEnum()) {
        result = new AjaxDropDownChoicePanel(id, fieldName, model).setChoices(Arrays.asList(type.getEnumConstants()));
    }
    // treat as String if nothing matched above
    if (result == null) {
        result = new AjaxTextFieldPanel(id, fieldName, model);
    }
    result.hideLabel();
    return result;
}
Also used : AjaxTextFieldPanel(org.apache.syncope.client.console.wicket.markup.html.form.AjaxTextFieldPanel) PropertyModel(org.apache.wicket.model.PropertyModel) AjaxSpinnerFieldPanel(org.apache.syncope.client.console.wicket.markup.html.form.AjaxSpinnerFieldPanel) AjaxDropDownChoicePanel(org.apache.syncope.client.console.wicket.markup.html.form.AjaxDropDownChoicePanel) FieldPanel(org.apache.syncope.client.console.wicket.markup.html.form.FieldPanel) AjaxSpinnerFieldPanel(org.apache.syncope.client.console.wicket.markup.html.form.AjaxSpinnerFieldPanel) AjaxTextFieldPanel(org.apache.syncope.client.console.wicket.markup.html.form.AjaxTextFieldPanel) AjaxDateTimeFieldPanel(org.apache.syncope.client.console.wicket.markup.html.form.AjaxDateTimeFieldPanel) MultiFieldPanel(org.apache.syncope.client.console.wicket.markup.html.form.MultiFieldPanel) AjaxCheckBoxPanel(org.apache.syncope.client.console.wicket.markup.html.form.AjaxCheckBoxPanel) AjaxDateTimeFieldPanel(org.apache.syncope.client.console.wicket.markup.html.form.AjaxDateTimeFieldPanel)

Example 10 with AjaxTextFieldPanel

use of org.apache.syncope.client.console.wicket.markup.html.form.AjaxTextFieldPanel in project syncope by apache.

the class ConnConfPropertyListView method populateItem.

@Override
@SuppressWarnings({ "unchecked", "rawtypes" })
protected void populateItem(final ListItem<ConnConfProperty> item) {
    final ConnConfProperty property = item.getModelObject();
    final String label = StringUtils.isBlank(property.getSchema().getDisplayName()) ? property.getSchema().getName() : property.getSchema().getDisplayName();
    final FieldPanel<? extends Serializable> field;
    boolean required = false;
    boolean isArray = false;
    if (property.getSchema().isConfidential() || Constants.GUARDED_STRING.equalsIgnoreCase(property.getSchema().getType()) || Constants.GUARDED_BYTE_ARRAY.equalsIgnoreCase(property.getSchema().getType())) {
        field = new AjaxPasswordFieldPanel("panel", label, new Model<>(), false);
        ((PasswordTextField) field.getField()).setResetPassword(false);
        required = property.getSchema().isRequired();
    } else {
        Class<?> propertySchemaClass;
        try {
            propertySchemaClass = ClassUtils.getClass(property.getSchema().getType());
            if (ClassUtils.isPrimitiveOrWrapper(propertySchemaClass)) {
                propertySchemaClass = org.apache.commons.lang3.ClassUtils.primitiveToWrapper(propertySchemaClass);
            }
        } catch (ClassNotFoundException e) {
            LOG.error("Error parsing attribute type", e);
            propertySchemaClass = String.class;
        }
        if (ClassUtils.isAssignable(Number.class, propertySchemaClass)) {
            @SuppressWarnings("unchecked") Class<Number> numberClass = (Class<Number>) propertySchemaClass;
            field = new AjaxSpinnerFieldPanel.Builder<>().build("panel", label, numberClass, new Model<>());
            required = property.getSchema().isRequired();
        } else if (ClassUtils.isAssignable(Boolean.class, propertySchemaClass)) {
            field = new AjaxCheckBoxPanel("panel", label, new Model<>());
        } else {
            field = new AjaxTextFieldPanel("panel", label, new Model<>());
            required = property.getSchema().isRequired();
        }
        if (propertySchemaClass.isArray()) {
            isArray = true;
        }
    }
    field.setIndex(item.getIndex());
    field.setTitle(property.getSchema().getHelpMessage(), true);
    final AbstractFieldPanel<? extends Serializable> fieldPanel;
    if (isArray) {
        final MultiFieldPanel multiFieldPanel = new MultiFieldPanel.Builder(new PropertyModel<>(property, "values")).setEventTemplate(true).build("panel", label, field);
        item.add(multiFieldPanel);
        fieldPanel = multiFieldPanel;
    } else {
        setNewFieldModel(field, property.getValues());
        item.add(field);
        fieldPanel = field;
    }
    if (required) {
        fieldPanel.addRequiredLabel();
    }
    if (withOverridable) {
        fieldPanel.showExternAction(addCheckboxToggle(property));
    }
}
Also used : AjaxTextFieldPanel(org.apache.syncope.client.console.wicket.markup.html.form.AjaxTextFieldPanel) MultiFieldPanel(org.apache.syncope.client.console.wicket.markup.html.form.MultiFieldPanel) ConnConfProperty(org.apache.syncope.common.lib.types.ConnConfProperty) PasswordTextField(org.apache.wicket.markup.html.form.PasswordTextField) AjaxCheckBoxPanel(org.apache.syncope.client.console.wicket.markup.html.form.AjaxCheckBoxPanel) AjaxPasswordFieldPanel(org.apache.syncope.client.console.wicket.markup.html.form.AjaxPasswordFieldPanel) IModel(org.apache.wicket.model.IModel) Model(org.apache.wicket.model.Model) PropertyModel(org.apache.wicket.model.PropertyModel)

Aggregations

AjaxTextFieldPanel (org.apache.syncope.client.console.wicket.markup.html.form.AjaxTextFieldPanel)11 MultiFieldPanel (org.apache.syncope.client.console.wicket.markup.html.form.MultiFieldPanel)6 IModel (org.apache.wicket.model.IModel)6 AjaxDropDownChoicePanel (org.apache.syncope.client.console.wicket.markup.html.form.AjaxDropDownChoicePanel)5 Model (org.apache.wicket.model.Model)5 PropertyModel (org.apache.wicket.model.PropertyModel)5 AjaxDateTimeFieldPanel (org.apache.syncope.client.console.wicket.markup.html.form.AjaxDateTimeFieldPanel)4 AjaxSpinnerFieldPanel (org.apache.syncope.client.console.wicket.markup.html.form.AjaxSpinnerFieldPanel)4 FieldPanel (org.apache.syncope.client.console.wicket.markup.html.form.FieldPanel)4 Test (org.junit.jupiter.api.Test)4 AjaxCheckBoxPanel (org.apache.syncope.client.console.wicket.markup.html.form.AjaxCheckBoxPanel)3 AjaxDateFieldPanel (org.apache.syncope.client.console.wicket.markup.html.form.AjaxDateFieldPanel)3 BinaryFieldPanel (org.apache.syncope.client.console.wicket.markup.html.form.BinaryFieldPanel)3 EncryptedFieldPanel (org.apache.syncope.client.console.wicket.markup.html.form.EncryptedFieldPanel)3 LoadableDetachableModel (org.apache.wicket.model.LoadableDetachableModel)2 ListModel (org.apache.wicket.model.util.ListModel)2 FormTester (org.apache.wicket.util.tester.FormTester)2 BootstrapToggle (de.agilecoders.wicket.extensions.markup.html.bootstrap.form.checkbox.bootstraptoggle.BootstrapToggle)1 BootstrapToggleConfig (de.agilecoders.wicket.extensions.markup.html.bootstrap.form.checkbox.bootstraptoggle.BootstrapToggleConfig)1 ArrayList (java.util.ArrayList)1