对于如何解决wicket Ajax 自动提示应用中出现的乱码问题!
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.ajax.form.AjaxFormSubmitBehavior;
import org.apache.wicket.extensions.ajax.markup.html.autocomplete.AutoCompleteTextField;
import org.apache.wicket.markup.html.WebPage;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.link.BookmarkablePageLink;
import org.apache.wicket.model.CompoundPropertyModel;
import org.apache.wicket.model.PropertyModel;
import org.apache.wicket.util.string.Strings;
private String name;
private List choices=new ArrayList(10);
private String inputName="";
public List getChoices() {
return choices;
}
this.choices = choices;
}
return inputName;
}
this.inputName = inputName;
}
return name;
}
this.name = name;
}
super();
this.add(new BookmarkablePageLink("back", IndexPage.class).setAutoEnable(true));
Form form =new Form ("form",new CompoundPropertyModel(this)){
@Override
protected void onSubmit() {
super.onSubmit();
}
};
add(form);
final AutoCompleteTextField textField=new AutoCompleteTextField("ac",new PropertyModel(this,"inputName")){
@Override
protected Iterator getChoices(String input) {
if(Strings.isEmpty(input)){
return Collections.EMPTY_LIST.iterator();
}
return choices.iterator();
}
};
label.setOutputMarkupId(true);
textField.add(new AjaxFormSubmitBehavior(form,"onkeyup"){
@Override
protected void onError(AjaxRequestTarget arg0) {
// TODO Auto-generated method stub
}
@Override
protected void onSubmit(AjaxRequestTarget target) {
Locale[] locales=Locale.getAvailableLocales();
for (Locale locale : locales) {
System.out.print(locale.getDisplayCountry()+",");
}
choices.clear();
for (int i = 0; i < locales.length; i++) {
final Locale locale=locales[i];
final String country=locale.getDisplayCountry(Locale.ENGLISH);
if(inputName!=null){
if(country.toUpperCase().startsWith(inputName.toUpperCase())){
choices.add(country);
if (choices.size()==10) {
break;
}
}
}
}
target.addComponent(label);
}
});
form.add(textField);
form.add(label);
}
}
<a href="IndexPage.html" wicket:id="back">[back]</a><br>
你所得到的字符是:<span wicket:id="label"></span><br/>
Country:
<input type="text" wicket:id="ac" size="50"/>
</form>
</body>
</html>
下一篇: 动态刷新实现图片验证码