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

com.databasesandlife.util.wicket.AskUserForLatitudeLongitudePanel Maven / Gradle / Ivy

There is a newer version: 21.0.1
Show newest version
package com.databasesandlife.util.wicket;

import org.apache.wicket.markup.html.form.Button;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.form.TextField;
import org.apache.wicket.markup.html.panel.Panel;
import org.apache.wicket.model.LambdaModel;
import org.apache.wicket.model.PropertyModel;

/** 
 * Asks the user for latitude and longitude via the HTML5 Geolocation API.
 *    

* To use: *

    *
  1. Include JQuery in your page *
  2. Put a <wicket:container> on your page somewhere, which is this panel (everything in this panel is "display:none") *
  3. Override isVisible and make this panel invisible (= will not be rendered) if you know the user's geo location * (otherwise this panel will submit again the geolocation, i.e. infinite loop.) *
  4. The user loads your page, this widget determines the location (if the user allows) and submits a form, * this widget calls your {@link LatitudeLongitudeListener}. *
* * @author This source is copyright Adrian Smith and licensed under the LGPL 3. * @see Project on GitHub */ @SuppressWarnings("serial") public class AskUserForLatitudeLongitudePanel extends Panel { public interface LatitudeLongitudeListener { public void latitudeLongitudeWasDetermined(double latitude, double longitude); } protected double latitude, longitude; public AskUserForLatitudeLongitudePanel(String wicketId, final LatitudeLongitudeListener listener) { super(wicketId); var form = new Form<>("form"); add(form); form.add(new TextField<>("latitude", LambdaModel.of(() -> latitude))); form.add(new TextField<>("longitude", LambdaModel.of(() -> longitude))); form.add(new Button("submit") { @Override public void onSubmit() { listener.latitudeLongitudeWasDetermined(latitude, longitude); } }); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy