you can simply write logic in sling model, below is the sample code. please check if this helps you.
public class Sample {
@ValueMapValue
@Deleted Account
private String flag; //checkbox name
@ValueMapValue
@Deleted Account
private String title;
@ScriptVariable
private Page currentPage;
@PostConstruct
public void init() {
try{
if (flag !=null && flag.equals("true")){
title = currentPage.getTitle();
}
}catch (Exception e){
log.error("Exception Sling Model :{}", e.getMessage());
}
}
}