检票口:Page.setVersioned(false) 但仍然序列化。为什么?
wicket: Page.setVersioned(false) but still serialized. Why?
我有单页应用程序(所有 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
),页面都会序列化。为什么没有版本控制?
只有无状态页面不存储。页面版本控制页面实例是否可以在商店中有多个版本。
从 Wicket 7.4.0 开始,也可以 make the Ajax components and behaviors stateless!
有关无状态的文档 AJAX 请参阅 https://ci.apache.org/projects/wicket/guide/7.x/single.html#_stateless_ajax_components_behaviors
我有单页应用程序(所有 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
),页面都会序列化。为什么没有版本控制?
只有无状态页面不存储。页面版本控制页面实例是否可以在商店中有多个版本。
从 Wicket 7.4.0 开始,也可以 make the Ajax components and behaviors stateless!
有关无状态的文档 AJAX 请参阅 https://ci.apache.org/projects/wicket/guide/7.x/single.html#_stateless_ajax_components_behaviors