Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    Bug with SpinnerItem

    I have create SpinnerItem:
    Code:
    SpinnerItem spinner = new SpinnerItem();
    	spinner.setName("fieldName");
    	spinner.setDataPath("fieldName");
    	spinner.setMin(0.0);
    	spinner.setMax(50.0);
    	spinner.setStep(0.1f);
    	spinner.setDefaultValue(1.0f);
    and later I setup value

    Code:
    	Float value = 2.2;
    	FormItem field = styleForm.getField("fieldName");
    	if (field != null) {
    		field.setValue(value);
    	}
    And on screen i see value: 2.200000047683716
    If I click up or down i see 2.300000047683716 or
    2.100000047683716 accordingly.
    How I can limit quantity of deduced signs after a comma?
    But if I save again value from DynamicForm I receive 2.2 again.
    Also How I can see step not 1.0 but 1.00000000xxxxxxx in this case...

    #2
    Do you see this in development only or even in web mode? If you want a faster response, always post a minimal but complete standalone testcase with an onModuleLoad() rather than snippets of code.

    Sanjiv

    Comment


      #3
      An example of using SpinnerItem without DataSource

      Code:
      package mytest.client;
      
      import java.math.BigDecimal;
      import java.util.Map;
      import com.google.gwt.core.client.EntryPoint;
      import com.google.gwt.core.client.GWT;
      import com.smartgwt.client.data.Record;
      import com.smartgwt.client.widgets.form.DynamicForm;
      import com.smartgwt.client.widgets.form.fields.SpinnerItem;
      import com.smartgwt.client.widgets.form.fields.events.ChangedEvent;
      import com.smartgwt.client.widgets.form.fields.events.ChangedHandler;
      
      /**
       * Entry point classes define <code>onModuleLoad()</code>.
       */
      public class Testsgwt implements EntryPoint {
      
          /**
           * This is the entry point method.
           */
          public void onModuleLoad() {
      
              final DynamicForm styleForm = new DynamicForm();
              SpinnerItem spinner = new SpinnerItem();
              spinner.setName("fieldName");
              spinner.setMin(-50.0d);
              spinner.setMax(50.0d);
              spinner.setStep(0.1d);
              styleForm.setFields(spinner);
      
              /*
               * Sets the value.
               */
              Double setValue = new Double(12.1d);
              Record record = new Record();
      
              // Using String here also can work.
              record.setAttribute("fieldName", setValue);
      
              styleForm.editRecord(record);
      
              spinner.addChangedHandler(new ChangedHandler() {
      
                  @Override
                  public void onChanged(ChangedEvent event) {
      
                      /*
                       * Gets the value.
                       */
                      Double returnValue = null;
      
                      Map<String, Object> valueMap = styleForm.getValues();
                      Object tempVal = valueMap.get("fieldName");
                      if (tempVal instanceof Float) {
                          returnValue = new Double((Float) tempVal);
                          GWT.log("Instance of Float.");
                      } else if (tempVal instanceof Integer) {
                          returnValue = new Double((Integer) tempVal);
                          GWT.log("Instance of Integer.");
                      } else if (tempVal instanceof Double) {
                          returnValue = (Double) tempVal;
                          GWT.log("Instance of Double.");
                      }
      
                      GWT.log("Before round up: " + returnValue.toString());
      
                      // GWT-Math is used. See [url]http://code.google.com/p/gwt-math/[/url]
                      int decimalPlace = 2;
                      BigDecimal tempValue = new BigDecimal(returnValue);
                      BigDecimal roundedValue = tempValue.setScale(decimalPlace,
                              BigDecimal.ROUND_HALF_UP);
                      Double roundedReturnValue = roundedValue.doubleValue();
                      GWT.log("After round up: " + roundedReturnValue.toString());
                  }
              });
      
              styleForm.draw();
      
          }
      }
      Last edited by valueman; 12 Jun 2010, 08:29.

      Comment


        #4
        valueman,

        did you get your problem solved? I have the exact same issue and need a solution. (I might try your gwt-math bit if nothing else works...)
        Last edited by tdk; 14 Jul 2011, 22:53.

        Comment


          #5
          looks like it works in Production mode, kinda strange tho'...

          Comment

          Working...
          X