Struts2。如何在一个变量中选择某些组合框的选项?
使用我试图在我的jsp上绘制一些组合框,这些组合框必须与我的Action类中的变量连接。由于我的组合框的数量是动态计算的,我无法在 Action 类中创建确切数量的变量。所以我试图将索引原则应用于我的组合框。但我的 Action 类被误解了 Object 值。
<s:iterator value="question.answers" id="entry" status="status">
<s:property value="text"/>
<s:combobox list = "question.answers" listValue="rightText" listKey="rightText" name="%{'chosenComboOption['+#status.count+']'}" emptyOption="false"/>
<br />
</s:iterator>
请帮助我从组合框中获取所选值!
Using I am trying to paint on my jsp some comboboxes which must be connected with variable in my Action class. Because of amount of my comboboxes are dynamic calculated I cann't create exact amount of variables in Action class. So I was trying to apply principle of index to my comboboxes. But my Action class gets misunderstood Object value.
<s:iterator value="question.answers" id="entry" status="status">
<s:property value="text"/>
<s:combobox list = "question.answers" listValue="rightText" listKey="rightText" name="%{'chosenComboOption['+#status.count+']'}" emptyOption="false"/>
<br />
</s:iterator>
Please help me to get chosen values from my comboboxes!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
有几件事让我突然想到。首先,您不想使用“status.count”,因为它返回列表中的项目总数,而不是当前迭代索引。相反,您需要使用“status.index”。其次,我认为你的索引选择语法不正确。尝试像这样手动做事情是一种黑魔法,你必须进行调整才能做到恰到好处。
在我最近正在进行的一个项目中,我必须做类似的事情。不确定这个确切的语法是否适合您,但值得一试。尝试将: 更改
为:
A couple of things jump out at me. First of all, you don't want to use "status.count", because that returns the total number of items in the list, not the current iteration index. Instead you would want to use "status.index". Second, I think your syntax is incorrect in the index selection. Trying to do things manually like this is a sort of black magic that you have to tweak to try to get just right.
In a project that I was working on recently, I had to do something similar to this. Not sure if this exact syntax will work for you or not, but it is worth a shot. Try to change:
to this: