Index: api/src/main/java/org/hippoecm/frontend/widgets/NumberFieldWidget.html IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== --- api/src/main/java/org/hippoecm/frontend/widgets/NumberFieldWidget.html (revision ) +++ api/src/main/java/org/hippoecm/frontend/widgets/NumberFieldWidget.html (revision ) @@ -0,0 +1,20 @@ + + + + + + Index: api/src/main/java/org/hippoecm/frontend/model/properties/LongConverter.java IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== --- api/src/main/java/org/hippoecm/frontend/model/properties/LongConverter.java (revision ) +++ api/src/main/java/org/hippoecm/frontend/model/properties/LongConverter.java (revision ) @@ -0,0 +1,65 @@ +/* + * Copyright 2016 Hippo B.V. (http://www.onehippo.com) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.hippoecm.frontend.model.properties; + +import org.apache.wicket.model.IModel; +import org.hippoecm.frontend.session.UserSession; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import javax.jcr.RepositoryException; +import javax.jcr.Value; +import javax.jcr.ValueFactory; + +public class LongConverter implements IModel { + + private static final long serialVersionUID = 1L; + static final Logger log = LoggerFactory.getLogger(LongConverter.class); + private JcrPropertyValueModel decorated; + + public LongConverter(JcrPropertyValueModel valueModel) { + decorated = valueModel; + } + + public Long getObject() { + try { + if (decorated != null && decorated.getValue() != null) { + return decorated.getValue().getLong(); + } else { + log.debug("LongConverter: JcrPropertyValueModel decorated equals null"); + } + } catch (RepositoryException ex) { + log.info(ex.getMessage()); + } + return null; + } + + public void setObject(Long object) { + try { + long longValue = object == null ? 0l : object; + ValueFactory factory = UserSession.get().getJcrSession().getValueFactory(); + Value value = factory.createValue(longValue); + decorated.setValue(value); + } catch (RepositoryException ex) { + log.info(ex.getMessage()); + } + } + + public void detach() { + decorated.detach(); + } + +} Index: editor/frontend/src/main/java/org/hippoecm/frontend/editor/plugins/ValueTemplatePlugin.java IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== --- editor/frontend/src/main/java/org/hippoecm/frontend/editor/plugins/ValueTemplatePlugin.java (revision 57521) +++ editor/frontend/src/main/java/org/hippoecm/frontend/editor/plugins/ValueTemplatePlugin.java (revision ) @@ -1,5 +1,5 @@ /* - * Copyright 2008-2015 Hippo B.V. (http://www.onehippo.com) + * Copyright 2008-2016 Hippo B.V. (http://www.onehippo.com) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,16 +21,20 @@ import org.apache.wicket.util.string.Strings; import org.hippoecm.frontend.model.IModelReference; import org.hippoecm.frontend.model.properties.JcrPropertyValueModel; +import org.hippoecm.frontend.model.properties.LongConverter; import org.hippoecm.frontend.model.properties.StringConverter; import org.hippoecm.frontend.plugin.IPluginContext; import org.hippoecm.frontend.plugin.config.IPluginConfig; import org.hippoecm.frontend.plugins.standards.diff.TextDiffModel; import org.hippoecm.frontend.service.IEditor; import org.hippoecm.frontend.service.render.RenderPlugin; +import org.hippoecm.frontend.widgets.NumberFieldWidget; import org.hippoecm.frontend.widgets.TextFieldWidget; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import javax.jcr.PropertyType; + public class ValueTemplatePlugin extends RenderPlugin { private static final long serialVersionUID = 1L; @@ -44,14 +48,23 @@ final IEditor.Mode mode = IEditor.Mode.fromString(config.getString("mode"), IEditor.Mode.VIEW); switch (mode) { case EDIT: - TextFieldWidget widget = new TextFieldWidget("value", stringModel); + if (((JcrPropertyValueModel) getModel()).getType() == PropertyType.LONG) { + final LongConverter longModel = new LongConverter((JcrPropertyValueModel) getModel()); + add(new NumberFieldWidget("value", longModel)); + } else { + + TextFieldWidget textFieldWidget = new TextFieldWidget("value", stringModel); + - if (config.getString("size") != null) { + if (config.getString("size") != null) { - widget.setSize(config.getString("size")); + textFieldWidget.setSize(config.getString("size")); - } - if (config.getString("maxlength") != null) { + } + if (config.getString("maxlength") != null) { - widget.setMaxlength(config.getString("maxlength")); + textFieldWidget.setMaxlength(config.getString("maxlength")); - } + } - add(widget); + + add(textFieldWidget); + } + break; case COMPARE: final IModel baseModel = context.getService(config.getString("model.compareTo"), IModelReference.class) Index: api/src/main/java/org/hippoecm/frontend/widgets/NumberFieldWidget.java IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== --- api/src/main/java/org/hippoecm/frontend/widgets/NumberFieldWidget.java (revision ) +++ api/src/main/java/org/hippoecm/frontend/widgets/NumberFieldWidget.java (revision ) @@ -0,0 +1,46 @@ +/* + * Copyright 2016 Hippo B.V. (http://www.onehippo.com) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.hippoecm.frontend.widgets; + +import org.apache.wicket.markup.html.form.NumberTextField; +import org.apache.wicket.model.IModel; +import org.apache.wicket.util.time.Duration; + +public class NumberFieldWidget extends AjaxUpdatingWidget { + + public NumberFieldWidget(String id, IModel model) { + this(id, model, null); + } + + public NumberFieldWidget(String id, IModel model, IModel labelModel) { + this(id, model, labelModel, null); + } + + public NumberFieldWidget(String id, IModel model, IModel labelModel, Duration throttleDelay) { + super(id, model, throttleDelay); + + final NumberTextField numberField = new NumberTextField("widget", model) { + { + setFlag(FLAG_CONVERT_EMPTY_INPUT_STRING_TO_NULL, false); + } + }; + addFormField(numberField); + + if (labelModel != null) { + numberField.setLabel(labelModel); + } + } +}