a4j:support - 从h检索的值:selectOneMenu始终为NULL

jgu*_*emv 5 ajax jsf richfaces ajax4jsf

每个行都有一个带有ah:selectOneMenu的数据表.我希望能够检索bean中selectOneMenu中选择的值.我正在使用richfaces a4j:support标签来对辅助bean进行AJAX调用.你可以看到下面的代码:

DataTable标头:

<t:dataTable id="datatable" var="row" value="#{myBean.dataTableRows}">
Run Code Online (Sandbox Code Playgroud)

SelectOneMenu with A4j:

<h:selectOneMenu id="type" label="Type:" styleClass="tamanho80" 
                                value="#{datatableHolder.selectedValue}" converter="comboConverter" immediate="true" >                           
  <f:selectItem itemValue="#{null}" itemLabel="" />
  <t:selectItems var="tp" 
    itemValue="#{tp}" itemLabel="#{tp.nome}"
        value="#{row.comboTypeValues}"  />
   <f:attribute name="row" value="#{row}"/>                                                         
   <a4j:support event="onchange" reRender="parent" actionListener="${myBean.executeAjax}" immediate="true" ajaxSingle="true" />
</h:selectOneMenu>
Run Code Online (Sandbox Code Playgroud)

要执行的Backing Bean方法:

public void executeAjax(ActionEvent event){

    ValueHolder comboBox = (ValueHolder) event.getComponent().getParent();      
    comboBox .getValue();

}
Run Code Online (Sandbox Code Playgroud)
  • comboBox .getValue()返回NULL,即使我选择了一个值.

PS:

这个问题已被确定为可能与此问题重复,但事实并非如此.我的问题使用dataTable并且不对每个元素使用绑定.另外,我使用的是JSF 1.1和RichFaces 3.3.3.

jgu*_*emv 5

问题已确定:

t:selectItems 标记生成的每个“选项”都带有项目 id 而不是索引,而comboConverter 使用索引来选择项目。因此,列表有 12 个项目(索引范围应为 0 到 11),但所选项目的 id 为 22。然后转换器将遍历列表到索引 22 并检索元素。但是这个列表中没有这样的索引,因为最大值是 12,然后转换器将始终返回 NULL。

对于这个问题,基本上有3种方法可以解决:

  • 创建一个新的转换器,通过 id 查找项目
  • 调整/更改“comboConverter”以通过其 id 查找项目(这样做会影响使用此转换器的其他代码段
  • 调整列表以使用索引而不是 id

由于对系统影响较小,我选择了第一个。