use of org.apache.syncope.client.console.wicket.markup.html.form.AjaxTextFieldPanel in project syncope by apache.
the class ConnObjectPanel method getValuePanel.
/**
* Get panel for attribute value (not remote status).
*
* @param id component id to be replaced with the fragment content.
* @param attrTO remote attribute.
* @return fragment.
*/
private Panel getValuePanel(final String id, final String schemaName, final AttrTO attrTO) {
Panel field;
if (attrTO == null) {
field = new AjaxTextFieldPanel(id, schemaName, new Model<>());
} else if (CollectionUtils.isEmpty(attrTO.getValues())) {
field = new AjaxTextFieldPanel(id, schemaName, new Model<>());
} else if (ConnIdSpecialName.PASSWORD.equals(schemaName)) {
field = new AjaxTextFieldPanel(id, schemaName, new Model<>("********"));
} else if (attrTO.getValues().size() == 1) {
field = new AjaxTextFieldPanel(id, schemaName, new Model<>(attrTO.getValues().get(0)));
} else {
field = new MultiFieldPanel.Builder<>(new ListModel<>(attrTO.getValues())).build(id, schemaName, new AjaxTextFieldPanel("panel", schemaName, new Model<>()));
}
field.setEnabled(false);
return field;
}
use of org.apache.syncope.client.console.wicket.markup.html.form.AjaxTextFieldPanel in project syncope by apache.
the class SearchClausePanel method settingsDependingComponents.
@Override
public FieldPanel<SearchClause> settingsDependingComponents() {
final SearchClause searchClause = this.clause.getObject();
final WebMarkupContainer operatorContainer = new WebMarkupContainer("operatorContainer");
operatorContainer.setOutputMarkupId(true);
field.add(operatorContainer);
final BootstrapToggleConfig config = new BootstrapToggleConfig().withOnStyle(BootstrapToggleConfig.Style.info).withOffStyle(BootstrapToggleConfig.Style.warning).withSize(BootstrapToggleConfig.Size.mini);
operatorFragment.add(new BootstrapToggle("operator", new Model<Boolean>() {
private static final long serialVersionUID = -7157802546272668001L;
@Override
public Boolean getObject() {
return searchClause.getOperator() == Operator.AND;
}
@Override
public void setObject(final Boolean object) {
searchClause.setOperator(object ? Operator.AND : Operator.OR);
}
}, config) {
private static final long serialVersionUID = 2969634208049189343L;
@Override
protected IModel<String> getOffLabel() {
return Model.of("OR");
}
@Override
protected IModel<String> getOnLabel() {
return Model.of("AND");
}
@Override
protected CheckBox newCheckBox(final String id, final IModel<Boolean> model) {
final CheckBox checkBox = super.newCheckBox(id, model);
checkBox.add(new IndicatorAjaxFormComponentUpdatingBehavior(Constants.ON_CHANGE) {
private static final long serialVersionUID = 1L;
@Override
protected void onUpdate(final AjaxRequestTarget target) {
}
});
return checkBox;
}
}.setOutputMarkupPlaceholderTag(true));
if (getIndex() > 0) {
operatorContainer.add(operatorFragment);
} else {
operatorContainer.add(searchButtonFragment);
}
final AjaxTextFieldPanel property = new AjaxTextFieldPanel("property", "property", new PropertyModel<String>(searchClause, "property"), false);
property.hideLabel().setOutputMarkupId(true).setEnabled(true);
property.setChoices(properties.getObject());
field.add(property);
property.getField().add(AttributeModifier.replace("onkeydown", Model.of("if(event.keyCode == 13) { event.preventDefault(); }")));
property.getField().add(new IndicatorAjaxEventBehavior("onkeyup") {
private static final long serialVersionUID = -7866120562087857309L;
@Override
protected void onEvent(final AjaxRequestTarget target) {
if (field.getModel().getObject() == null || field.getModel().getObject().getType() == null) {
return;
}
if (field.getModel().getObject().getType() == Type.GROUP_MEMBERSHIP) {
String[] inputAsArray = property.getField().getInputAsArray();
if (StringUtils.isBlank(property.getField().getInput()) || inputAsArray.length == 0) {
property.setChoices(properties.getObject());
} else {
String inputValue = (inputAsArray.length > 1 && inputAsArray[1] != null) ? inputAsArray[1] : property.getField().getInput();
inputValue = (inputValue.startsWith("*") && !inputValue.endsWith("*")) ? inputValue + "*" : (!inputValue.startsWith("*") && inputValue.endsWith("*")) ? "*" + inputValue : (inputValue.startsWith("*") && inputValue.endsWith("*") ? inputValue : "*" + inputValue + "*");
if (groupInfo.getRight() > AnyObjectSearchPanel.MAX_GROUP_LIST_CARDINALITY) {
List<GroupTO> filteredGroups = groupRestClient.search("/", SyncopeClient.getGroupSearchConditionBuilder().is("name").equalToIgnoreCase(inputValue).query(), 1, AnyObjectSearchPanel.MAX_GROUP_LIST_CARDINALITY, new SortParam<>("name", true), null);
Collection<String> newList = CollectionUtils.collect(filteredGroups, new Transformer<GroupTO, String>() {
@Override
public String transform(final GroupTO input) {
return input.getName();
}
});
final List<String> names = new ArrayList<>(newList);
Collections.sort(names);
property.setChoices(names);
}
}
}
}
@Override
protected void updateAjaxAttributes(final AjaxRequestAttributes attributes) {
super.updateAjaxAttributes(attributes);
attributes.getAjaxCallListeners().clear();
}
}, new IndicatorAjaxFormComponentUpdatingBehavior(Constants.ON_CHANGE) {
private static final long serialVersionUID = -1107858522700306810L;
@Override
protected void onUpdate(final AjaxRequestTarget target) {
}
});
final AjaxDropDownChoicePanel<SearchClause.Comparator> comparator = new AjaxDropDownChoicePanel<>("comparator", "comparator", new PropertyModel<>(searchClause, "comparator"));
comparator.setChoices(comparators);
comparator.setNullValid(false).hideLabel().setOutputMarkupId(true);
comparator.setRequired(required);
comparator.setChoiceRenderer(getComparatorRender(field.getModel()));
field.add(comparator);
final AjaxTextFieldPanel value = new AjaxTextFieldPanel("value", "value", new PropertyModel<>(searchClause, "value"), false);
value.hideLabel().setOutputMarkupId(true);
field.add(value);
value.getField().add(AttributeModifier.replace("onkeydown", Model.of("if(event.keyCode == 13) {event.preventDefault();}")));
value.getField().add(new IndicatorAjaxEventBehavior("onkeydown") {
private static final long serialVersionUID = -7133385027739964990L;
@Override
protected void onEvent(final AjaxRequestTarget target) {
target.focusComponent(null);
value.getField().inputChanged();
value.getField().validate();
if (value.getField().isValid()) {
value.getField().valid();
value.getField().updateModel();
}
}
@Override
protected void updateAjaxAttributes(final AjaxRequestAttributes attributes) {
super.updateAjaxAttributes(attributes);
attributes.getAjaxCallListeners().add(new AjaxCallListener() {
private static final long serialVersionUID = 7160235486520935153L;
@Override
public CharSequence getPrecondition(final Component component) {
return "if (Wicket.Event.keyCode(attrs.event) == 13) { return true; } else { return false; }";
}
});
}
});
final AjaxDropDownChoicePanel<SearchClause.Type> type = new AjaxDropDownChoicePanel<>("type", "type", new PropertyModel<>(searchClause, "type"));
type.setChoices(types).hideLabel().setRequired(required).setOutputMarkupId(true);
type.setNullValid(false);
type.getField().add(new IndicatorAjaxFormComponentUpdatingBehavior(Constants.ON_CHANGE) {
private static final long serialVersionUID = -1107858522700306810L;
@Override
protected void onUpdate(final AjaxRequestTarget target) {
final SearchClause searchClause = new SearchClause();
if (StringUtils.isNotEmpty(type.getDefaultModelObjectAsString())) {
searchClause.setType(Type.valueOf(type.getDefaultModelObjectAsString()));
}
SearchClausePanel.this.clause.setObject(searchClause);
setFieldAccess(searchClause.getType(), property, comparator, value);
// reset property value in case and just in case of change of type
property.setModelObject(StringUtils.EMPTY);
target.add(property);
target.add(comparator);
target.add(value);
}
});
field.add(type);
comparator.getField().add(new IndicatorAjaxFormComponentUpdatingBehavior(Constants.ON_CHANGE) {
private static final long serialVersionUID = -1107858522700306810L;
@Override
protected void onUpdate(final AjaxRequestTarget target) {
if (type.getModelObject() == SearchClause.Type.ATTRIBUTE || type.getModelObject() == SearchClause.Type.RELATIONSHIP) {
if (comparator.getModelObject() == SearchClause.Comparator.IS_NULL || comparator.getModelObject() == SearchClause.Comparator.IS_NOT_NULL) {
value.setModelObject(StringUtils.EMPTY);
value.setEnabled(false);
} else {
value.setEnabled(true);
}
target.add(value);
}
if (type.getModelObject() == SearchClause.Type.RELATIONSHIP) {
property.setEnabled(true);
final SearchClause searchClause = new SearchClause();
searchClause.setType(Type.valueOf(type.getDefaultModelObjectAsString()));
searchClause.setComparator(comparator.getModelObject());
SearchClausePanel.this.clause.setObject(searchClause);
target.add(property);
}
}
});
setFieldAccess(searchClause.getType(), property, comparator, value);
return this;
}
use of org.apache.syncope.client.console.wicket.markup.html.form.AjaxTextFieldPanel in project syncope by apache.
the class ParametersDetailsPanel method getFieldPanel.
@SuppressWarnings({ "rawtypes", "unchecked" })
private Panel getFieldPanel(final String id, final AttrTO attrTO) {
final String valueHeaderName = getString("values");
final PlainSchemaTO schemaTO = schemaRestClient.read(SchemaType.PLAIN, attrTO.getSchema());
final FieldPanel panel;
switch(schemaTO.getType()) {
case Date:
final String datePattern = schemaTO.getConversionPattern() == null ? SyncopeConstants.DEFAULT_DATE_PATTERN : schemaTO.getConversionPattern();
if (StringUtils.containsIgnoreCase(datePattern, "H")) {
panel = new AjaxDateTimeFieldPanel("panel", schemaTO.getKey(), new Model<>(), datePattern);
} else {
panel = new AjaxDateFieldPanel("panel", schemaTO.getKey(), new Model<>(), datePattern);
}
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(schemaTO));
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".equalsIgnoreCase(schemaTO.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<>(), schemaTO.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 (schemaTO.isMultivalue()) {
return new MultiFieldPanel.Builder<>(new PropertyModel<List<String>>(attrTO, "values")).build(id, valueHeaderName, panel);
} else {
panel.setNewModel(attrTO.getValues());
}
panel.setRequired("true".equalsIgnoreCase(schemaTO.getMandatoryCondition()));
return panel;
}
use of org.apache.syncope.client.console.wicket.markup.html.form.AjaxTextFieldPanel in project syncope by apache.
the class AjaxTextFieldITCase method requiredAttribute.
@Test
public void requiredAttribute() {
TestPage<String, AjaxTextFieldPanel> testPage = new TestPage.Builder<String, AjaxTextFieldPanel>().build(new AjaxTextFieldPanel(TestPage.FIELD, TestPage.FIELD, TEXT_MODEL));
testPage.getFieldPanel().setOutputMarkupId(true);
testPage.getFieldPanel().getField().setRequired(true);
TESTER.startPage(testPage);
TESTER.assertLabel("form:field:field-label", "field");
TESTER.assertVisible("form:field:required");
TESTER.assertVisible("form:field:externalAction");
}
use of org.apache.syncope.client.console.wicket.markup.html.form.AjaxTextFieldPanel in project syncope by apache.
the class AjaxTextFieldITCase method nullIsNotValidated.
@Test
public void nullIsNotValidated() {
TestPage<String, AjaxTextFieldPanel> testPage = new TestPage.Builder<String, AjaxTextFieldPanel>().build(new AjaxTextFieldPanel(TestPage.FIELD, TestPage.FIELD, TEXT_MODEL));
testPage.getFieldPanel().getField().setRequired(false);
testPage.getFieldPanel().getField().add(StringValidator.minimumLength(2));
TESTER.startPage(testPage);
FormTester formTester = TESTER.newFormTester(testPage.getForm().getId());
formTester.setValue("field:textField", "");
formTester.submit();
assertNull(testPage.getFieldPanel().getDefaultModelObject());
assertTrue(testPage.getFieldPanel().getField().isValid());
}
Aggregations