JSF - h:selectOneListbox - 如何上下移动项目
我有一个
,其中填充了
,它仅附加到我的 Seam 对象上的列表属性。下面是我的(简化的)JSF 代码:
<a4j:outputPanel ajaxRendered="true" id="valuesListPanel">
<table border="0" cellspacing="5">
<tr><td rowspan="5">
<h:selectOneListbox id="pickValue" value="#{seamObject.selectedValue}">
<s:selectItems value="#{seamObject.propertyValues}" var="properties" label="#{properties}" />
</h:selectOneListbox>
</td>
<td><a4j:commandButton value="Move Up"
action="#{seamObject.moveUp}"/></td></tr>
<tr><td><a4j:commandButton value="Move Down" action="#{seamObject.moveDown}"/></td></tr>
</table>
</a4j:outputPanel>
Seam 对象中的 moveUp 和 moveDown 方法在支持列表中查找选定的项目,并将其向上或向下移动。
这是我遇到的问题:当我单击这些按钮之一时,AJAX 请求就会通过,并且支持对象会发生变化。但是,该列表不会更新。然而,当我第二次单击其中一个按钮时,之前的更改会反映在列表框中。
因此,如果我“下移”一项,则看不到任何变化。但是,如果我“向上移动”另一个项目,则该项目不会发生任何变化,但我之前想要向下移动的项目会向下移动。
通过强制另一个 AJAX 请求来破解此问题“有效”,但第二个请求会清除任何应该显示的 FacesMessage。
我怎样才能让它发挥作用?有更好的方法来解决这个问题吗?
I have an <h:selectOneListbox>
populated with an <s:selectItems>
, which is just attached to a list property on my Seam object. Here's my (simplified) JSF code:
<a4j:outputPanel ajaxRendered="true" id="valuesListPanel">
<table border="0" cellspacing="5">
<tr><td rowspan="5">
<h:selectOneListbox id="pickValue" value="#{seamObject.selectedValue}">
<s:selectItems value="#{seamObject.propertyValues}" var="properties" label="#{properties}" />
</h:selectOneListbox>
</td>
<td><a4j:commandButton value="Move Up"
action="#{seamObject.moveUp}"/></td></tr>
<tr><td><a4j:commandButton value="Move Down" action="#{seamObject.moveDown}"/></td></tr>
</table>
</a4j:outputPanel>
The moveUp and moveDown methods in the Seam object find the selected item in the backing list, and move it up, or down.
Here's the problem I'm having: When I click one of these buttons, the AJAX request goes through, and the backing object does change. However, the list doesn't update. The second time I click one of these buttons, however, the previous change is reflected in the list box.
So, if I "move down" one item, no change is visible. However, if I "move up" another item, nothing happens to that one, but the item I previously wanted to move down, moves down.
Hacking this by forcing another AJAX request "works," with the exception that the second request wipes out any FacesMessages that are supposed to be showing.
How can I get this to work? Is there a better way to approach the problem?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您不使用
rich:orderingList
是否有特殊原因?对列表进行排序正是它的目的。如果你做不到这一点,
a4j:log
会说什么?面板是否重新渲染?如果是,用什么数据?Is there a particular reason you are not using the
rich:orderingList
? Ordering a list is exactly what it is intended for.If you can't do that, what does
a4j:log
say? Is the panel rerendered? If yes, with what data?我最终在两个 a4j:commandButtons 上都放置了immediate="true"。这与对列表框的 onchange 事件进行 AJAX 调用(以便服务器知道所选项目是什么)相结合,给了我所需的行为。它并不漂亮,但它有效,而且我不能在上面花费更多的时间。
I ended up putting immediate="true" on both a4j:commandButtons. This, combined with putting an AJAX call on the onchange event for the listbox (so that the server knows what the selected item is), gave me the desired behavior. It's not pretty, but it works, and I can't afford to spend a whole lot more time on it.