Implementing javascript events to Wicket

房东的猫 提交于 2019-12-01 09:36:44

问题


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?

All help greatly appreciated!

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

}

回答1:


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.

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()))));

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



来源:https://stackoverflow.com/questions/5212537/implementing-javascript-events-to-wicket

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!