【问题标题】:Get the selected values from a rich:select which is inside o a4j:repeat从 a4j:repeat 中的 rich:select 获取选定的值
【发布时间】:2014-01-08 23:09:43
【问题描述】:

我正在使用a4j:repeat 控件来遍历Map<Object, List<MyType>> 列表。 XHTML 页面同时显示h:outputTextrich:select 控件。

我循环遍历Map<String, List<Items>> 实例,以显示主从表。在h:outputText 中显示主要描述,rich:select 显示详细信息。

代码如下:

客户.xhtml

<a4j:repeat value="#{masterManagedBean.listMasterItems.entrySet().toArray()}"
var="itemsVar">
    <h:outputText value="#{itemsVar.key}" />
    <rich:select enableManualInput="true">
       <f:selectItems value="#{itemsVar.value}" id="itemsMenu" 
                var="itemsVarSelect"
                     itemLabel="#{itemsVarSelect.descriptionItems}"
                      itemValue="#{itemsVarSelect.idItems}" />
    </rich:select>
 </a4j:repeat>

这个 sn-p 工作完美。但是,我不知道如何从中继器生成的每个rich:select 中获取所选值。请指导我解决这个问题。

【问题讨论】:

  • 请提供您的 xhtml 和托管 bean 的示例 (sscce.org)。您想详细实现什么,当前的确切问题是什么(异常、错误消息)...
  • @L-Ray 我在下面发布了一个 sn-p。提前致谢
  • 据我了解,List&lt;MyType&gt; 对于每个对象都不同,对吧?
  • @HumanoLegal 您输入该信息的框是为了回答。请记住,stackOverflow 不像具有对话线程的论坛。您可以在必要时编辑您的问题以包含其他信息(在这种情况下,L-Ray 已经这样做了)。

标签: ajax jsf jsf-2 map richfaces


【解决方案1】:

基本上,我建议不要将数据结构Map&lt;String,List&gt; 用于所描述的情况。为什么不将结构更改为具有SelectionObject-class 的普通对象列表(List&lt;SelectionObject&gt;):

  • 名称/标签
  • 可能的值(如列表或数组)
  • 选定的值

所以 JSF 代码看起来像

<a4j:repeat value="#{masterManagedBean.listMasterItems}"
    var="itemsVar">
    <h:outputText value="#{itemsVar.label}" />
    <rich:select enableManualInput="true" value="#{itemsVar.selectedValue}">
       <f:selectItems value="#{itemsVar.possibleValues}" id="itemsMenu" 
                var="itemsVarSelect"
                     itemLabel="#{itemsVarSelect.descriptionItems}"
                     itemValue="#{itemsVarSelect.idItems}" />
    </rich:select>
</a4j:repeat>

可以为此对象结构进行任何准备/构建,例如在getListMasterItems(使用一些缓存)中,用户数据的检索是在提交按钮的action 中完成的。只需遍历列表并读出`selectedValue.如果答案有用/有帮助,请考虑投票,确认它是否适合您。

希望对你有帮助...

【讨论】:

  • 这听起来是一个公平的解决方案。因此,我需要创建另一个具有接近属性的类来模仿 Map> 结构。列表中的每个对象都有选定的值,对吧?
  • 很好,很棒的反馈! Soo,“upvote”/“accept” 和......今天开始新的事情。 :-)
猜你喜欢
  • 1970-01-01
  • 2017-05-30
  • 1970-01-01
  • 1970-01-01
  • 2012-11-11
  • 2015-10-10
  • 2021-06-14
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多