Wicket 6.2 AbstractDefaultAjaxBehavior getCallbackUrl 不再解析 JS 变量 [英] Wicket 6.2 AbstractDefaultAjaxBehavior getCallbackUrl no longer resolves JS variables
问题描述
最近我一直致力于将一个使用 wicket 1.4.18 的大型 Web 应用程序升级到 6.2.我们有一种情况,我们将创建 javascript 变量来跟踪拖放列表中的位置.这只是代码的检票口,因为 js 一直有效并且没有改变.
Recently I have been working on upgrading a big web application that was using wicket 1.4.18 to 6.2. We had a situation where we would create javascript variables to keep track of positioning within a drag and drop list. This is just the wicket side of the code since the js has always worked and has not been changed.
ListItem.add(new AbstractDefaultAjaxBehavior()
{
private static final long serialVersionUID = 1L;
@Override
public void onComponentTag(ComponentTag tag)
{
tag.put("ondrop", "var value = $(ui.item[0]).attr('hiddenvalue');"
+ this.getCallbackScript());
}
@Override
public final CharSequence getCallbackUrl()
{
return super.getCallbackUrl() + "&hiddenvalue' + value + '";
}
}
然而,我遇到的问题是 javascript 变量没有解析为值,现在在 getCallbackUrl 中被视为文字字符串(例如:'value' 而不是 5).这在 wicket 1.4.18 中并非如此,我不认为这个问题源于我们向 1.5.8 的迁移.
However the problem I am running into is the javascript variables are not resolving to values and are now being taken as literal strings (Ex: 'value' instead of 5) in the getCallbackUrl. This was not the case in wicket 1.4.18 and I don't believe this problem originated in our migration to 1.5.8.
最后我们只是希望能够使用
In the end we just want to be able to pull the value out using
@Override
protected void respond(AjaxRequestTarget target)
{
getRequest().getRequestParameters().getParameterValue("hiddenvalue");
}
对此有什么建议吗?我希望我提供了足够的信息.在此先感谢您的帮助.其中一些内容有点超出我的知识范围,可能会让人不知道该往哪里看.
Any advice on this? I hope I have provided enough information. Thanks in advance for any help. Some of this is a little beyond my knowledge and can be intimidating not knowing where to look.
推荐答案
Wicket Ajax 已针对 Wicket 6 完全重写.请参阅 此页面 详细说明.
Wicket Ajax has been completely rewritten for Wicket 6. See this page for a detailed description.
在您的情况下,您应该使用新的 AjaxRequestAttributes 就像这样:
In your case, you should use the new AjaxRequestAttributes like that:
@Override
protected void updateAjaxAttributes(final AjaxRequestAttributes attributes) {
super.updateAjaxAttributes(attributes);
attributes.getExtraParameters().put("hiddenvalue", "value");
}
从请求中检索值仍然像以前一样工作.
Retrieval of the value from the request still works the same as before.
@Override
protected void respond(AjaxRequestTarget target)
{
getRequest().getRequestParameters().getParameterValue("hiddenvalue");
}
这篇关于Wicket 6.2 AbstractDefaultAjaxBehavior getCallbackUrl 不再解析 JS 变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!