Bet*_*sta 1 java wicket wicket-6
我想在wicket 6.5中测试一些AJAX DropDown(试过wicket 6.6并遇到同样的问题).
我使用quickstart wicket页面创建了我的wicket测试项目 - http://wicket.apache.org/start/quickstart.html
mvn archetype:generate -DarchetypeGroupId = org.apache.wicket -DarchetypeArtifactId = wicket-archetype-quickstart -DarchetypeVersion = 6.6.0 -DgroupId = net.betlista -DartifactId = tests.wicket-6.6 -DarchetypeRepository = https://repository.apache .org / -DinteractiveMode = false
我改变了HomaPage我LoadableDropDownTestPage在getHomePage()生成的WicketApplication类.
LoadableDropDownTestPage的Java代码是:
package net.betlista;
import java.io.Serializable;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.ajax.IAjaxIndicatorAware;
import org.apache.wicket.ajax.form.OnChangeAjaxBehavior;
import org.apache.wicket.ajax.markup.html.form.AjaxButton;
import org.apache.wicket.markup.html.WebPage;
import org.apache.wicket.markup.html.form.DropDownChoice;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.panel.FeedbackPanel;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.LoadableDetachableModel;
import org.apache.wicket.model.Model;
import org.apache.wicket.model.PropertyModel;
public class LoadableDropDownTestPage extends WebPage implements IAjaxIndicatorAware {
public LoadableDropDownTestPage() {
addComponents();
}
private void addComponents() {
add(new FeedbackPanel("feedback"));
FormObject formObject = new FormObject();
Form<FormObject> form = new Form<FormObject>("loadableDropDownTestForm", Model.of(formObject));
form.setOutputMarkupId(true);
form.setOutputMarkupPlaceholderTag(true);
final DropDownChoice<String> countryDD = new LoadableDropDown("countryDD", new PropertyModel<String>(formObject, "country"));
countryDD.setChoices(new CountryLoadableModel());
countryDD.setOutputMarkupId(true);
countryDD.setRequired(true);
countryDD.setOutputMarkupPlaceholderTag(true);
final DropDownChoice<String> cityDD = new LoadableDropDown("cityDD", new PropertyModel<String>(formObject, "city"));
cityDD.setChoices(new CityLoadableModel());
cityDD.setOutputMarkupId(true);
cityDD.setRequired(true);
cityDD.setOutputMarkupPlaceholderTag(true);
countryDD.add(new OnChangeAjaxBehavior() {
@Override
protected void onUpdate(AjaxRequestTarget target) {
System.out.println("country DD changed");
target.add(cityDD);
}
});
form.add(countryDD);
form.add(cityDD);
form.add(new AjaxButton("ab") {} );
add(form);
}
static class LoadableDropDown extends DropDownChoice<String> {
public LoadableDropDown(String id, IModel<String> model) {
super(id);
setModel(model);
}
}
static class FormObject implements Serializable {
String country;
String city;
}
class CountryLoadableModel extends LoadableDetachableModel<List<String>> {
@Override
protected List<String> load() {
System.out.println("loading CountryLoadableModel");
List<String> result = Arrays.asList(new String[] { "CR", "SR" } );
return result;
}
}
class CityLoadableModel extends LoadableDetachableModel<List<String>> {
List<String> choices = new LinkedList<String>();
@Override
protected List<String> load() {
System.out.println("loading CityLoadableModel");
if (choices.isEmpty()) {
choices.add("1");
} else {
int size = choices.size();
choices.add(Integer.toString(size+1));
}
return choices;
}
}
@Override
public String getAjaxIndicatorMarkupId() {
return "ajaxIndicator";
}
}
Run Code Online (Sandbox Code Playgroud)
和页面的HTML是:
<!DOCTYPE html>
<html xmlns:wicket="http://wicket.apache.org">
<div wicket:id="feedback"></div>
<form wicket:id="loadableDropDownTestForm">
Countries: <select wicket:id="countryDD"></select><br>
Cities: <select wicket:id="cityDD"></select><br>
<!-- input type="submit"-->
<button wicket:id="ab"></button>
</form>
</html>
Run Code Online (Sandbox Code Playgroud)
我的第一个问题是,我在页面上看不到AJAX调试链接.但我认为虽然有OnChangeAjaxBehavior我应该看到它.
接下来的问题是,当我改变国家DropDown的值时,没有任何反应,我不知道我做错了什么.
在我的代码中,您可以看到,我也尝试使用AjaxButton,但这也不起作用.
编辑:
日志的一部分(它在DEV模式下运行)
********************************************************************
*** WARNING: Wicket is running in DEVELOPMENT mode. ***
*** ^^^^^^^^^^^ ***
*** Do NOT deploy to your live server(s) without changing this. ***
*** See Application#getConfigurationType() for more information. ***
********************************************************************
Run Code Online (Sandbox Code Playgroud)
我认为问题在于您没有<body>在HTML中使用该标记.这打破了HTML解析器,这就是为什么你看不到AJAX调试窗口(以及任何其他javascript行为)的原因.
有一个很好的例子,你在Wicket例子中尝试做什么,看看它:http: //www.wicket-library.com/wicket-examples/ajax/choice
| 归档时间: |
|
| 查看次数: |
2561 次 |
| 最近记录: |