Tabnine Logo
CustomNumberEditor
Code IndexAdd Tabnine to your IDE (free)

How to use
CustomNumberEditor
in
org.springframework.beans.propertyeditors

Best Java code snippets using org.springframework.beans.propertyeditors.CustomNumberEditor (Showing top 20 results out of 315)

origin: spring-projects/spring-framework

  @Override
  public void registerCustomEditors(PropertyEditorRegistry registry) {
    registry.registerCustomEditor(Number.class, new CustomNumberEditor(Integer.class, false));
  }
});
origin: spring-projects/spring-framework

@Test
public void testCustomNumberEditor() {
  CustomNumberEditor editor = new CustomNumberEditor(Integer.class, false);
  editor.setAsText("5");
  assertEquals(new Integer(5), editor.getValue());
  assertEquals("5", editor.getAsText());
  editor.setValue(null);
  assertEquals(null, editor.getValue());
  assertEquals("", editor.getAsText());
}
origin: spring-projects/spring-framework

@Test
public void testCustomNumberEditorWithHex() {
  CustomNumberEditor editor = new CustomNumberEditor(Integer.class, false);
  editor.setAsText("0x" + Integer.toHexString(64));
  assertEquals(new Integer(64), editor.getValue());
}
origin: spring-projects/spring-framework

@Test
public void testParseShortGreaterThanMaxValueWithoutNumberFormat() {
  try {
    CustomNumberEditor editor = new CustomNumberEditor(Short.class, true);
    editor.setAsText(String.valueOf(Short.MAX_VALUE + 1));
    fail(Short.MAX_VALUE + 1 + " is greater than max value");
  }
  catch (NumberFormatException ex) {
    // expected
  }
}
origin: spring-projects/spring-framework

/**
 * Parse the Number from the given text, using the specified NumberFormat.
 */
@Override
public void setAsText(String text) throws IllegalArgumentException {
  if (this.allowEmpty && !StringUtils.hasText(text)) {
    // Treat empty String as null value.
    setValue(null);
  }
  else if (this.numberFormat != null) {
    // Use given NumberFormat for parsing text.
    setValue(NumberUtils.parseNumber(text, this.numberClass, this.numberFormat));
  }
  else {
    // Use default valueOf methods for parsing text.
    setValue(NumberUtils.parseNumber(text, this.numberClass));
  }
}
origin: spring-projects/spring-framework

/**
 * Format the Number as String, using the specified NumberFormat.
 */
@Override
public String getAsText() {
  Object value = getValue();
  if (value == null) {
    return "";
  }
  if (this.numberFormat != null) {
    // Use NumberFormat for rendering value.
    return this.numberFormat.format(value);
  }
  else {
    // Use toString method for rendering value.
    return value.toString();
  }
}
origin: org.springframework/spring-beans

/**
 * Parse the Number from the given text, using the specified NumberFormat.
 */
@Override
public void setAsText(String text) throws IllegalArgumentException {
  if (this.allowEmpty && !StringUtils.hasText(text)) {
    // Treat empty String as null value.
    setValue(null);
  }
  else if (this.numberFormat != null) {
    // Use given NumberFormat for parsing text.
    setValue(NumberUtils.parseNumber(text, this.numberClass, this.numberFormat));
  }
  else {
    // Use default valueOf methods for parsing text.
    setValue(NumberUtils.parseNumber(text, this.numberClass));
  }
}
origin: org.springframework/spring-beans

/**
 * Format the Number as String, using the specified NumberFormat.
 */
@Override
public String getAsText() {
  Object value = getValue();
  if (value == null) {
    return "";
  }
  if (this.numberFormat != null) {
    // Use NumberFormat for rendering value.
    return this.numberFormat.format(value);
  }
  else {
    // Use toString method for rendering value.
    return value.toString();
  }
}
origin: spring-projects/spring-framework

  @Override
  public void registerCustomEditors(PropertyEditorRegistry registry) {
    registry.registerCustomEditor(Number.class, new CustomNumberEditor(Integer.class, false));
  }
});
origin: spring-projects/spring-framework

@Test
public void testCustomNumberEditorWithEmptyAsNull() {
  CustomNumberEditor editor = new CustomNumberEditor(Integer.class, true);
  editor.setAsText("5");
  assertEquals(new Integer(5), editor.getValue());
  assertEquals("5", editor.getAsText());
  editor.setAsText("");
  assertEquals(null, editor.getValue());
  assertEquals("", editor.getAsText());
  editor.setValue(null);
  assertEquals(null, editor.getValue());
  assertEquals("", editor.getAsText());
}
origin: camunda/camunda-bpm-platform

/**
 * Parse the Number from the given text, using the specified NumberFormat.
 */
@Override
public void setAsText(String text) throws IllegalArgumentException {
  if (this.allowEmpty && !StringUtils.hasText(text)) {
    // Treat empty String as null value.
    setValue(null);
  }
  else if (this.numberFormat != null) {
    // Use given NumberFormat for parsing text.
    setValue(NumberUtils.parseNumber(text, this.numberClass, this.numberFormat));
  }
  else {
    // Use default valueOf methods for parsing text.
    setValue(NumberUtils.parseNumber(text, this.numberClass));
  }
}
origin: camunda/camunda-bpm-platform

/**
 * Format the Number as String, using the specified NumberFormat.
 */
@Override
public String getAsText() {
  Object value = getValue();
  if (value == null) {
    return "";
  }
  if (this.numberFormat != null) {
    // Use NumberFormat for rendering value.
    return this.numberFormat.format(value);
  }
  else {
    // Use toString method for rendering value.
    return value.toString();
  }
}
origin: spring-projects/spring-framework

  @Override
  public void registerCustomEditors(PropertyEditorRegistry registry) {
    NumberFormat nf = NumberFormat.getInstance(Locale.GERMAN);
    registry.registerCustomEditor(Float.class, new CustomNumberEditor(Float.class, nf, true));
  }
});
origin: org.tinygroup/org.tinygroup.jdbctemplatedslsession

@Override
public void setValue(Object value) {
  if (allowEmpty && value == null) {
    super.setValue(DEFAULT.get(numberClass));
  } else {
    super.setValue(value);
  }
}
origin: springframework/spring-beans

/**
 * Format the Number as String, using the specified NumberFormat.
 */
public String getAsText() {
  Object value = getValue();
  if (value == null) {
    return "";
  }
  if (this.numberFormat != null) {
    // Use NumberFormat for rendering value.
    return this.numberFormat.format(value);
  }
  else {
    // Use toString method for rendering value.
    return value.toString();
  }
}
origin: spring-projects/spring-framework

  @Override
  public void registerCustomEditors(PropertyEditorRegistry registry) {
    NumberFormat nf = NumberFormat.getInstance(Locale.GERMAN);
    registry.registerCustomEditor(Float.class, new CustomNumberEditor(Float.class, nf, true));
  }
});
origin: springframework/spring-beans

/**
 * Parse the Number from the given text, using the specified NumberFormat.
 */
public void setAsText(String text) throws IllegalArgumentException {
  if (this.allowEmpty && !StringUtils.hasText(text)) {
    // Treat empty String as null value.
    setValue(null);
  }
  else if (this.numberFormat != null) {
    // Use given NumberFormat for parsing text.
    setValue(NumberUtils.parseNumber(text, this.numberClass, this.numberFormat));
  }
  else {
    // Use default valueOf methods for parsing text.
    setValue(NumberUtils.parseNumber(text, this.numberClass));
  }
}
origin: apache/servicemix-bundles

/**
 * Format the Number as String, using the specified NumberFormat.
 */
@Override
public String getAsText() {
  Object value = getValue();
  if (value == null) {
    return "";
  }
  if (this.numberFormat != null) {
    // Use NumberFormat for rendering value.
    return this.numberFormat.format(value);
  }
  else {
    // Use toString method for rendering value.
    return value.toString();
  }
}
origin: spring-projects/spring-framework

this.defaultEditors.put(byte.class, new CustomNumberEditor(Byte.class, false));
this.defaultEditors.put(Byte.class, new CustomNumberEditor(Byte.class, true));
this.defaultEditors.put(short.class, new CustomNumberEditor(Short.class, false));
this.defaultEditors.put(Short.class, new CustomNumberEditor(Short.class, true));
this.defaultEditors.put(int.class, new CustomNumberEditor(Integer.class, false));
this.defaultEditors.put(Integer.class, new CustomNumberEditor(Integer.class, true));
this.defaultEditors.put(long.class, new CustomNumberEditor(Long.class, false));
this.defaultEditors.put(Long.class, new CustomNumberEditor(Long.class, true));
this.defaultEditors.put(float.class, new CustomNumberEditor(Float.class, false));
this.defaultEditors.put(Float.class, new CustomNumberEditor(Float.class, true));
this.defaultEditors.put(double.class, new CustomNumberEditor(Double.class, false));
this.defaultEditors.put(Double.class, new CustomNumberEditor(Double.class, true));
this.defaultEditors.put(BigDecimal.class, new CustomNumberEditor(BigDecimal.class, true));
this.defaultEditors.put(BigInteger.class, new CustomNumberEditor(BigInteger.class, true));
origin: apache/servicemix-bundles

/**
 * Parse the Number from the given text, using the specified NumberFormat.
 */
@Override
public void setAsText(String text) throws IllegalArgumentException {
  if (this.allowEmpty && !StringUtils.hasText(text)) {
    // Treat empty String as null value.
    setValue(null);
  }
  else if (this.numberFormat != null) {
    // Use given NumberFormat for parsing text.
    setValue(NumberUtils.parseNumber(text, this.numberClass, this.numberFormat));
  }
  else {
    // Use default valueOf methods for parsing text.
    setValue(NumberUtils.parseNumber(text, this.numberClass));
  }
}
org.springframework.beans.propertyeditorsCustomNumberEditor

Javadoc

Property editor for any Number subclass such as Short, Integer, Long, BigInteger, Float, Double, BigDecimal. Can use a given NumberFormat for (locale-specific) parsing and rendering, or alternatively the default decode / valueOf / toString methods.

This is not meant to be used as system PropertyEditor but rather as locale-specific number editor within custom controller code, parsing user-entered number strings into Number properties of beans and rendering them in the UI form.

In web MVC code, this editor will typically be registered with binder.registerCustomEditor calls.

Most used methods

  • <init>
    Create a new CustomNumberEditor instance, using the default valueOf methods for parsing and toString
  • getValue
  • setValue
    Coerce a Number value into the required target class, if necessary.
  • getAsText
    Format the Number as String, using the specified NumberFormat.
  • setAsText
    Parse the Number from the given text, using the specified NumberFormat.

Popular in Java

  • Updating database using SQL prepared statement
  • getSystemService (Context)
  • getSharedPreferences (Context)
  • setScale (BigDecimal)
  • Font (java.awt)
    The Font class represents fonts, which are used to render text in a visible way. A font provides the
  • HttpURLConnection (java.net)
    An URLConnection for HTTP (RFC 2616 [http://tools.ietf.org/html/rfc2616]) used to send and receive d
  • Notification (javax.management)
  • Response (javax.ws.rs.core)
    Defines the contract between a returned instance and the runtime when an application needs to provid
  • Base64 (org.apache.commons.codec.binary)
    Provides Base64 encoding and decoding as defined by RFC 2045.This class implements section 6.8. Base
  • FileUtils (org.apache.commons.io)
    General file manipulation utilities. Facilities are provided in the following areas: * writing to a
  • Top 17 Free Sublime Text Plugins
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimAtomGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyStudentsTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now