How to enable Anonymous Access to Screen in Jmix V2

Hi all,
Please I need to allow anonymous access to a screen in my Jmix v2. How does it work in Jmix v2? I can see documentation for v1 but not in v2 so I am wondering if this facility is not available in v2. Please let me know other ways to handle this.

Thanks

Hi!

The first way

You can use standard Vaadin’s mechanisms to allow anonymous access to view.
See: Securing Plain Java Applications | Advanced Security Topics | Security | Vaadin Docs

The second way

Starting with version Jmix 2.2.2, it became possible to use Jmix resource roles to provide anonymous access to views.
Check out the following issue for more information: Anonymous access to a view does not work if it's configured using resource role · Issue #3022 · jmix-framework/jmix · GitHub
You can also find a test project in the issue.

Best regards,
Dmitriy

Hi Dmitriy,
Thanks so much for your great help. I am able to access the view anonymously now. However, the view displays the side menu by the side. I want this side menu invisible so that only the view will be seen by the user. The reason for doing this anonymous access is that the view is not being rendered properly on mobile devices, and mobile rendering is very important here.

So I am thinking if I can display only the view without the side menu, there will be enough space for the view to occupy on mobile devices.

Thanks

To detach the target view from the MainView, you can simply remove dependency on layout in @Route annotation:

Before:

@Route(value = "mobile-view", layout = MainView.class)
@ViewController("MobileView")
@ViewDescriptor("mobile-view.xml")
public class MobileView extends StandardView {
    // your code
}

After:

@Route(value = "mobile-view")
@ViewController("MobileView")
@ViewDescriptor("mobile-view.xml")
@AnonymousAllowed
public class MobileView extends StandardView {
    // your code
}

I think this will be enough for the above case.

Regards,
Dmitriy

Hi Dmitriy,
Thanks so much. It works as you have suggested.
However, my problem of displaying the view properly on mobile devices is still there. I can still see that the controls are scattered. I thought hiding the menu with anonymous access would solve the problem for me.

Please, is there other things I need to know about Jmix 2.2 to display views properly on mobile devices? I understand that Jmix 2.2 is mobile-friendly. Why is my view not displaying properly on mobile devices?

Your assistance in this area will be highly appreciated.

Thanks

Unfortunately, without screenshots I don’t quite understand the problem.

Could you provide a screenshot of the actual view and describe what exactly you expect?

Hi Dmitriy,
See the screenshot here. It displays fine on the web but scattered on the mobile.
Do I need to design another view specifically to be targeted by mobile only?

My expectation on the mobile device browser is also to have the same view output as it’s obtainable on web.

Thanks

image

As I can see, you are not using the standard menu that is used in MainView.

This menu is specially adapted for mobile devices.
Responsibility is supported by the Vaadin framework.
Here is an example of displaying a view with a menu on a mobile device:
image

Here I can hide the side menu using the ToggleButton component:
image

This is an example of our online demo application: UI Samples

If you use your own MainView implementation, then you must style it for mobile devices yourself.

Hi Dmitriy,
Ok thanks for your assistance. If I understand you very well, what I need to do is to style the view for mobile.

Thanks