Page 1 of 1

Mask part of value returned from DB

PostPosted: Mon Sep 16, 2019 10:20 am
by reversedr
Hello!

I have a screen with a grid that is populated from the DB.

The grid has a column that shows values, i want to mask part of the value.

For example:
the value is: 123456789
want to see it as ******789

Is it possible ?
how do i do it ?

Thank You

Re: Mask part of value returned from DB

PostPosted: Mon Sep 16, 2019 1:17 pm
by Support@SIB
Should the value be read-only or do you have an editor for this column?
and if, should the editor show the masked value or the original value?

Re: Mask part of value returned from DB

PostPosted: Mon Sep 16, 2019 4:53 pm
by reversedr
The grid is readonly, no editor for this column.

Thank you

Re: Mask part of value returned from DB

PostPosted: Tue Sep 17, 2019 2:22 pm
by Support@SIB
You have different options:

  • Use a view for fetching data
  • Add a virtual column to your select statement, via DBStorage

    Syntax: [ Download ] [ Hide ]
    storage.setAdditionalQueryColumns(new String[] {"1234 as pin_code_hidden"});

    This requires a db function to change the pin. This method is db (in)dependent, but works great.
  • Use the calculate row event

    Syntax: [ Download ] [ Hide ]
    storage.getMetaData().addColumnMetaData(new ColumnMetaData("PIN_CODE_HIDDEN"));
    storage.eventCalculateRow().addListener(this, "doCalculate");

    public void doCalculate(StorageEvent pEvent)
    {
            IBean bnNew = pEvent.getNew();
            bnNew.put("PIN_CODE_HIDDEN", hide(bnNew.get("PIN_CODE")));
    }

    private Object hide(Object pValue)
    {
            if (pValue == null)
            {
                    return null;
            }
           
            String value = pValue.toString();
           
            return StringUtil.lpad(value.substring(value.length() - 3), 10, '*');
    }

Simple hide the orignal column if you want. With all options it's possible to use an editor for the original column.

Re: Mask part of value returned from DB

PostPosted: Tue Sep 17, 2019 4:22 pm
by reversedr
Thanks for you help! :)