小票重定向:如何传递参数并保持网址“漂亮"? [英] Wicket redirect: how to pass on parameters and keeps URLs "pretty"?

查看:72
本文介绍了小票重定向:如何传递参数并保持网址“漂亮"?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

考虑一个重定向到另一个页面的Wicket网页(基于此处省略的某些逻辑):

Consider a Wicket WebPage that redirects to another page (based on some logic omitted from here):

public class SomePage extends WebPage {
    public SomePage(PageParameters parameters) {
        setResponsePage(AnotherPage.class);
        setRedirect(true);
    }
}

我需要将PageParameters传递到另一个页面,这似乎是这样做的方式:

I need to pass on the PageParameters to that other page, and this seems to be the way to do that:

setResponsePage(new AnotherPage(parameters));

但是,当像这样创建一个新的Page对象时,我最终到达的是诸如/?wicket:interface=:1::::之类的URL,而不是纯净的/another. AnotherPage定义为:

However, when creating a new Page object like this, I end up at an URL such as /?wicket:interface=:1:::: instead of the clean /another. AnotherPage is defined as:

@MountPath(path = "another")
public class AnotherPage extends WebPage {
    // ...
}

(MountPath来自org.wicketstuff.annotation.mount软件包.)

(Where MountPath is from org.wicketstuff.annotation.mount package.)

所以,我的问题是:

  • 通过其他方式传递参数吗?
  • 以某种方式使网址保持美观?以上是Wicket Stuff的特定限制,而不是核心Wicket?

嘿,只要建议的方法有效,任何都行得通,只要我删除setRedirect(true)也是我最初尝试的方法-setResponsePage(new AnotherPage(parameters)).在这种情况下,URL确实保持不变(指向SomePage的路径),并且我刚刚意识到,我确实应该从一开始就提到如果可以的话(只要它漂亮"即可)就可以了.并传递参数)!

Heh, turns out any of the suggested approaches work, and also what I originally tried — setResponsePage(new AnotherPage(parameters)) — as long as I remove setRedirect(true). The URL does stay the same (path to SomePage) in that case, and I just realised I really should have mentioned right from the start that it's okay if it does (as long as it's "pretty" and the parameters are passed)!

该页面("SomePage")基于查询参数将请求分派给看起来可能不同但是可以通过相同的URL访问的几个可能的结果页面.我试图将问题尽可能地概括和简化,但是当我遗漏了相关信息时,该问题就出了问题. :-/

The page ("SomePage") dispatches requests, based on query params, to a couple of possible result pages that look different but that are accessed through the same url. I tried to formulate the question as generic and minimalist as possible, but that went awry as I left out relevant info. :-/

对不起,如果结果变得怪异,不清楚或对其他人毫无用处.如果您有关于重命名的建议,请随时发表评论.

Sorry if this ended up weird, unclear or useless for others. If you have a suggestion about renaming it, feel free to comment.

推荐答案

也许Component中的另一个setResponsePage方法更接近于您想要的:

Maybe the other setResponsePage method in Component is closer to what you want:

/**
 * 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);
}

这篇关于小票重定向:如何传递参数并保持网址“漂亮"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆