Editor ReadOnly Mode

I have been looking for this feature for a while now. Something similar to the Readonly role.
In my application I have a lot of entities that cannot be modified after they reached a certain “status”.
In CUBA 6 I just disabled the the fieldgroups, and all the detail(nested) table actions, which is a lot of work, because you also have disable the detail table edit screens.

Here is one simple universal solution for CUBA7:

Screen XML with standard window actions and one additional button: closeNoCommitBtn

<hbox id="editActions" spacing="true">
	<button id="windowCommitAndCloseBtn" action="windowCommitAndClose"/>
	<button id="windowCommitBtn" action="windowCommit"/>
	<button id="windowCloseBtn" action="windowClose"/>
	<button id="closeNoCommitBtn" caption="Close" icon="font-icon:CLOSE" invoke="onCloseNoCommitBtnClick"/>


private Button windowCommitBtn, windowCloseBtn, windowCommitAndCloseBtn, closeNoCommitBtn;

private void onBeforeShow(BeforeShowEvent event) {

 * Close the window without changes
public void onCloseNoCommitBtnClick() {

 * Override preventUnsavedChanges. This prevents the framweork from asking to save changes.
 * This is necessary because, if the user uses the close X of the tab, the framework asks to save changes.
 * @param event
protected void preventUnsavedChanges(BeforeCloseEvent event) {
	if (this.isUpdateAllowed()) { // Some function to check entity fields if update is allowed
		super.preventUnsavedChanges(event); // Call super method to work like normal
	// else do nothing

 * Enable disable edit based on the status
private void disableEdit(boolean updateAllowed) {
	if (!updateAllowed) {
		// Hide the standard window buttons
		// Disable the actions to prevent user from using shortcut CTRL+ENTER to save.
	// Disable/enable close without commit button
	closeNoCommitBtn.setVisible(!updateAllowed); // Only show this button when update is not allowed

I was looking into the code of preventUnsavedChanges and it calls a function isCheckForUnsavedChanges(). It would be nice if this was a setting you could turn on/off in the editor screen.
It would be even nicer if ReadOnly was a standard feature you could turn on for Editor Screens.

The reason I can’t do this wit security constraints, is there are still some actions you can do with the entity that are invoked through a button that does make ‘controlled’ changes to the entity.

Anyone have any other ideas?


1 Like

I agree, that having ReadOnly mode for editor screen out-of-the-box would be a good thing.

Comparing to your solution, I would like to have not only actions hidden and disabled, but also controls (fields, etc…) disabled.

Seems like an approach in MasterDetailScreen can be reused. I’ll try and post here later


apparently this is on the roadmap for CUBA 7.2 as documented in this issue: https://github.com/cuba-platform/cuba/issues/2270

Implementation seems to be in progress / done already, so there is a chance this is covered in the next minor version.


1 Like

Looking forward to this feature !


Since 7.2 is release, can anyone direct me to an example on how this can be used?

Thank you.


you can look it up from the Petclinic example. It is implemented in the Owner Editor: https://demo10.cuba-platform.com/petclinic/#main/1/owners

owner-browse: https://github.com/cuba-platform/cuba-petclinic/blob/master/modules/web/src/com/haulmont/sample/petclinic/web/owner/owner/owner-browse.xml#L32

owner-edit: https://github.com/cuba-platform/cuba-petclinic/blob/master/modules/web/src/com/haulmont/sample/petclinic/web/owner/owner/owner-edit.xml#L54


Hi Mario,

Thanks for the response.
I have taken a look at the examples that you have given.
However, it seems that the Edit screen is disabled by being triggered from the browse screen.

What if I wanted to directly go to an Edit screen disable it without a browse screen?
Do you have any experience with this case.

Once again, thank you

Hi Mario,

It’s ok. I resolve this using :
public void onInit(InitEvent event) {