Directory

← Back

numberfield7

Modification of TextField for only number input

Author

Rating

Popularity

<100

This is addon modification of TextField, which accepts only number input and has configuration:

  1. Minimum value. If value this property != null - validates value for minimum;
  2. Maximum value If value of this property != null - validates value for maximum;
  3. Method getDoubleValue returns null, if string value is invalid number;
  4. Character of decimal separator. Default = '.';
  5. Decimal length. Default = 0;
  6. Character of grouping separator. Default = space;
  7. Is signed. Default = true;
  8. Is use grouping. Default = false;

Sample code

package by.kod.numberfield.test;

import javax.servlet.annotation.WebServlet;

import by.kod.numberfield.NumberField;

import com.vaadin.annotations.VaadinServletConfiguration;
import com.vaadin.server.VaadinRequest;
import com.vaadin.server.VaadinServlet;
import com.vaadin.ui.Button;
import com.vaadin.ui.Button.ClickEvent;
import com.vaadin.ui.Table;
import com.vaadin.ui.UI;
import com.vaadin.ui.VerticalLayout;

/**
 * UI class for testing number field
 * 
 * @author Kerim O.D.
 *
 */
@SuppressWarnings("serial")
public class NumberFieldTestUI extends UI {
	private static final String PAGE_TITLE = "Test Simple Number Field";
	private static final String TEXT_VALUE = "Text value";
	private static final String DOUBLE_VALUE = "Double value";

	/**
	 * Servlet
	 *
	 */
	@WebServlet(value = "/*", asyncSupported = true)
	@VaadinServletConfiguration(productionMode = false, ui = NumberFieldTestUI.class, widgetset = "by.kod.numberfield.NumberFieldWidgetSet")
	public static class Servlet extends VaadinServlet {
	}
	// next row id for add
	private int nextRowId;

	@Override
	protected void init(VaadinRequest request) {
		// init content layout
		final VerticalLayout content = new VerticalLayout();
		content.setMargin(true);
		content.setSpacing(true);
		setContent(content);
		// init number field for test
		final NumberField field = new NumberField();
		field.setWidth(300, Unit.PIXELS);
		field.setDoubleValue(50000d);
		content.addComponent(field);
		// init table representing textual value and converted double value
		final Table table = new Table();
		table.addContainerProperty(TEXT_VALUE, String.class, null);
		table.addContainerProperty(DOUBLE_VALUE, Double.class, null);
		table.setWidth(300, Unit.PIXELS);
		table.setHeight(400, Unit.PIXELS);
		Button button = new Button("Click Me");
		button.addClickListener(new Button.ClickListener() {
			public void buttonClick(ClickEvent event) {
				if (field.isValid()) {
					table.addItem(
							new Object[] { field.getValue(),
									field.getDoubleValue() }, nextRowId++);
				}
			}
		});
		content.addComponent(button);
		content.addComponent(table);
		// setting page title
		getPage().setTitle(PAGE_TITLE);
	}

}

Compatibility

(Loading compatibility data...)

Was this helpful? Need more help?
Leave a comment or a question below. You can also join the chat on Discord or ask questions on StackOverflow.

Version

Released
2014-07-11
Maturity
EXPERIMENTAL
License
Apache License 2.0

Compatibility

Framework
Vaadin 7.2
Browser
Browser Independent

numberfield7 - Vaadin Add-on Directory

Modification of TextField for only number input numberfield7 - Vaadin Add-on Directory
This is addon modification of TextField, which accepts only number input and has configuration: 1. Minimum value. If value this property != null - validates value for minimum; 2. Maximum value If value of this property != null - validates value for maximum; 3. Method getDoubleValue returns null, if string value is invalid number; 4. Character of decimal separator. Default = '.'; 5. Decimal length. Default = 0; 6. Character of grouping separator. Default = space; 7. Is signed. Default = true; 8. Is use grouping. Default = false;
Online