Check checkboxes if value is present in a database

Hi everyone,

I want to do if value is present in a database the checkbox will stay checked. If the value is not exist, the checkbox will stay unchecked.

my pseudo code will be something like this:

((valuefromdb.exist()==true))?checkbox.checked==true:checkbox.checked==false;

How to do this in CUBA. Please help me & Thanks in advanced.

Hi,

  1. Use DataManager to execute query in the database: DataManager - CUBA Platform. Developer’s Manual

E.g.

long count = dataManager.loadValue(
        "select count(u) from sec$User u where u.login = 'admin'", Long.class)
         .one();
boolean valuefromdb = count > 0;
  1. Inject the CheckBox to the screen controller by using Studio’s actions.
  2. Assign the value via the myCheckBox.setValue(valuefromdb);

The code can be performed in the “BeforeShowEvent” event handler of the screen controller.