All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.googlecode.wicket.jquery.ui.form.slider.AjaxSlider Maven / Gradle / Ivy

/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.googlecode.wicket.jquery.ui.form.slider;

import org.apache.wicket.Component;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.core.request.handler.IPartialPageRequestHandler;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.form.FormComponentPanel;
import org.apache.wicket.markup.html.form.TextField;
import org.apache.wicket.model.IModel;

import com.googlecode.wicket.jquery.core.JQueryBehavior;
import com.googlecode.wicket.jquery.core.JQueryEvent;
import com.googlecode.wicket.jquery.core.ajax.IJQueryAjaxAware;
import com.googlecode.wicket.jquery.core.ajax.JQueryAjaxPostBehavior;
import com.googlecode.wicket.jquery.core.event.IValueChangedListener;
import com.googlecode.wicket.jquery.ui.ajax.OnChangeAjaxBehavior;
import com.googlecode.wicket.jquery.ui.ajax.OnChangeAjaxBehavior.ChangeEvent;

/**
 * Provides a jQuery slider based on a {@link FormComponentPanel}
* This ajax version will post the {@link Component}, using a {@link OnChangeAjaxBehavior}, when the 'change' javascript method is called. * * @author Sebastien Briquet - sebfz1 */ public class AjaxSlider extends Slider implements IJQueryAjaxAware, IValueChangedListener { private static final long serialVersionUID = 1L; /** * Constructor * * @param id the markup id */ public AjaxSlider(String id) { super(id); } /** * Constructor * * @param id the markup id * @param model the {@link IModel} */ public AjaxSlider(String id, IModel model) { super(id, model); } /** * Constructor * * @param id the markup id * @param model the {@link IModel} * @param label {@link Label} on which the current slide value will be displayed */ public AjaxSlider(String id, IModel model, Label label) { super(id, model, label); } /** * Constructor * * @param id the markup id * @param model the {@link IModel} * @param input the {@link TextField} that will host the value */ public AjaxSlider(String id, IModel model, TextField input) { super(id, model, input); } // Events // @Override public void onAjax(AjaxRequestTarget target, JQueryEvent event) { if (event instanceof ChangeEvent) { // In case of issue, consider copying code from AjaxFormComponentUpdatingBehavior.onEvent this.input.processInput(); this.validate(); if (this.isValid() && super.input.isValid()) { this.onValueChanged(target); } else { this.onError(target); } } } @Override public void onValueChanged(IPartialPageRequestHandler handler) { // noop } /** * Triggered when the validation failed (ie, not input provided) * * @param target the {@link AjaxRequestTarget} */ protected void onError(AjaxRequestTarget target) { // noop } // IJQueryWidget // @Override public JQueryBehavior newWidgetBehavior(String selector) { return new AjaxSliderBehavior(selector, this.options) { private static final long serialVersionUID = 1L; @Override public void onConfigure(Component component) { super.onConfigure(component); AjaxSlider.this.onConfigure(this); // important, should call Slider#onConfigure(JQueryBehavior) } @Override public void onAjax(AjaxRequestTarget target, JQueryEvent event) { AjaxSlider.this.onAjax(target, event); } @Override protected JQueryAjaxPostBehavior newOnChangeAjaxBehavior(IJQueryAjaxAware source) { return new OnChangeAjaxBehavior(source, AjaxSlider.this.input); } }; } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy