This website uses cookies for visitor traffic analysis. By using the website, you agree with storing the cookies on your computer.More information

Mask part of value returned from DB

General questions regarding the development with JVx.

Mask part of value returned from DB

Postby reversedr » Mon Sep 16, 2019 10:20 am

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
reversedr
 
Posts: 35
Joined: Tue Oct 23, 2018 11:03 am

Re: Mask part of value returned from DB

Postby Support@SIB » Mon Sep 16, 2019 1:17 pm

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?
User avatar
Support@SIB
 
Posts: 353
Joined: Mon Sep 28, 2009 1:56 pm

Re: Mask part of value returned from DB

Postby reversedr » Mon Sep 16, 2019 4:53 pm

The grid is readonly, no editor for this column.

Thank you
reversedr
 
Posts: 35
Joined: Tue Oct 23, 2018 11:03 am

Re: Mask part of value returned from DB

Postby Support@SIB » Tue Sep 17, 2019 2:22 pm

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.
User avatar
Support@SIB
 
Posts: 353
Joined: Mon Sep 28, 2009 1:56 pm

Re: Mask part of value returned from DB

Postby reversedr » Tue Sep 17, 2019 4:22 pm

Thanks for you help! :)
reversedr
 
Posts: 35
Joined: Tue Oct 23, 2018 11:03 am


Return to Development