Hi,
How can we do a logout in mainview’s controller ?
Thnkx
Hello,
if you go to Jmix - User Interface - Views - main, you will find MainView.java controller and main-view.xml descriptor. In the xml descriptor, there is the logoutButton button, with assigned action “logout”.
So if you want, you can have another button somewhere else, having the same action.
If you want to call the logout action programatically, based on some logic, then you need to implement the logic in the MainView.java.
To start go to MainView.java, press Inject button in the IDE, under Actions select logoutAction as shown on this picture:
and then something like this
@Route("")
@ViewController("pcl_MainView")
@ViewDescriptor("main-view.xml")
public class MainView extends StandardMainView {
//Example 1 Injected with Inject button
@ViewComponent
private LogoutAction logout;
//Example 2 added manually
private LogoutAction logoutAction;
void customLogoutLogicExample1 (String howveryyesno) {
if (howveryyesno != null) {
if (howveryyesno.equals("logout")) {
logout.execute();
}
}
}
void customLogoutLogicExample2 (String howveryyesno) {
if (howveryyesno != null) {
if (howveryyesno.equals("logout")) {
logoutAction.execute();
}
}
}
}
The key was to use LogoutAction, either by getting it from descriptor or defining manually.
Kind regards,
Mladen