com.databasesandlife.util.wicket.AskUserForLatitudeLongitudePanel Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of java-common Show documentation
Show all versions of java-common Show documentation
Utility classes developed at Adrian Smith Software (A.S.S.)
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:
*
* - Include JQuery in your page
*
- Put a <wicket:container> on your page somewhere, which is this panel (everything in this panel is "display:none")
*
- 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.)
*
- 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);
}
});
}
}