开发者

Working with JQWicket's AjaxSlider

Once again I'm gonna show my noobiness by asking about the basics. This follow-up question is related to thread: Accessing javascript (Jquery) variables from Apache Wicket

I started to work with the AjaxSlider example, I have the value send back to me, but how do I render the slider component again with other parameters? I would like to change the maximum value that can be assigned to that AjaxSlider. Is there an api somewhere about this?

[the object for me is to create a label wit开发者_运维百科h percentages (from 0 to 100) and two sliders with which you can distribute the percentage as you please. E.g. let the user distribute money among men and women] This is the code I'm working with currently:

 add(new AjaxSlider("ajaxSlider1") {
    private static final long serialVersionUID = 1L;

    @Override
    public void onValueChanged(AjaxRequestTarget target, int newValue) {

        System.out.println("selected_value: "+newValue);

    }
});

The original example can be found here: AjaxSliderExample

Appreciate all the help and thank you for reading this far!


You have to access the underlying jqwicket's SliderBehavior from within the onValueChanged(..) method (e.g. create a getter for the SliderBehavior in the AjaxSlider or make it protected). After this you can change the maximum value of the slider like this:

@Override
public void onValueChanged(AjaxRequestTarget target, int newValue) {
   this.sliderBehavior.option(target, "'max'", "10");
}

In this way you can manipulate all available slider options (see jqwicket's SliderOptions class or original JQuery UI Slider documentation).

Note! You can alternatively inherit jqwicket's predefined SliderWebMarkupContainer to achieve the same result.


I'm not familiar with AjaxSlider, however if an Ajax request wants to re-render any component, the component has to be added to the AjaxRequestTarget.

(A restriction on this is that only components with markup ids can be redrawn by an Ajax request. This means that you have to call setOutputMarkupId( true ) on these components when you create them.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜