Hello Everyone
I have found a situation, that I believe needs improvement.
Operating System: macOS Big Sur 11.1
Browser: Safari Version 14.0.2 (16610.3.7.1.9)
File System: Case-Sensitive Journaled HFS+ (APFS)
Datebase: MySQL 8.0.19
CUBA Platform version: 7.2.11
CUBA Studio plugin version: 14.3-193
IntelliJ version: CUBA Studio 2019.3
Use Case: I need to present an Anonymous user with the possibility to change the locale before the Login dialog is displayed.
My application presents the Anonymous user with a SideMenu and an initial ExtMainScreen (analog to the cuba-petclinic-social-login-master demo). The ExtMainScreen currently contains a BrowserFrame that displays my static HTML pages that are stored in a resource path and the http://localhost:8080/app/VAADIN directory as described in the documentation at Opening Static Resources in Browser - CUBA Platform. Developer’s Manual.
The Anonymous user must be able to select his/her locale before opening the Login dialog (that contains the locale lookup field) so that the SideMenu changes its language immediately and so that I can also load the proper language-dependent static HTML page(s) into the BrowserFrame at the same time, thereby synchronized with the SideMenu language. Any other UI components in the ExtMainScreen should also receive their new language.
Problem: I can allow access to the SettingsWindow for the Anonymous user but the SettingsWindow.java code automatically disables the language “appLangField” if “cuba.localeSelectVisible = true” in web-app.properties for the Login dialog. Here is the code:
boolean langFieldVisible = !globalConfig.getLocaleSelectVisible();
languageLabel.setVisible(langFieldVisible);
appLangField.setVisible(langFieldVisible);
Please see: cuba/SettingsWindow.java at a9f54fbbf4cb9a381fe6ce38c5d44c5326d6694f · cuba-platform/cuba · GitHub
Therefore, an Anonymous user can only change his locale in the Login dialog when logging into the application but not beforehand and not afterward either; after the Anonymous user has logged in, the langFieldVisible is still not visible.
My workaround for this is situation is the following:
public class ExtSettingsWindow extends SettingsWindow {
@Inject
private Screens screens;
@Inject
private DefaultApp defaultApp;
@Override
public void init(Map<String, Object> params) {
super.init(params);
languageLabel.setVisible(true);
appLangField.setVisible(true);
appLangField.setNullOptionVisible(false);
appLangField.addValueChangeListener(e -> {
defaultApp.setLocale(LocaleUtils.toLocale(appLangField.getValue()));
});
okBtn.addClickListener(e -> {
screens.create(ExtMainScreen.class, OpenMode.ROOT).show();
});
}
}
This workaround allows the Anonymous user to set the locale and also reload my main screen, thereby updating the SideMenu and my static HTML page dependent upon the locale during the ExtMainScreen init(), all before opening the Login dialog. And once the user has logged in, it allows the user to update the SideMenu and everything else without logging out and back in. In the default implementation, without the Anonymous user access enabled, the user can set the locale but this does not update the language anywhere; a new login is required.
(Maybe I should have used the “cuba.web.initialScreenId” instead of hardcoding the screen class.) Anyway…
In my opinion, this is a normal use case and should not require such a workaround. An Anonymous user must be able to change the locale before logging into the application. My voodoo should not be necessary.
Can you please consider improving this implementation?
In a final note, while I was looking into different ways of refreshing my ExtMainScreen I found this bit of documentation that I’m sure is incorrect…
https://doc.cuba-platform.com/manual-7.2/webBrowserTools.html
webBrowserTools.showWebPage(“https://cuba-platform.com”, ParamsMap.of(“_target”, “blank"));
should be…
webBrowserTools.showWebPage(“https://cuba-platform.com”, ParamsMap.of(“target”, “_blank"));
as is discussed in this post:
I hope that all of this information can be of help to everyone.
Best regards
Chris