Working with JQWicket's AjaxSlider

末鹿安然 提交于 2019-12-13 05:40:20

问题


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 with 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!


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/5165191/working-with-jqwickets-ajaxslider

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