简体   繁体   English

h:p中的selectOneMenu:dataTable不提交其值

[英]h:selectOneMenu in p:dataTable doesn't submit its value

I have a question about selectOneMenu and settting the values. 我有一个关于selectOneMenu和设置值的问题。 I have an Object SampleDesc that has and ID, Text, and a List<SampleDescValues> . 我有一个Object SampleDesc,它有ID,Text和List<SampleDescValues> For each datatable row the Text is the output label and the select one menu values are the List<SampleDescValues> . 对于每个数据表行,Text是输出标签,select一个菜单值是List<SampleDescValues> XHTML: XHTML:

    <h:panelGroup id="tables">
    <p:dataTable resizableColumns="true" 
             var="sampleDesc" id="SampleDescTable" rowIndexVar="rowIndex"
                     value="#{sampleBean.sampleDescList.list}" 
                     rendered="#{sampleBean.sampleDescList.list.size() gt 0}">
            <p:column>
                    <h:outputLabel value="#{sampleDesc.sampleDescText}"/>
                </p:column>
        <p:column>
            <h:selectOneMenu required="#{sampleBean.sampleDescList.list.size() gt 0}" converter="#{sampleDescValueConverter}" 
                                                         id="SampleDescValue" value="#{sampleBean.selectedSampleDescList.get(rowIndex)}">                                                         
                <f:selectItem itemLabel="Select One" itemValue="#{null}"/>
                            <f:selectItems value="#{sampleDesc.sampleDescValues}" var="sdv" 
                                       itemLabel="#{sdv.sampleDescValuesText}" itemValue="#{sdv}" />

                        </h:selectOneMenu>
                </p:column>    
        </p:dataTable>
</h:panelGroup>   

I have the converter setup and it works because ive set it to a single SampleDescValue and it set the value. 我有转换器设置,它的工作原理是因为我将它设置为单个SampleDescValue并设置了值。

The problem is when i try and populate the form with a Sample from the database it can only set one of the dropdowns when there could be an infinite number of selectonemenu's 问题是,当我尝试使用数据库中的Sample填充表单时,它只能设置一个下拉列表,当可能存在无限数量的selectonemenu时

I set the value selected to private List<SampleDescValue> selectedSampleDescList; 我将选择的值设置为private List<SampleDescValue> selectedSampleDescList;

When i try and submit it does nothing, it works when the datatable is not rendered. 当我尝试提交它什么都不做时,它在数据表未呈现时起作用。

Your menu value is wrong: 您的菜单值错误:

<h:selectOneMenu value="#{sampleBean.selectedSampleDescList.get(rowIndex)}">

It's not possible to perform a set operation on this EL expression. 无法对此EL表达式执行set操作。

Use the brace notation instead: 改为使用括号表示法:

<h:selectOneMenu value="#{sampleBean.selectedSampleDescList[rowIndex]}">

Note that this expects a non-null selectedSampleDescList . 请注意,这需要一个非null的selectedSampleDescList So make sure that you've already properly initialized it with a new ArrayList<>() beforehand. 因此,请确保您已使用new ArrayList<>()正确初始化它。 EL won't do that for you. EL不会为你做那件事。 It will only set the list items using List#add(index, object) method. 它只会使用List#add(index, object)方法设置列表项。

See also: 也可以看看:


Unrelated to the concrete problem, this expression 这个表达与具体问题无关

#{sampleBean.sampleDescList.list.size() gt 0}

can be simplified as follows 可简化如下

#{not empty sampleBean.sampleDescList.list}

And this is unnecessary in the required attribute of the <h:selectOneMenu> as it would always evaluate true at that point. 这在<h:selectOneMenu>required属性中是不必要的,因为它总是在那时评估为true Just use required="true" directly instead. 只需直接使用required="true"即可。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM