Hello,
I feel like I am making this way more complicated than it needs to be, and I am starting to spin my wheels.
I have two fields for date
dueDate and extendedDueDate
I would like to make the dueDate field read-only if there is already a value in it on the editor screen. This would force the user to use the extendedDueDate field.
I tried to simply put this in the Java edit screen
if (dueDateField != null) {
dueDateField.setEditable(false);
extendedDueDateField.setVisible(true);
} else {
extendedDueDateField.setVisible(false);
}
This kind of worked, but would make the dueDate field read only on job creation too not allowing any values.
I then attempted using
https://doc.cuba-platform.com/manual-latest/entity_attribute_access.html
I created a new bean
and tried this code but the dueDate field is still editable.
import org.springframework.stereotype.Component;
import com.company.hermes.entity.Job;
import com.haulmont.cuba.core.app.SetupAttributeAccessHandler;
import com.haulmont.cuba.core.app.events.SetupAttributeAccessEvent;
import org.springframework.context.event.EventListener;
//@Component(JobAttributeAccessHandler.NAME)
@Component("JobAttributeAccessHandler")
public class JobAttributeAccessHandler implements SetupAttributeAccessHandler<Job> {
//public static final String NAME = "hermes_JobAttributeAccessHandler";
@Override
public boolean supports(Class clazz) {
return Job.class.isAssignableFrom(clazz);
}
@Override
public void setupAccess(SetupAttributeAccessEvent<Job> event){
Job job = event.getEntity();
if(job.getDueDate() != null){
event.addReadOnly("dueDateField");
} else {
event.addHidden("extendedDueDate");
}
}
}
What am I missing?