我有一个5列的h:datatable。最后2个列是h:inputtext和commandButton。应该发生的是单击按钮后,该行的某些信息将定向到另一个数据表。传递的信息包括输入文本中的内容。
JSF代码:
<h:dataTable class="table"
headerClass="table-header"
rowClasses="table-odd-row, table-even-row"
value="#{food.getAllFoods()}"
var="foodlist">
<h:column>
<f:facet name="header">
Name
</f:facet>
#{foodlist.name}
</h:column>
<h:column>
<f:facet name="header">
Description
</f:facet>
#{foodlist.description}
</h:column>
<h:column>
<f:facet name="header">
Price
</f:facet>
#{foodlist.price}
</h:column>
<h:column>
<f:facet name="header">
Quantity
</f:facet>
<h:inputText value="#{productModel.qty[row.index]}"/>
</h:column>
<h:column>
<f:facet name="header">
Add to cart
</f:facet>
<h:form>
<h:commandButton value="Add to cart"
actionListener="#
{productModel.addProduct(foodlist.name, foodlist.price,
productModel.qty[loop.index])}"
action="orderwhat">
</h:commandButton>
</h:form>
</h:column>
</h:dataTable>
假定数据表中的inputtext字段使用户可以输入所需的数量(整数)。输入必须将其放入ArrayList数量。
<h:column>
<f:facet name="header">
Quantity
</f:facet>
<h:inputText value="#{productModel.qty[row.index]}"/>
</h:column>
然后通过命令按钮访问此数组:
<h:column>
<f:facet name="header">
Add to cart
</f:facet>
<h:form>
<h:commandButton value="Add to cart"
actionListener="#
{productModel.addProduct(foodlist.name,
foodlist.price,
productModel.qty[loop.index])}"
action="orderwhat">
</h:commandButton>
</h:form>
</h:column>
问题:
h:column创建的输入文本不会将其保存的值传递给数组。
后备豆工作正常。问题出在JSF代码内。
实现此目标的正确方法是什么?