h:selectOneMenu在p:dataTable中不提交其值 [英] h:selectOneMenu in p:dataTable doesn't submit its value
问题描述
我有一个关于selectOneMenu和设置值的问题。我有一个Object SampleDesc和ID,Text和一个 List< SampleDescValues>
。对于每个数据行,Text是输出标签,选择一个菜单值是 List< SampleDescValues>
。
XHTML:
I have a question about selectOneMenu and settting the values. I have an Object SampleDesc that has and ID, Text, and a List<SampleDescValues>
. For each datatable row the Text is the output label and the select one menu values are the List<SampleDescValues>
.
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>
我有转换器设置,它的工作原理是因为将它设置为单个SampleDescValue,并设置值。
I have the converter setup and it works because ive set it to a single SampleDescValue and it set the value.
问题是当我从数据库中尝试使用Sample填充表单时,只能在无限数量的selectonemenu的
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
我将所选值设置为 private List< SampleDescValue> selectedSampleDescList;
当我尝试提交它什么也不做,当datatable没有呈现时它工作。
When i try and submit it does nothing, it works when the datatable is not rendered.
推荐答案
您的菜单值是错误的:
<h:selectOneMenu value="#{sampleBean.selectedSampleDescList.get(rowIndex)}">
无法执行设置
操作在这个EL表达式上。
It's not possible to perform a set
operation on this EL expression.
改用括号符号:
<h:selectOneMenu value="#{sampleBean.selectedSampleDescList[rowIndex]}">
请注意,这需要非空值 selectedSampleDescList
。因此,请确保您已经使用新的ArrayList()
进行了正确的初始化。 EL不会为你做的。它只会使用 List#add(index,object)
方法设置列表项。
Note that this expects a non-null selectedSampleDescList
. So make sure that you've already properly initialized it with a new ArrayList<>()
beforehand. EL won't do that for you. It will only set the list items using List#add(index, object)
method.
- Our EL wiki page
与具体问题无关 p>
Unrelated to the concrete problem, this expression
#{sampleBean.sampleDescList.list.size() gt 0}
可以简化如下
#{not empty sampleBean.sampleDescList.list}
这是始终 c $ c> c true
。只需直接使用 required =true
And this is unnecessary in the required
attribute of the <h:selectOneMenu>
as it would always evaluate true
at that point. Just use required="true"
directly instead.
这篇关于h:selectOneMenu在p:dataTable中不提交其值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!