动态更改struts2 url的参数
我在 struts2 框架中动态地将参数分配给 url 时遇到问题。 我已经为此苦苦挣扎了几天,但无法将其投入工作。 一点背景知识,我正在使用 struts2 做一个 Web 应用程序,我还使用 JQuery 插件。 我有两个自动完成器,我需要将它们相互链接,我发现这样做的最佳方法是将第一个自动完成器上所选项目的 id 传递给第二个自动完成器以缩小其选项范围。
所以我正在做的事情是这样的,如下所述 http://struts .apache.org/2.2.3/docs/url.html
<s:url id="contactsautocompleterurl" action="contacts-autocompleter">
<s:param name="companyId" value="%{companyId}"></s:param>
</s:url>
<s:hidden id="contact_company_id" name="companyId"></s:hidden>
我用 JQuery 设置了隐藏字段的值,我可以看到该值正在更改。我的问题是将该值放入参数中。我也尝试过这样的方法,但仍然没有
<s:param name="companyId" value="%{contact_company_id}"></s:param>
遗漏任何细节,希望有人能指出。
提前致谢。
I'm having problems to dynamically assign a parameter to a url in struts2 framework.
I'm struggling with this for a couple of days and I can't put it to work.
A little background, I'm doing a web application using struts2, I also use JQuery plugin.
I have two autocomplete which I need to be linked to each other, the best way I found to do so, is to pass the id of the choosen item on the first autocompleter to the second one to narrow its options.
So what I'm doing is something like this, as stated here http://struts.apache.org/2.2.3/docs/url.html
<s:url id="contactsautocompleterurl" action="contacts-autocompleter">
<s:param name="companyId" value="%{companyId}"></s:param>
</s:url>
<s:hidden id="contact_company_id" name="companyId"></s:hidden>
I set the value of the hidden field with JQuery and I can see that the value is being changed. My problem is to get that value into the parameter. I've also tried like this and still nothing
<s:param name="companyId" value="%{contact_company_id}"></s:param>
I'm sure I'm missing a tiny detail, hope someone can point it out.
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不确定我是否理解您的意思,但我认为您不能使用“s:”标签来做到这一点,因为这些标签是在页面生成时在服务器端处理的,并且一旦页面加载完成就无法再次处理。
I'm not sure if I understood you, but I think you can't do it with "s:" tags, since these are processed server-side on page generation, and cannot be processed again once the page has finished loading.
您必须使用 jQuery 客户端构建 URL。您可以使用 s:url 标签创建 URL,并在页面上做出选择后在 javascript 中对其进行操作。
这应该会产生您正在寻找的结果,然后您只需将 actionURL javascript 变量分配到您需要的地方即可。
You'll have to build the URL with jQuery client side. You can create the URL with the s:url tag and manipulate it in the javascript once your selections are made on the page.
This should produce results like you're looking for, you then just assign the actionURL javascript variable to where ever you need it.