1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
|
import java.util.TimeZone;
import org.apache.wicket.ajax.AbstractAjaxTimerBehavior;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.ajax.form.AjaxFormValidatingBehavior;
import org.apache.wicket.ajax.markup.html.form.AjaxButton;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.model.PropertyModel;
import org.apache.wicket.util.time.Duration;
import com.ac.api.error.ServerException;
public class WorldClockPage extends BasePage
{
String nom= "test";
public void setNom(String nom) {
this.nom = nom;
}
public String getNom() throws ServerException {
nom+=nom;
return nom;
}
@SuppressWarnings("serial")
public WorldClockPage()
{
// create clock components for different timezones
final Clock la = new Clock("la", TimeZone.getTimeZone("America/Los_Angeles"));
final Clock ny = new Clock("ny", TimeZone.getTimeZone("America/New_York"));
final Clock moscow = new Clock("moscow", TimeZone.getTimeZone("Europe/Moscow"));
final Clock prague = new Clock("prague", TimeZone.getTimeZone("Europe/Prague"));
final Clock london = new Clock("london", TimeZone.getTimeZone("Europe/London"));
// make components print out id attrs so they can be updated via ajax
la.setOutputMarkupId(true);
ny.setOutputMarkupId(true);
moscow.setOutputMarkupId(true);
prague.setOutputMarkupId(true);
london.setOutputMarkupId(true);
// add the components to the container and add a markup id setter to
// each component.
add(la);
add(ny);
add(moscow);
add(prague);
add(london);
final Label nomText = new Label("nomText", new PropertyModel<String>(this, "nom"));
// add the timer behavior to the page and make it update all
// other components as well
add(new AbstractAjaxTimerBehavior(Duration.seconds(1))
{
/**
* @see org.apache.wicket.ajax.AbstractAjaxTimerBehavior#onTimer(org.apache.wicket.ajax.AjaxRequestTarget)
*/
protected void onTimer(AjaxRequestTarget target)
{
target.addComponent(la);
target.addComponent(ny);
target.addComponent(moscow);
target.addComponent(prague);
target.addComponent(london);
}
});
nomText.setOutputMarkupId(true);
Form form = new Form("ficheForm");
// attach an ajax validation behavior to all form component's onkeyup
// event and throttle it down to once per second
AjaxFormValidatingBehavior.addToAllFormComponents(form, "onkeyup", Duration.ONE_SECOND);
// add a button that can be used to submit the form via ajax
form.add(new AjaxButton("ajax-button", form)
{
@Override
protected void onSubmit(AjaxRequestTarget target, Form<?> form)
{
// repaint the feedback panel so that it is hidden
target.addComponent(nomText);
}
});
form.add(nomText);
add(form);
}
} |
Partager