Passing an Informational Message to a Wicket Page Using PageParameters

Can Wicket allow both of the following parameters to be passed to the PageParameters object? Apparently not?

  • accountId which shown in URL ( /account/<ID> )
  • infoMessage parameter not displayed in URL (bookmarkable)

I am currently using IndexedHybridUrlCodingStrategy for the page in question, and just trying the "0" and "infoMessage" parameters throw this exception:

WicketMessage: not all parameters have been encoded. Make sure that all parameter names are integers in sequential order starting from zero. Names of the current parameters: [0, infoMessage]

If I change the parameter name "infoMessage" to "1", it works, but it gives an ugly URL (in this case something like /account/42/Tosite%20108207%20tallennettiin.5 ), which is not what I want.


Now the obvious answer might be that infoMessage should not be in PageParameters . But the fact is, I tried to add it as a regular constructor parameter, for example:

 public AccountPage(PageParameters parameters, String infoMessage) { // ... } 

But this approach is not suitable in one important use case. After you delete the persistent Record object associated with the account, the following: does not load the account correctly (the deleted account is still displayed). This code is executed in onClick () of AjaxFallbackLink.

 setResponsePage(new AccountPage(AccountPage.pageParameters(account), message)); 

On the other hand, my original approach ...

 setResponsePage(AccountPage.class, AccountPage.pageParameters(account)); 

... works great because it somehow loads the AccountPage “more thoroughly”, but again, I don't know how easy it is to pass the infoMessage parameter.

( AccountPage.pageParameters() above is a simple static utility for creating the corresponding PageParameters with "0" = account identifier. The AccountPage constructor always loads the account with saving using the identifier.)

Any ideas? Perhaps using AjaxFallbackLink partially causes the problem?

Use of the gate 1.4.

+2
source share
1 answer

From what I see in your question, you are trying to display a bookmark page and display a feedback message to the user (most likely in the FeedbackPanel ), but you do not want this message to be part of the URL.

What you want to do is tell Session that you have an informational message, and let the feedback panel process the message.

 @Override void onSubmit() { ... save object ... getSession().info("Object ... has been saved"); setResponsePage(ObjectPage.class, new PageParameters("id="+object.getId())); } 

In this case, you tell Wicket to temporarily store the message in the session until it is displayed by the feedback panel. This idiom is also known as flash messaging.

You cannot use both PageParameters and another parameter as constructor arguments, because Wicket cannot create an instance of a page with such a constructor when requesting a page. Wicket knows how to instantiate pages with standard constructors or pages with the PageParameters parameter.

+4
source

Source: https://habr.com/ru/post/890784/


All Articles