如何删除或隐藏Wicket 1.5中引入的URL中的版本号?
安装页面无济于事。
http://localhost/MyPage/SubPage?0
答案 0 :(得分:20)
在Application.init()中:
mount(new MountedMapperWithoutPageComponentInfo("/subpage", MyPage.class));
使用以下Mapper类:
public class MountedMapperWithoutPageComponentInfo extends MountedMapper {
public MountedMapperWithoutPageComponentInfo(String mountPath, Class<? extends IRequestablePage> pageClass) {
super(mountPath, pageClass, new PageParametersEncoder());
}
@Override
protected void encodePageComponentInfo(Url url, PageComponentInfo info) {
// do nothing so that component info does not get rendered in url
}
@Override
public Url mapHandler(IRequestHandler requestHandler)
{
if (requestHandler instanceof ListenerInterfaceRequestHandler ||
requestHandler instanceof BookmarkableListenerInterfaceRequestHandler) {
return null;
} else {
return super.mapHandler(requestHandler);
}
}
}
答案 1 :(得分:4)
如果您不想要版本号,那么您的页面应该是完全无状态的,版本号适用于有状态页面。例如,如果您的页面包含表单,那么您应该使用Form组件的无状态变体,即org.apache.wicket.markup.html.form.StatelessForm。 如果您的页面已经完全无状态,您可以通过调用org.apache.wicket.Page #setStatelessHint方法为wicket提供提示。
答案 2 :(得分:4)
使用自创的MountedMapperWithoutPageComponentInfo类的解决方案对Wicket 6.13+不起作用,页面不会响应回调用户操作。 (请注意,Internet上有多个版本的MountedMapperWithoutPageComponentInfo。)
6.13+(用6.15测试)的解决方案可以在这里找到:
http://apache-wicket.1842946.n4.nabble.com/Delete-version-number-in-url-td4665752.html
// Put this code in your WebApplication subclass
import org.apache.wicket.core.request.mapper.MountedMapper;
import org.apache.wicket.request.component.IRequestablePage;
import org.apache.wicket.request.mapper.parameter.PageParametersEncoder;
import org.apache.wicket.request.mapper.info.PageComponentInfo;
import org.apache.wicket.request.IRequestHandler;
import org.apache.wicket.core.request.handler.BookmarkableListenerInterfaceRequestHandler;
private static class NoVersionMapper extends MountedMapper {
public NoVersionMapper(final Class<? extends IRequestablePage> pageClass) {
this("/", pageClass);
}
public NoVersionMapper(String mountPath, final Class<? extends IRequestablePage> pageClass) {
super(mountPath, pageClass, new PageParametersEncoder());
}
@Override
protected void encodePageComponentInfo(Url url, PageComponentInfo info) {
//Does nothing
}
@Override
public Url mapHandler(IRequestHandler requestHandler) {
if (requestHandler instanceof ListenerInterfaceRequestHandler || requestHandler instanceof BookmarkableListenerInterfaceRequestHandler) {
return null;
} else {
return super.mapHandler(requestHandler);
}
}
}
然后您可以使用以下方式挂载页面:
// Put this in the init() method of your WebApplication subclass
getRootRequestMapperAsCompound().add(new NoVersionMapper("urlPatternOfAPage", YourPage.class));
答案 3 :(得分:3)
使用以下映射器来挂载页面,这应该适用于除主页之外的任何可识别书签的页面。
以下是如何在Application.init()
中使用mappermount(new MountedMapperWithoutPageComponentInfo("/subpage", MyPage.class));
这是映射器。
import org.apache.wicket.request.Url;
import org.apache.wicket.request.component.IRequestablePage;
import org.apache.wicket.request.mapper.MountedMapper;
import org.apache.wicket.request.mapper.info.PageComponentInfo;
import org.apache.wicket.request.mapper.parameter.PageParametersEncoder;
public class MountedMapperWithoutPageComponentInfo extends MountedMapper {
public MountedMapperWithoutPageComponentInfo(String mountPath, Class<? extends IRequestablePage> pageClass) {
super(mountPath, pageClass, new PageParametersEncoder());
}
@Override
protected void encodePageComponentInfo(Url url, PageComponentInfo info) {
// does nothing so that component info does not get rendered in url
}
}
答案 4 :(得分:3)
对我来说,使用setStatelessHint
的解决方案不起作用。以下工作:
class MyApplication extends WebApplication {
@Override protected void init() {
getRequestCycleSettings().setRenderStrategy(
IRequestCycleSettings.RenderStrategy.ONE_PASS_RENDER);
....
}
}
答案 5 :(得分:1)
对于Wicket 8,这个NoVersionMapper类可以工作:
public class NoVersionMapper extends MountedMapper {
public NoVersionMapper(final Class pageClass) {
this("/", pageClass);
}
public NoVersionMapper(String mountPath, final Class pageClass) {
super(mountPath, pageClass, new PageParametersEncoder());
}
@Override
protected void encodePageComponentInfo(Url url, PageComponentInfo info) {
//Does nothing
}
@Override
public Url mapHandler(IRequestHandler requestHandler) {
if (requestHandler instanceof ListenerRequestHandler || requestHandler instanceof BookmarkableListenerRequestHandler) {
return null;
} else {
return super.mapHandler(requestHandler);
}
}
}
这与Devabc的代码基本相同,但是这个代码在Wicket 8上进行了编译。它已经针对以前版本的代码的已知回归进行了测试:Ajax工作,不应该触发页面刷新。
答案 6 :(得分:0)
到目前为止建议的解决方法可能适用于特定版本并具有副作用。他们应该被视为黑客。我已经使用过这些黑客攻击而且它们被新版本打破了。因此,我在这里创建了一个通用框架支持请求(请评论/投票):setVersioned(false) should force single Page Version。