问题描述
Wicket是否以某种方式允许在PageParameters对象中传递以下两种参数?显然不是吗?
Does Wicket somehow allow passing both of the following kinds of params in a PageParameters object? Apparently not?
- 网址(
-
accountId
-
infoMessage
参数,该参数未显示在(可标记的)URL中
/account/<ID>
)中显示 的accountId
which is shown in the URL (/account/<ID>
)infoMessage
parameter which is not shown in the (bookmarkable) URL
我当前正在使用有问题的页面的IndexedHybridUrlCodingStrategy,仅尝试参数"0"和"infoMessage"就会出现此异常:
I'm currently using IndexedHybridUrlCodingStrategy for the page in question, and simply trying parameters "0" and "infoMessage" gives this exception:
如果我将"infoMessage"参数名称更改为"1",它可以工作,但是会产生一个丑陋的URL(在本例中为/account/42/Tosite%20108207%20tallennettiin.5
之类的东西),这不是我想要的.
If I change "infoMessage" parameter name into "1", it works, but yields an ugly URL (in this case something like /account/42/Tosite%20108207%20tallennettiin.5
) which is not what I want.
现在,最明显的答案可能是 infoMessage不应出现在PageParameters 中.但事实是,我尝试将其添加为普通的构造函数参数,如下所示:
Now, the obvious answer perhaps is that infoMessage shouldn't be in PageParameters. But thing is, I tried adding it as normal constructor parameter instead, like so:
public AccountPage(PageParameters parameters, String infoMessage) {
// ...
}
但是这种方法在一个重要的用例中失败了.删除与帐户相关的永久性记录"对象后,以下操作不不会正确加载AccountPage(删除的记录仍然可见).该代码在AjaxFallbackLink的onClick()中执行.
But this approach fails in one important use case. After deleting a persistent "Record" object related to the Account, the following does not load the AccountPage properly (the deleted record is still visible). This code is executed in onClick() of an AjaxFallbackLink.
setResponsePage(new AccountPage(AccountPage.pageParameters(account), message));
另一方面,我的原始方法...
On the other hand, my original approach...
setResponsePage(AccountPage.class, AccountPage.pageParameters(account));
...工作正常,因为它以某种方式更彻底"地加载了AccountPage,但是同样,我也不知道如何干净地传递infoMessage参数.
... works fine, as it somehow loads the AccountPage "more thoroughly", but, again, I don't know how to pass the infoMessage parameter cleanly.
(上面的AccountPage.pageParameters()
是一个简单的静态实用程序,用于使用"0" =帐户ID创建适当的PageParameters.AccountPage构造函数始终使用ID从持久性中加载帐户.)
(AccountPage.pageParameters()
above is a simple static utility for creating appropriate PageParameters with "0" = account id. The AccountPage constructor always loads the account from persistence using the ID.)
有什么想法吗?也许部分使用AjaxFallbackLink会导致问题?
Any ideas? Perhaps using AjaxFallbackLink partially causes the problem?
使用Wicket 1.4.
Using Wicket 1.4.
推荐答案
根据我在问题中看到的内容,您尝试同时呈现可书签页面并向用户显示反馈消息(很可能在FeedbackPanel
中) ,但您不希望该消息成为URL的一部分.
From what I see in your question, you try to render both a bookmarkable page and show a feedback message to the user (most probably in a FeedbackPanel
), but you don't want that message to be part of the URL.
您要做的是告诉Session
您有一条参考消息,然后让反馈面板处理该消息.
What you want to do is tell the Session
that you have an informational message, and let the feedback panel handle the message.
@Override void onSubmit() {
... save object ...
getSession().info("Object ... has been saved");
setResponsePage(ObjectPage.class, new PageParameters("id="+object.getId()));
}
在这种情况下,您告诉Wicket将消息临时存储在会话中,直到消息被反馈面板呈现为止.这个习语也称为即插即用消息".
In this case you tell Wicket to temporarily store a message in the session, until it gets rendered by a feedback panel. This idiom is also known as "flash messages".
不能同时使用PageParameters
和另一个参数作为构造函数参数,因为在请求页面时,Wicket不能使用这种构造函数创建页面实例. Wicket只知道如何实例化具有默认构造函数的页面或具有PageParameters
参数的页面.
You can't use both PageParameters
and another parameter as constructor arguments, because Wicket can't create your page instance with such a constructor when the page is requested. Wicket only knows how to instantiate pages with default constructors or pages with a PageParameters
parameter.
这篇关于使用PageParameters时将信息消息传递到Wicket页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!