为 Wicket 实现 javascript 事件 [英] Implementing javascript events to Wicket

查看:23
本文介绍了为 Wicket 实现 javascript 事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 ria-development 的新手,并且正在使用 Ajax 滑块示例.我不知道如何使用 javascript 事件.在此示例中,onValueChanged 事件是预先实现的.如何实现说 onchange- 或 onSlider-event?

I'm new to ria-development and working with the Ajax Slider example. I can't figure out how to work with javascript events. Here in the example the onValueChanged-event is preimplemented. How do I implement say onchange- or onSlider-event?

非常感谢所有帮助!

public abstract class AjaxSlider extends WebMarkupContainer {

    private static final long serialVersionUID = 1L;

    public AjaxSlider(String id) {
            super(id);
            super.setOutputMarkupId(true);
    }
    public JQUIComponentBehaivor<SliderOptions> getSlideBehaviors() {
        List behaviors = getBehaviors();
        for(Object behavior : behaviors){
            if(behavior instanceof SliderBehavior)
                        return (SliderBehavior) behavior;
        }
        return null;
    }


    public abstract void onValueChanged(AjaxRequestTarget target,
                    int newValue);

    @Override
    protected void onInitialize() {
            super.onInitialize();
            AbstractDefaultAjaxBehavior ajaxBehavior =
                new AbstractDefaultAjaxBehavior() {
                    private static final long serialVersionUID = 1L;

                    @Override
                    protected void respond(AjaxRequestTarget target) {
                            String sliderValue = RequestCycle.get().getRequest()
                                            .getParameter("sv");
                            if (Utils.isNotBlank(sliderValue)) {
                                    onValueChanged(target, Integer.valueOf(sliderValue));
                            }
                    }
            };
            super.add(ajaxBehavior);
            super.add(new SliderBehavior(new SliderOptions()
                            .changeEvent(wicketAjaxGet(
                                            ajaxBehavior,
                                            new MapBuilder<String, Object>().add("sv",
                                                            js("ui.value")).build()))));
    }

}

推荐答案

您给出的示例为更改事件添加了一个事件处理程序.这个事件处理程序所做的是向上面定义的 ajaxBehavior 发出 GET 请求.然后该行为从 GET 参数中提取滑块值并调用 onValueChanged.

The example you gave adds an event handler for the change event. What this event handler does is issueing a GET request to the ajaxBehaviordefined above. The behavior then extracts the slider value from the GET parameters and calls onValueChanged.

您可以像这样向 SliderOptions 添加另一个事件处理程序.例如:

You can add another event handler just like this to SliderOptions. For instance:

.slideEvent(
    wicketAjaxGet(ajaxBehavior,
                  new MapBuilder<String, Object>()
                  .add("sv",  js("ui.value")).build()))));

此处理程序应在用户移动滑块时调用 ajax 行为.

This handler should call the ajax behavior any time the user moves the slider.

这篇关于为 Wicket 实现 javascript 事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆