How to return value from AbstractWindow

Hi,

I want to create a quick window with one or two fields, and an OK and Cancel button, and then use the value of those fields after the window is closed.

I started coding as follows:


AbstractWindow window = openWindow("myScreen", OpenType.DIALOG);
    	window.addCloseListener((listener) ->{
    		
    		if (listener.equals("perform")){
    			//GET FIELD VALUES OR RETURN VALUES AND DO SOMETHING USEFUL
    		}else{
                        //DO NOTHING
    		}
    	});

How can I have access to field values, or return values from ‘myScreen’ ?

Thanks!

1 Like

Hi,

You can cast the result of the openWindow() method to the controller class of the opened screen. For example, the controller can be as follows:

public class MyScreen extends AbstractWindow {

    @Inject
    private TextField myField;

    public String getMyFieldValue() {
        return myField.getValue();
    }

    public void onOkBtnClick() {
        close("perform");
    }

    public void onCancelBtnClick() {
        close("cancel");
    }
}

Then you can invoke it and get value from it in the following way:

MyScreen myScreen = (MyScreen) openWindow("my-screen", WindowManager.OpenType.DIALOG);
myScreen.addCloseListener(actionId -> {
    if (actionId.equals("perform")) {
        String myFieldValue = myScreen.getMyFieldValue();
        showNotification("Value: " + myFieldValue);
    }
});
1 Like

Hi Konstantin,

This works great!
Thank you for your detailed reply!