我有单页应用程序(所有AJAX),因此不需要页面版本控制。所以我做setVersioned(false)
。但是,页面仍然在每个AJAX请求上序列化,我想知道原因。
我使用的Wicket版本是:7.6.0
WicketApplication.java
public class WicketApplication extends WebApplication {
public Class<? extends WebPage> getHomePage() {
return HomePage.class;
}
public void init() {
super.init();
getFrameworkSettings().setSerializer(new MySerizalizer("foo"));
System.out.println("SERIALIZER: " + getFrameworkSettings().getSerializer().getClass().getName());
}
static class MySerizalizer extends org.apache.wicket.serialize.java.JavaSerializer {
public MySerizalizer(String applicationKey) {
super(applicationKey);
}
public byte[] serialize(Object object) {
final byte[] serialize = super.serialize(object);
System.out.println("serialized " + String.valueOf(serialize.length) + " bytes of " + object.getClass().getName());
return serialize;
}
}
}
HomePage.java
public class HomePage extends WebPage {
public HomePage() {
final Label label = new Label("message", new PropertyModel<>(foo, "bar"));
label.setOutputMarkupId(true);
add(label);
label.setVersioned(false);
final AjaxLink<Foo> ajaxLink = new AjaxLink<Foo>("plus1") {
public void onClick(AjaxRequestTarget target) {
foo.inc();
target.add(label);
}
};
ajaxLink.setVersioned(false);
add(ajaxLink);
setVersioned(false);
System.out.println("VERSIONED: " + isVersioned());
}
private Foo foo = new Foo();
class Foo implements Serializable {
int bar = 0;
public String getBar() {
return "bar is " + String.valueOf(bar);
}
public void inc() {
bar += 1;
}
}
}
HomePage.html
<!DOCTYPE html>
<html>
<body>
<h1>home page</h1>
<span wicket:id="message">Message goes here</span><br><br>
<input type="button" wicket:id="plus1" value="add one"></input>
</body>
</html>
日志:
SERIALIZER: com.foobar.WicketApplication$MySerizalizer
VERSIONED: false
serialized 2286 bytes of com.foobar.HomePage
serialized 2499 bytes of com.foobar.HomePage
serialized 2499 bytes of com.foobar.HomePage
serialized 2499 bytes of com.foobar.HomePage
serialized 2499 bytes of com.foobar.HomePage
对于每次点击按钮(org.apache.wicket.ajax.markup.html.AjaxLink
),页面都会被序列化。为什么没有版本化?
答案 0 :(得分:1)
仅存储无状态页面。页面版本控制是控制页面实例是否可以在商店中有多个版本。
从Wicket 7.4.0开始,make the Ajax components and behaviors stateless也可以!
答案 1 :(得分:1)