package org.apache.wicket.examples.ajax.builtin;
import java.util.Arrays;
import java.util.List;
import java.util.Locale;
import org.apache.wicket.extensions.ajax.markup.html.AjaxEditableChoiceLabel;
import org.apache.wicket.extensions.ajax.markup.html.AjaxEditableLabel;
import org.apache.wicket.extensions.ajax.markup.html.AjaxEditableMultiLineLabel;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.link.Link;
import org.apache.wicket.model.CompoundPropertyModel;
import org.apache.wicket.util.convert.ConversionException;
import org.apache.wicket.util.convert.IConverter;
@link
@author
public class EditableLabelPage extends BasePage
{
private static final List<String> SITES = Arrays.asList("The Server Side", "Java Lobby",
"Java.Net");
private String site = SITES.get(0);
private String text1 = "fox";
private String text2 = "dog";
private String text3 = "multiple\nlines of\ntextual content";
private int number = 42;
private int refreshCounter = 0;
public EditableLabelPage()
{
Form form = new Form<>("form", new CompoundPropertyModel<>(this));
add(form);
form.add(new AjaxEditableLabel("text1"));
form.add(new AjaxEditableLabel("text2"));
form.add(new AjaxEditableMultiLineLabel("text3"));
form.add(new AjaxEditableChoiceLabel<>("site", SITES));
form.add(new AjaxEditableLabel<Integer>("number") {
@Override
protected IConverter<?> createConverter(Class<?> type)
{
return new IConverter<Integer>() {
@Override
public Integer convertToObject(String value, Locale locale)
throws ConversionException
{
return Integer.parseInt(value);
}
@Override
public String convertToString(Integer value, Locale locale)
{
return String.format("%010d", value);
}
};
}
});
form.add(new Label("refresh-counter", () -> "" + refreshCounter));
form.add(new Link<Void>("refresh-link")
{
@Override
public void onClick()
{
refreshCounter++;
}
});
}
@return
public String getText1()
{
return text1;
}
@return
public String getText2()
{
return text2;
}
@return
public String getText3()
{
return text3;
}
@param
public void setText1(String text1)
{
this.text1 = text1;
}
@param
public void setText2(String text2)
{
this.text2 = text2;
}
@param
public void setText3(String text3)
{
this.text3 = text3;
}
@return
public String getSite()
{
return site;
}
@param
public void setSite(String site)
{
this.site = site;
}
}