View action from browse


I need add to browse new action which show edit window in view mode.
In this mode all fields are no editable. That would be lovely to create this action to all browse. Is there any way to simple create this functionality.



You can define an additional global action that extends EditAction, for example, something like this:

public class ReadOnlyViewAction extends EditAction {

    public static final String ACTION_ID = "readOnlyView";

    public ReadOnlyViewAction(ListComponent target) {

    public ReadOnlyViewAction(ListComponent target, WindowManager.OpenType openType) {
        super(target, WindowManager.OpenType.DIALOG);

    public ReadOnlyViewAction(ListComponent target, WindowManager.OpenType openType, String id) {
        super(target, WindowManager.OpenType.DIALOG, ACTION_ID);

    public void setCaption(String caption) {
        super.setCaption("Read-only View");

    public void actionPerform(Component component) {
        setWindowParams(ParamsMap.of("isReadOnly", true));

Next, you can extend AbstractEditor and add some logic for disabling editable components, for example:

public class ReadOnlyOptionEditor<Y extends StandardEntity> extends AbstractEditor {

    private boolean isReadOnly = false;

    public void init(Map<String, Object> params) {
        if (params.get("isReadOnly") != null)
            isReadOnly = (boolean) params.get("isReadOnly");

    public void ready() {
        if (isReadOnly) {
            for (Component component : getOwnComponents()) {
                if (component instanceof Editable) {
                    ((Editable) component).setEditable(false);

Now make the editor screens of your entities extend the new custom editor, for example:

public class CustomerEdit extends ReadOnlyOptionEditor<Customer> {

Finally, in the entity’s browser screen, add the new action to the table:

    public void init(Map<String, Object> params) {
        customersTable.addAction(new ReadOnlyViewAction(customersTable, WindowManager.OpenType.DIALOG, ReadOnlyViewAction.ACTION_ID));

Not very straightforward, but at least you don’t need to create an action in each screen controller individually. (86.9 KB)


Thanks to you for complet example. I done a little modification and set component enabled in edit controller by method setEnabled(false) like below

protected void postInit() {
	if (viewmode)

Now I have other problem. The vertical scrollbar in inner browse is disable.


Is there any way change this feature ? I need enabled scrollbar in this component when component enabled parametr set false.

You cannot enable the scrollbar separately. In fact, you don’t even need to apply setEnabled(false) to the whole table. I would recommend to disable only table actions, thus the data will remain readable (not light-grey as in disabled mode), you will have your scrollbar, but the user will not be able to modify the data. Of course, this requires more complex logic than in my demo sample.

I have last question. I add this action to browse action panel by code

Button viewButton = componentsFactory.createComponent(Button.class);
				ViewAction va = new ViewAction(table, OpenType.DIALOG);
				va.setCaption(messages.getMessage("com.haulmont.cuba.gui.components", "view"));
				viewButton.setCaption(messages.getMessage("com.haulmont.cuba.gui.components", "view"));

Now I’d like add shortcut. I done it in ViewAction

	public void setShortcut(String shortcut) {

but this method invoke doesn’t work in my case.

This method is not invoked by the framework. Call it explicitly like va.setShortcut("CTRL-ENTER") after creation of the action or in its constructor.

I invoke this method after create action, but this way doesn’t work.