muhammadsyamil
(Muhammad Syamil Muhammad Zamzuri )
#1
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.
albudarov
(Alexander Budarov)
#2
Hi,
- 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;
- Inject the CheckBox to the screen controller by using Studio’s actions.
- Assign the value via the
myCheckBox.setValue(valuefromdb);
The code can be performed in the “BeforeShowEvent” event handler of the screen controller.