Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
550 views
in Technique[技术] by (71.8m points)

javascript - Wicket 6.2 AbstractDefaultAjaxBehavior getCallbackUrl no longer resolves JS variables

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 + '";
    }
}

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Wicket Ajax has been completely rewritten for Wicket 6. See this page for a detailed description.

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");
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...