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());
}
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)));
}
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;
}
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;
}
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));
}
}
Aggregations