public NameUriField(final String id, final IModel<StringCodec> codecModel, final String url, final String name, final Boolean urlFieldEnabled) { super(id); this.codecModel = codecModel; // If urlFieldEnabled is null, we check if the encoded version of param name equals param url. If true we // choose to keep the name field in control of the value of url, otherwise control over the url field is // handed over to the user. urlIsEditable = urlFieldEnabled != null ? urlFieldEnabled : StringUtils.isNotEmpty(name) && !StringUtils.equals(encode(name), url); nameModel = Model.of(name); add(nameComponent = createNameComponent()); urlModel = new Model<String>(url) { @Override public String getObject() { return encode(urlIsEditable ? super.getObject() : getName()); } }; add(urlComponent = createUrlComponent()); add(createUrlAction()); }
@Override public String getObject() { return encode(urlIsEditable ? super.getObject() : getName()); } };
public RenameDocumentDialog(StdWorkflow action, IModel<String> title) { super(action, null, title); setSize(DialogConstants.MEDIUM_AUTO); nameModel = PropertyModel.of(action, "targetName"); uriModel = PropertyModel.of(action, "uriName"); final IModel<StringCodec> codecModel = getStringCodecModel(); final String originalTargetName = nameModel.getObject(); final String originalUriName = uriModel.getObject(); add(nameUriField = new NameUriField("name-url", codecModel, originalUriName, originalTargetName, true)); }
public String getUrlValue() { if (urlIsEditable) { final String url = urlComponent.getValue(); return url != null ? url.toLowerCase() : StringUtils.EMPTY; } else { // read URL directly from the name component because the URL component's model may not have been updated yet final String name = nameComponent.getValue(); return name != null ? encode(name.toLowerCase()) : StringUtils.EMPTY; } } }
@Override protected void updateAjaxAttributes(final AjaxRequestAttributes attributes) { super.updateAjaxAttributes(attributes); attributes.setChannel(ajaxChannel); attributes.setThrottlingSettings(new ThrottlingSettings(getPath(), NAME_COMPONENT_THROTTLE_DURATION)); } });
@Override public void onClick(final AjaxRequestTarget target) { urlIsEditable = !urlIsEditable; urlComponent.modelChanging(); urlModel.setObject(getName()); urlComponent.modelChanged(); final Form<?> form = urlComponent.getForm(); if (form.hasFeedbackMessage()) { form.getFeedbackMessages().clear(); } if (!urlComponent.isValid()) { urlComponent.validate(); } target.add(this); target.add(urlComponent); target.focusComponent(urlIsEditable ? urlComponent : nameComponent); } };
public RenameDocumentDialog(StdWorkflow action, IModel<String> title, IModel<StringCodec> codecModel) { super(action, null, title); setSize(DialogConstants.MEDIUM_AUTO); nameModel = new PropertyModel<>(action, "targetName"); uriModel = new PropertyModel<>(action, "uriName"); String originalName = nameModel.getObject(); String originalUriName = uriModel.getObject(); add(nameUriField = new NameUriField("name-url", codecModel, originalUriName, originalName, true)); add(new RenameDocumentValidator(this, nameUriField, action.getModel())); }