Hello! I have such problem:
When I add entity editor URL to notification .
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
When you click to link Unread Message you can see:
Well Iwould like to know:
-How to open screen in dialog mode?
-How can I open editor from link?
durygin
(Gleb Durygin)
January 10, 2020, 6:41pm
#3
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 :
Add annotaion @Route("message")
for message editor.
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));
}
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
Which drops notification with link on it clicked
and when I follow this link, there is no result
Also I follow your advice
durygin
(Gleb Durygin)
January 13, 2020, 10:04am
#6
@olegmps2014 , could you send a test project with the above example or the screen controller code?
durygin
(Gleb Durygin)
January 13, 2020, 4:15pm
#8
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
durygin
(Gleb Durygin)
January 15, 2020, 8:38am
#10
You can generate a route using RouteGenerator
:
getEditorRoute(Entity entity)
– generates a route for default editor with the given entity
;
String route = urlRouting.getRouteGenerator().getEditorRoute(entity);
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