Jon*_*nik 5 java redirect wicket friendly-url
考虑一个重定向到另一个页面的Wicket WebPage(基于此处省略的一些逻辑):
public class SomePage extends WebPage {
public SomePage(PageParameters parameters) {
setResponsePage(AnotherPage.class);
setRedirect(true);
}
}
Run Code Online (Sandbox Code Playgroud)
我需要将PageParameters传递给其他页面,这似乎是这样做的方式:
setResponsePage(new AnotherPage(parameters));
Run Code Online (Sandbox Code Playgroud)
但是,在创建这样的新Page对象时,我最终会使用URL /?wicket:interface=:1::::
而不是clean /another
.AnotherPage定义为:
@MountPath(path = "another")
public class AnotherPage extends WebPage {
// ...
}
Run Code Online (Sandbox Code Playgroud)
(其中MountPath来自org.wicketstuff.annotation.mount包.)
所以,我的问题是:
嘿,原来任何建议的方法是可行的,而且也是我最初试图- setResponsePage(new AnotherPage(parameters))
-只要我删除setRedirect(true)
.在这种情况下,URL确实保持不变(SomePage的路径),我刚刚意识到我真的应该从一开始就提到它是可以的,如果它确实(只要它"漂亮"并且参数传递)!
页面("SomePage")基于查询参数将请求分派给几个看起来不同但通过相同URL访问的可能结果页面.我试图尽可能地将问题表述为通用和极简主义,但是当我遗漏相关信息时,这就出错了.: - /
对不起,如果这对他人来说很奇怪,不清楚或无用.如果您有关于重命名的建议,请随时发表评论.
seanizer有正确的想法,但为了完整性,有更多的选择,BookmarkablePageRequestTargetUrlCodingStrategy
而且HybridUrlCodingStrategy
:
IndexedHybridUrlCodingStrategy
IndexedParamUrlCodingStrategy
MixedParamUrlCodingStrategy
QueryStringUrlEncodingStrategy
小智 3
也许 Component 中的其他 setResponsePage 方法更接近您想要的:
/**
* Sets the page class and its parameters that will respond to this request
*
* @param <C>
*
* @param cls
* The response page class
* @param parameters
* The parameters for this bookmarkable page.
* @see RequestCycle#setResponsePage(Class, PageParameters)
*/
public final <C extends Page> void setResponsePage(final Class<C> cls, PageParameters parameters)
{
getRequestCycle().setResponsePage(cls, parameters);
}
Run Code Online (Sandbox Code Playgroud)