【发布时间】:2012-10-06 16:14:17
【问题描述】:
我使用 JQuery 在 2 个选择多个列表框之间移动元素(来回)。下面是我的 JQuery 代码。
<script type="text/javascript">
$(document).ready(function() {
alert('inside function');
$('#testForm\\:button_add').click(function(e) {
var selectedOpts = $("#testForm\\:select_from option:selected");
if (selectedOpts.length == 0) {
alert("Nothing to move.");
e.preventDefault();
}
$('#testForm\\:select_to').append($(selectedOpts).clone());
$(selectedOpts).remove();
e.preventDefault();
});
$('#testForm\\:button_remove').click(function(e) {
var selectedOpts = $("#testForm\\:select_to option:selected");
if (selectedOpts.length == 0) {
alert("Nothing to move.");
e.preventDefault();
}
$('#testForm\\:select_from').append($(selectedOpts).clone());
$(selectedOpts).remove();
e.preventDefault();
});
});
</script>
下面是我的 JSF 代码:
<td width="40%">
<h:selectManyListbox value="#{testListBox.selectManyOptions}" id="select_from" size="5" >
<f:selectItems value="#{testListBox.selectedOptions}" />
</h:selectManyListbox>
</td>
<td></td>
<td width="40%">
<h:commandButton value="To" id="button_add"/><br/>
<h:commandButton value="From" id="button_remove"/>
</td>
<td></td>
<td>
<h:selectManyListbox id="select_to" size="5"
value="#{testListBox.selectedItems}">
<f:selectItems />
</h:selectManyListbox>
</td>
<td></td>
在页面 bean 中,我已经声明了相应的绑定变量,如下所示,分别带有相应的 getter/setter。
private Map<String, Object> selectedOptions;
private Map<String, Object> selectManyOptions;
private List<SelectItem> selectItems = new ArrayList<SelectItem>();
private List<String> selectedItems;
现在我在提交页面时遇到错误。 “目标模型类型不是集合或数组” 任何人都可以建议它阻止我的导航吗? - 瓦姆西
【问题讨论】:
标签: jsf-2