Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Actually Vaadin behaves correctly, but it follows the magnitude rules (already mentioned by Yogendra Singh) please see an <a href="http://demo.vaadin.com/book-examples/book/?restartApplication#component.table.binding.editorform" rel="nofollow noreferrer">example</a></p> <p><img src="https://i.stack.imgur.com/4rOoB.png" alt="enter image description here"></p> <p>Please also check the following:</p> <pre class="lang-java prettyprint-override"><code> float value1 = 12.0f; float value2 = 123123123; BeanItem&lt;Float&gt; item1 = new BeanItem&lt;Float&gt;(value1); BeanItem&lt;Float&gt; item2 = new BeanItem&lt;Float&gt;(value2); System.out.println(" result 1: " + item1.getBean()); System.out.println(" result 2: " + item2.getBean()); </code></pre> <p>Result:</p> <pre><code>result 1: 12.0 result 2: 1.2312312E8 </code></pre> <p>So the correct solution (as I can see it) looks like the following:</p> <ol> <li>Define your own Bean. There is no reason to have a BeanItem wrapping a float value.</li> <li>Define your PropertyFormatter (<a href="http://demo.vaadin.com/book-examples/book/1_10/" rel="nofollow noreferrer">example</a>)</li> <li>Important to note, the one should not return a String instead of the correct data type. It will affect editing, validation, etc.</li> </ol> <p>PropertyFormatter example:</p> <pre class="lang-java prettyprint-override"><code>/** Integer formatter that accepts empty values. */ public class LenientIntegerFormatter extends PropertyFormatter { public LenientIntegerFormatter(Property propertyDataSource) { setPropertyDataSource(propertyDataSource); } @Override public Object parse(String formattedValue) throws Exception { if ("".equals(formattedValue)) return null; else return Integer.valueOf(formattedValue); } @Override public String format(Object value) { if (value == null) return ""; return ((Integer) value).toString(); } @Override public Class&lt;?&gt; getType() { return String.class; } } </code></pre> <p>It may look a little bit scary, but this is the cost of flexibility. Custom Bean allows to use table view, forms, etc without any significant changes. Basically, this is the data model behind Vaadin UI.</p> <p><img src="https://i.stack.imgur.com/Iitor.png" alt="enter image description here"></p> <p><a href="https://vaadin.com/book/-/page/datamodel.html" rel="nofollow noreferrer">Chapter 9. Binding Components to Data</a></p> <p>Custom Bean example:</p> <pre class="lang-java prettyprint-override"><code>public class Bean implements Serializable { String name; float value; public Bean(String name, float newValue) { this.name = name; this.value = newValue; } public String getName() { return name; } public void setName(String name) { this.name = name; } public float getValue() { return value; } public void setValue(float newValue) { this.value = newValue; } } </code></pre> <p>Just to provide all required insights:</p> <pre class="lang-java prettyprint-override"><code> Bean bean = new Bean("Test", value1); BeanItem&lt;Bean&gt; beanItem = new BeanItem&lt;Bean&gt;(bean); for(Object propertyId: beanItem.getItemPropertyIds()) { System.out.println(" Property: '" + propertyId + "' value: " + beanItem.getItemProperty(propertyId)); } </code></pre> <p>Will print:</p> <pre><code>Property: 'name' value: Test Property: 'value' value: 12.0 </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload