Permalink
Browse files

Use the new HTML5 input types from Wicket core

git-svn-id: file:///home/igor/dev/stuff/svnbackup/trunk@5687 ef7698a4-5110-0410-9fc6-c7eb3693863f
  • Loading branch information...
Martin Grigorov
Martin Grigorov committed Dec 20, 2010
1 parent c73d7cb commit 589a14b855a607c2fda0e8db00bc997e98d743b9
@@ -2,13 +2,15 @@
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.form.Form;
+import org.apache.wicket.markup.html.form.NumberTextField;
import org.apache.wicket.markup.html.panel.FeedbackPanel;
import org.apache.wicket.model.PropertyModel;
import org.apache.wicket.request.mapper.parameter.PageParameters;
import org.wicketstuff.html5.BasePage;
public class NumberFieldDemo extends BasePage {
+ @SuppressWarnings("unused")
private Double d;
public NumberFieldDemo(PageParameters parameters) {
@@ -20,7 +22,10 @@ public NumberFieldDemo(PageParameters parameters) {
Form<Void> form = new Form<Void>("form");
add(form);
- form.add(new NumberField("number", new PropertyModel<Double>(this, "d")));
+ NumberTextField numberField = new NumberTextField("number", new PropertyModel<Double>(this, "d"));
+ numberField.setRequired(false);
+ form.add(numberField);
+ numberField.setMinimum(4.0d);
add(new Label("numberLabel", new PropertyModel<Double>(this, "d")));
}
@@ -8,7 +8,7 @@ <h1>Range input</h1>
<article>
<form wicket:id="form">
- <input wicket:id="range" type="range" onchange="console.log(this.value)" />
+ <input wicket:id="range" type="range" onchange="console.log(this.value)" step="0.5" />
</form>
<summary>Range is set to: <span wicket:id="rangeLabel"></span></summary>
@@ -2,39 +2,33 @@
import java.io.Serializable;
-import org.apache.wicket.Component;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.ajax.form.AjaxFormComponentUpdatingBehavior;
-import org.apache.wicket.markup.html.IHeaderResponse;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.form.Form;
+import org.apache.wicket.markup.html.form.RangeTextField;
import org.apache.wicket.model.CompoundPropertyModel;
import org.apache.wicket.model.Model;
-import org.apache.wicket.request.resource.CompressedResourceReference;
import org.apache.wicket.util.time.Duration;
import org.wicketstuff.html5.BasePage;
public class RangeTextFieldDemo extends BasePage {
- private static final CompressedResourceReference WICKET_AJAX_HTML5_JS =
- new CompressedResourceReference(RangeTextFieldDemo.class, "wicket-ajax-html5.js");
-
private final Pojo pojo;
public RangeTextFieldDemo() {
this.pojo = new Pojo();
- pojo.range = 2.0d;
+ pojo.range = 2.3d;
Form<Pojo> form = new Form<Pojo>("form", new CompoundPropertyModel<Pojo>(pojo));
add(form);
RangeTextField rangeTextField = new RangeTextField("range");
form.add(rangeTextField);
- rangeTextField.setMinimum(0.0d);
+ rangeTextField.setMinimum(1.4d);
rangeTextField.setMaximum(10.0d);
- rangeTextField.setStep(0.5d);
final Label rangeLabel = new Label("rangeLabel", new Model<String>(pojo.range.toString()));
rangeLabel.setOutputMarkupId(true);
@@ -48,12 +42,6 @@ protected void onUpdate(AjaxRequestTarget target) {
rangeLabel.setDefaultModelObject(pojo.range.toString());
target.add(rangeLabel);
}
-
- public void renderHead(Component c, IHeaderResponse response) {
- super.renderHead(c, response);
- // override Wicket.Form.serializeInput so that input[type=range] is serialized too
- response.renderJavaScriptReference(WICKET_AJAX_HTML5_JS);
- }
}.setThrottleDelay(Duration.milliseconds(500)));
}
@@ -9,7 +9,7 @@ <h1>Number input</h1>
<div wicket:id="feedback"></div>
<form wicket:id="form">
- <input wicket:id="number" type="number" min="3.0" max="10.0" onchange="console.log(this.value)" /><br/>
+ <input wicket:id="number" required type="number" min="3.0" max="10.0" onchange="console.log(this.value)" /><br/>
<input type="submit" value="Submit"/>
</form>
@@ -1,61 +0,0 @@
-package org.wicketstuff.html5.markup.html.form;
-
-import org.apache.wicket.markup.html.MarkupUtil;
-import org.apache.wicket.markup.html.form.TextField;
-import org.apache.wicket.model.IModel;
-import org.apache.wicket.util.value.ValueMap;
-import org.apache.wicket.validation.validator.RangeValidator;
-
-public class NumberField extends TextField<Double> {
-
- private static final long serialVersionUID = 1L;
-
- /**
- * @param id
- * See Component
- */
- public NumberField(final String id)
- {
- super(id);
- setType(Double.class);
- }
-
- /**
- * @param id
- * @param model
- * @see org.apache.wicket.Component#Component(String, IModel)
- */
- public NumberField(final String id, final IModel<Double> model)
- {
- super(id, model);
- setType(Double.class);
- }
-
- @Override
- protected void onInitialize() {
- super.onInitialize();
-
- if (MarkupUtil.isMarkupHtml5Compliant(this)) {
-
- ValueMap attributes = getMarkupAttributes();
- Double min = attributes.getAsDouble("min");
- Double max = attributes.getAsDouble("max");
-
- if (min == null) {
- min = Double.MIN_VALUE;
- }
-
- if (max == null) {
- max = Double.MAX_VALUE;
- }
-
- add(new RangeValidator<Double>(min, max));
- }
- }
-
- @Override
- protected final String getInputType()
- {
- return "number";
- }
-}
@@ -1,112 +0,0 @@
-package org.wicketstuff.html5.markup.html.form;
-
-import org.apache.wicket.markup.ComponentTag;
-import org.apache.wicket.markup.html.form.TextField;
-import org.apache.wicket.model.IModel;
-
-public class RangeTextField extends TextField<Double> {
-
- private static final long serialVersionUID = 1L;
-
- private Double minimum;
-
- private Double maximum;
-
- private Double step;
-
- /**
- * @see org.apache.wicket.Component#Component(String)
- */
- public RangeTextField(final String id)
- {
- this(id, null);
- }
-
- /**
- * @param id
- * @param model
- * @see org.apache.wicket.Component#Component(String, IModel)
- */
- public RangeTextField(final String id, IModel<Double> model)
- {
- super(id, model);
- setRequired(true);
- setType(Double.class);
- }
-
- /**
- * Processes the component tag.
- *
- * @param tag
- * Tag to modify
- * @see org.apache.wicket.Component#onComponentTag(ComponentTag)
- */
- @Override
- protected void onComponentTag(final ComponentTag tag)
- {
- super.onComponentTag(tag);
-
- if (minimum != null) {
- tag.put("min", minimum.toString());
- }
-
- if (maximum != null) {
- tag.put("max", maximum.toString());
- }
-
- if (step != null) {
- tag.put("step", step.toString());
- }
- }
-
- /**
- * @see org.apache.wicket.markup.html.form.TextField#getInputType()
- */
- @Override
- protected String getInputType()
- {
- return "range";
- }
-
- /**
- * @return the minimum
- */
- public Double getMinimum() {
- return minimum;
- }
-
- /**
- * @return the maximum
- */
- public Double getMaximum() {
- return maximum;
- }
-
- /**
- * @return the step
- */
- public Double getStep() {
- return step;
- }
-
- /**
- * @param minimum the minimum to set
- */
- public void setMinimum(Double minimum) {
- this.minimum = minimum;
- }
-
- /**
- * @param maximum the maximum to set
- */
- public void setMaximum(Double maximum) {
- this.maximum = maximum;
- }
-
- /**
- * @param step the step to set
- */
- public void setStep(Double step) {
- this.step = step;
- }
-}

0 comments on commit 589a14b

Please sign in to comment.