Announcement

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

    IntegerItem return null for zero lead values

    Create a IntegerItem field:
    Code:
    private final IntegerItem maximumPasswordAge = new IntegerItem();
    enter value like 001, 01 and so on.
    Try to get the value as Integer:
    Code:
    Integer value = maximumPasswordAge.getValueAsInteger();
    The returned value is null. I created the fix:
    Code:
        /**
             * Ensure that none of the IntegerItem fields returns null from the getValueAsInteger - this can be the case if
             * the number has leading zeros for example: 001 will returns null, not 1.
             *
             * [USER="45788"]param[/USER] field to process the int
             * @return integer evaluated by parsing
             */
            private Integer getIntegerFromIntegerItem( final IntegerItem field ) {
    
                Integer result = field.getValueAsInteger();
                if ( result == null ) {
                  [B]  String stringValue = field.getValueAsString();[/B]
                    try {
                        [B]result = Integer.parseInt( stringValue );[/B]
                        if ( result != null ) {
                            // do not leave value which can not be processed by the IntegerItem
                            field.setValue( result );
                        }
                    } catch ( NumberFormatException ignore ) {
                        // should never be here, because the function invoked after validation
                        result = null;
                    }
                }
    
                return result;
            }
    
    
    Integer value = getIntegerFromIntegerItem(maximumPasswordAge);
    This fixes the issue, but I think this should be fixed in the sgwt code.

    SmartClient Version: v10.1p_2016-08-05/PowerEdition Deployment (built 2016-08-05)
    Last edited by aafros; 2 Sep 2016, 09:44.

    #2
    Thanks for the notification. This is no longer an issue in more recent branches of SmartClient (11.0 / 11.1), where the value is automatically parsed to an integer value and redisplayed without the leading zero on blur.
    We're looking at back-porting that behavior to the 10.1 branch and will follow up here when we have that change complete (likely Monday or Tuesday of next week).

    Regards
    Isomorphic Software

    Comment


      #3
      This change has now been ported back to the 10.1 branch. Please try the next nightly build (dated Sep 7 or above) to get the fix.

      Regards
      Isomorphic Software

      Comment

      Working...
      X