NumberColumn does not accept Integer value

Issue #18 resolved
magesh waran created an issue

Thanks a lot for the team for providing such a beautiful API.

The Number column cell values in the table auto convert into double value once user enters the value. I am using tiwulfx1.2 version

Even though i configured the column as INTEGER.

I have attached the code with this issue.

Getting the below error while saving the table

java.lang.IllegalArgumentException: Cannot invoke com.finapp.model.db.Customer.setMobileno2 on bean class 'class com.finapp.model.db.Customer' - argument type mismatch - had objects of type "java.lang.Double" but expected signature "java.lang.Integer"

Comments (8)

  1. magesh waran reporter

    Hi Team,

    Found the root cause for the above issue. Please find the description below

    The Number column is initialized using default constructor even though we specify the generic type. In default constructor the class type is hard coded as Double.class.

    public NumberColumn() { this("", (Class<T>) Double.class); }

    Even though we define the generic type as Integer in controller, the cell pattern gets changed as DOUBLE.

    If I change it to INTEGER in default constructor. It is working fine. The issue is in instantiating the NumberColumn

  2. Panemu Ind repo owner

    I would suggest to use NumberColumn.setNumberType() instead of changing the default constructor.

    The number type is not automatically taken from the generic type due to Java language limitation (type erasure).

    We need the no-parameter constructor to be able to display the column in SceneBuilder.

    Thank you for using TiwulFX. We are porting it to JavaFX 8 with a bunch of new features.

  3. magesh waran reporter

    Hi,

    Thanks for the solution. It is working fine as you mentioned. I found a strange issue and i tried to find the root cause but not able to dig too much into the code base.

    For the Integer column of size 10. The UI column accepts '1234567890', but if i enter '9843906600' it accepts only till '984390660' and the last 0 is not accepted. Please find the screenshot attached. I tried inserting in DB it was working fine.number_size.JPG

  4. Panemu Ind repo owner

    That is because the max value is exceeded. If you define NumberField/Column as Integer, the the max value will be Integer.MAX_VALUE. Same thing happens for Double and Long.

    Phone number is better to use TextColumn, but you need to create a special tableCell that only accept number. The tableCell should extends BaseCell. You can modify TextColumn.TextTableCell and add logic to only accept number. Then use your modified TextTableCell as TextColumn's cellfactory.

    TiwulFX 1.2 doesn't address this problem well. This kind of customization will be handled better in TiwulFX 2 (jdk 8) that currently being developed.

  5. Log in to comment