Results 1 to 9 of 9

Thread: Format of Integer, BigDecimal in forms

  1. #1
    Join Date
    Feb 2007
    Posts
    13

    Default Format of Integer, BigDecimal in forms

    Hi, in my form I use BigDecimal's and Integer's. When the user inputs values, they look like this: '100000'. When they re-open the form, after persisting, they get them in the way of '100 000', with the whitespace in the middle.

    How do I change this behaviour ? SwingBinderSelectionStrategy? Any one got an example ? Thx!

  2. #2
    Join Date
    Mar 2007
    Location
    Oudenaarde
    Posts
    294

    Default

    By default, Spring RCP will use a simple text binder for Numbers. However, there's a NumberBinder you can use. By default, it's enabled for BigDecimals, but you can specify the specific Number type. With that binder you can:
    - specify the format
    - specify the number of decimals
    - set left or right decoration (currency sign for example)
    - enable/disable negative numbers

    for example:

    Code:
    <bean id="euroBinder" class="org.springframework.richclient.form.binding.swing.NumberBinder" lazy-init="true">
            <property name="format" value="###,###,###,##0.00"/>
            <property name="nrOfDecimals" value="2"/>
            <property name="leftDecoration" value="€"/>
        </bean>
    You can then use that binder in the formbuilders, or set it as the default for a type through the SwingBinderSelectionStrategy.
    MSN: PM me please
    Skype: doclo_lieven

    Spring Rich Client Project Lead

  3. #3
    Join Date
    Feb 2007
    Posts
    13

    Default

    Yes! That was exactly what I needed

  4. #4
    Join Date
    Sep 2009
    Posts
    1

    Default

    Quote Originally Posted by LievenDoclo View Post
    You can then use that binder in the formbuilders, or set it as the default for a type through the SwingBinderSelectionStrategy.
    Is there any way to use these custom binders to format values in JTables?

  5. #5
    Join Date
    Mar 2007
    Location
    Oudenaarde
    Posts
    294

    Default

    For that, you'll need to create a TableCellRenderer
    MSN: PM me please
    Skype: doclo_lieven

    Spring Rich Client Project Lead

  6. #6
    Join Date
    Aug 2009
    Posts
    25

    Default

    Can anyone provide/make a little tutorial on how to do this?
    I am trying to implement this with the SwingBinderSelectionStrategy:

    Code:
    <bean id="binderSelectionStrategy" depends-on="serviceLocator"
     class="org.springframework.richclient.form.binding.swing.SwingBinderSelectionStrategy">
        <property name="bindersForPropertyTypes">
          <map>
          	<entry>
              <key>
                <value type="java.lang.Class">java.math.BigDecimal</value>
              </key>
              <bean class="org.springframework.richclient.form.binding.swing.NumberBinder" lazy-init="true">
    		    <property name="format" value="###########0"/>
    		    <property name="nrOfDecimals" value="0"/>
    		  	<property name="leftDecoration" value="E"/>
    		  </bean>
            </entry>
        </property>
    </bean>
    But somehow this fails. Am I missing something

    Many thanks

  7. #7
    Join Date
    Mar 2007
    Location
    Oudenaarde
    Posts
    294

    Default

    Can you tell me how it fails?

    Quote Originally Posted by XuOne View Post
    Can anyone provide/make a little tutorial on how to do this?
    I am trying to implement this with the SwingBinderSelectionStrategy:

    Code:
    <bean id="binderSelectionStrategy" depends-on="serviceLocator"
     class="org.springframework.richclient.form.binding.swing.SwingBinderSelectionStrategy">
        <property name="bindersForPropertyTypes">
          <map>
          	<entry>
              <key>
                <value type="java.lang.Class">java.math.BigDecimal</value>
              </key>
              <bean class="org.springframework.richclient.form.binding.swing.NumberBinder" lazy-init="true">
    		    <property name="format" value="###########0"/>
    		    <property name="nrOfDecimals" value="0"/>
    		  	<property name="leftDecoration" value="E"/>
    		  </bean>
            </entry>
        </property>
    </bean>
    But somehow this fails. Am I missing something

    Many thanks
    MSN: PM me please
    Skype: doclo_lieven

    Spring Rich Client Project Lead

  8. #8
    Join Date
    Aug 2009
    Posts
    25

    Default

    Quote Originally Posted by LievenDoclo View Post
    Can you tell me how it fails?
    Well the form is still showing the Integer or the Double with a thousand sign or decimal sign.

    Form - Enter field (Integer) with the value: 3333333
    Save/persist
    Refresh
    Form - Field shows: 3,333,333

  9. #9
    Join Date
    Aug 2009
    Posts
    25

    Default

    Quote Originally Posted by XuOne View Post
    Well the form is still showing the Integer or the Double with a thousand sign or decimal sign.

    Form - Enter field (Integer) with the value: 3333333
    Save/persist
    Refresh
    Form - Field shows: 3,333,333
    I changed one of my field into a BigDecimal. After that, it was picked up correctly by the SwingBinderSelectionStrategy in my xml file. When entering a comma or a point, it is always represented as a point decimal separator (which is good).

    For my integers/long it seems I need to have a converter... as it can't convert from source Integer to target BigDecimal

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •