如何使用普通 Wicket 根据下拉列表动态地将用户定向到新页面?

发布于 2024-11-03 05:40:05 字数 384 浏览 2 评论 0原文

这是我的情况:用户选择一个部分(例如从下拉列表中),例如“Section1”、“Section2”或“Section3”。然后他单击“确定”按钮(或某个链接)。

我需要发生的事情:在他单击该按钮/链接后,他将被重定向到所选部分,例如 www.homepage.com/docs#section2

到目前为止,我还无法从 LinkonClick 方法处理表单,也无法调用一些 clickLink来自 Button 方法 onSubmit()Link

我不想使用 AJAX 或 JavaScript。我该怎么做?

Here is my situation: the user selects a section (for example from a dropdown) such as "Section1," "Section2" or "Section3." Then he clicks the OK button (or some link).

What I need to happen: after he clicks on that button/link, he will be redirected to the selected section, e.g. www.homepage.com/docs#section2.

So far, I have not been able to process the form from Link's onClick method, nor have I been able to call some clickLink on Link from the Button method onSubmit().

I would prefer not to use AJAX or JavaScript. How can I do this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

救星 2024-11-10 05:40:05

这是因为链接不提交表单。它只是充当到某个地方的链接。要访问您的表单数据,您需要先提交表单。尝试使用 SubmitLink 而不是 Link 并

getRequestCycle().setRequestTarget  
    (new RedirectRequestTarget("www.homepage.com/docs#section2"));

从 SubmitLink 的 onSubmit 函数调用。
从 Javadoc 来看,这应该可行,但我现在无法测试它。

A RequestTarget that will send a redirect url to the browser. Use this if you 
want to direct the browser to some external URL, like Google etc, immediately. 
Or if you want to redirect to a Wicket page. If you want to redirect with a 
delay the RedirectPage will do a meta tag redirect with a delay. 

That's because a Link doesn't submit the form. It just acts as a link to somewhere. To access your formdata you'll need to submit the form first. Try using a SubmitLink instead of a Link and call

getRequestCycle().setRequestTarget  
    (new RedirectRequestTarget("www.homepage.com/docs#section2"));

from the onSubmit function of the SubmitLink.
Judging from the Javadoc this should work but I can't test it right now.

A RequestTarget that will send a redirect url to the browser. Use this if you 
want to direct the browser to some external URL, like Google etc, immediately. 
Or if you want to redirect to a Wicket page. If you want to redirect with a 
delay the RedirectPage will do a meta tag redirect with a delay. 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文