Can't open editor screen from URL

Hello! I have such problem:
When I add entity editor URL to notification .
Screenshot_30

I cannot open it in my application, but if I add a blank screen URL there - it works but in full screen mode.

If I click ctrl+right mouse button - it open this screen
Screenshot_32

Screenshot_29

When you click to link Unread Message you can see:

Screenshot_31

Well Iwould like to know:

-How to open screen in dialog mode?

-How can I open editor from link?

Hello @olegmps2014,

To open the screen in dialog mode, you can use ScreenBuilders Bean:

screenBuilders.screen(this)
        .withOpenMode(OpenMode.DIALOG)
        .show();

Or you can use an annotation @DialogMode(forceDialog = true) for the Screen.

To open an editor screen from link you need to use a platform navigation API:

  1. Add annotaion @Route("message") for message editor.
  2. Mapping State to URL in MessageEdit screen
@Subscribe
public void onInitEntity(InitEntityEvent<Message> event) {
    Message message = event.getEntity();
    if (message == null) {
        urlRouting.replaceState(this);
        return;
    }

    String serializedMessageId = UrlIdSerializer.serializeId(message.getId());
    urlRouting.replaceState(this, ImmutableMap.of("id", serializedMessageId));
}
  1. Handling Route Changes in MessageEdit screen
    To do this, you need to subscribe to the UrlParamsChangedEvent. Event sent when browser URL parameters corresponding to opened screen are changed. It is fired before the screen is shown, which enables to do some preparatory work.
@Subscribe
public void onUrlParamsChanged(UrlParamsChangedEvent event) {
    String serializedMessageId = event.getParams().get("id");
    UUID messageId = (UUID) UrlIdSerializer.deserializeId(UUID.class, serializedMessageId);
    Message editMessage = dataManager.load(Message.class).id(messageId).one();
    setEntityToEdit(editMessage);
}

Regards,
Gleb

2 Likes

Hello, Gleb! Thanks so much for your reply

Unfortunately, it didn’t help me to solve the problem with opening editor screen

I created a button for testing
Screenshot_34
Screenshot_33
Which drops notification with link on it clicked
Screenshot_35

and when I follow this link, there is no result
Also I follow your advice
Screenshot_37

@olegmps2014, could you send a test project with the above example or the screen controller code?

Here the test project

decoder.zip (73.0 KB)

The DataManager attempts to load the entity with id = “new” and throws an IllegalStateException. Add a check for new elements in the onUrlParamsChanged method:

    @Subscribe
    private void onUrlParamsChanged(UrlParamsChangedEvent event) {
        String serializedCustomerId = event.getParams().get("id");
        if (!"new".equals(serializedCustomerId)) {
            UUID customerId = (UUID) UrlIdSerializer.deserializeId(UUID.class, serializedCustomerId);
            Customer editCustomer = dataManager.load(Customer.class).id(customerId).one();
            setEntityToEdit(editCustomer);
        }
    }

Regards,
Gleb

@durygin Thank for your answer

And I have one more question - How can I open the entity I need in editor with URL?

I know, we should paste entity ID to URL, but I read at Documenton: " Identifiers of the UUID type are encoded as Base32 Crockford Encoding, all other types are used as is."

But this ID is not Base32:

And in the System information we have one more entity ID :

Regards, Oleg Slepov

You can generate a route using RouteGenerator:

  1. getEditorRoute(Entity entity) – generates a route for default editor with the given entity;
String route = urlRouting.getRouteGenerator().getEditorRoute(entity);
  1. getEditorRoute(Entity entity, Class<? extends Screen> screenClass) – generates a route for editor with the given screenClass and entity.
String route = urlRouting.getRouteGenerator().getEditorRoute(entity, EntityEdit.class);

You can also find an example of use in the documentation.

Regards,
Gleb

@durygin Thanks, Gleb
I’ve fixed all problems with links)

Regards,Oleg Slepov