我正在尝试构建一个可编辑的表格来输入买入订单详细信息的值。我有一个rich:datatable绑定到List,我通过向列表中添加元素来向表添加行。该实体有两个必须手动输入的字段,因此我使用h:inputTexts来执行此操作,但在这些字段中输入的值不会保存到列表中的对象。我尝试使用rich:inplaceInput(按照Exadel Richfaces livedemo上的确切说明)执行此操作,但无济于事。这是我的代码:
<rich:panel>
<f:facet name="header">#{messages.DetalleOrdenCompra}</f:facet>
<h:outputLabel value="#{messages.Codigo}" for="txtCodigo" /> #{' '}
<h:inputText id="txtCodigo">
<rich:suggestionbox id="suggestionBox" for="txtCodigo"
var="consumible" fetchValue="#{consumible.conNombre}"
suggestionAction="#{ordenCompraHome.autoComplete}" minChars="1"
reRender="tablaDetOrdComp" ignoreDupResponses="true"
bypassUpdates="false">
<h:column>
<f:facet name="header">#{messages.Codigo}</f:facet>
<h:outputText value="#{consumible.conNumber}" />
</h:column>
<h:column>
<f:facet name="header">#{messages.Descripcion}</f:facet>
<h:outputText value="#{consumible.conNombre}" />
</h:column>
<a:support event="onselect" immediate="true"
ignoreDupResponses="true" bypassUpdates="false">
<f:setPropertyActionListener value="#{consumible}"
target="#{ordenCompraHome.conActual}" />
</a:support>
</rich:suggestionbox>
</h:inputText>
#{' '}
<!-- Add elements to the list -->
<a:commandButton type="button" value="#{messages.Agregar}"
action="#{ordenCompraHome.anadirSeleccionadoADetalle()}"
reRender="tablaDetOrdComp" immediate="true" />
<!-- Hitting this button after entering any values in the table below shows that the values are never updated -->
<a:commandButton type="button" value="Refrescar tabla"
reRender="tablaDetOrdComp" immediate="true" />
<br />
<br />
<rich:dataTable value="#{ordenCompraHome.detalleOrdenCompra}"
var="detOrdComp" id="tablaDetOrdComp" rowKeyVar="row">
<rich:column width="5%">
<f:facet name="header">
<h:outputText value="#"></h:outputText>
</f:facet>
<h:outputText value="#{row+1}"></h:outputText>
</rich:column>
<!-- ... more columns, just data output -->
<!-- The two following columns are user inputs -- no updates in the underlying list when entering any value, both values are always null -->
<rich:column width="10%">
<f:facet name="header">
<h:outputText value="#{messages.Cantidad}"></h:outputText>
</f:facet>
<s:decorate template="layout/edit-nolabel.xhtml">
<h:inputText value="#{detOrdComp.ordCantidad}" id="txtCantidad" required="true">
<!-- tried with both events, onblur and onviewactivated, first each on on its own, then both together, no results -->
<a:support event="onblur" reRender="columnaMonto" immediate="true"
bypassUpdates="false" ajaxSingle="true" />
<a:support event="onviewactivated" reRender="columnaMonto" immediate="true"
bypassUpdates="false" ajaxSingle="true" />
</h:inputText>
</s:decorate>
</rich:column>
<rich:column width="10%">
<f:facet name="header">
<h:outputText value="#{messages.CostoUnitario}"></h:outputText>
</f:facet>
<s:decorate template="layout/edit-nolabel.xhtml">
<h:inputText value="#{detOrdComp.ordCostoUnitario}"
id="txtCostoUnitario" required="true">
<a:support event="onblur" reRender="columnaMonto"
immediate="true" bypassUpdates="false" ajaxSingle="true" />
<a:support event="onviewactivated" reRender="columnaMonto" immediate="true"
bypassUpdates="false" ajaxSingle="true" />
</h:inputText>
</s:decorate>
</rich:column>
<!-- This column is the result of a multiplication between txtCantidad and txtCostoUnitario -- I don't get anything here since both factors are null (null values have been properly handled so 0.0 is displayed when any of the factors is null) -->
<rich:column id="columnaMonto" width="10%">
<f:facet name="header">
<h:outputText value="#{messages.Monto}"></h:outputText>
</f:facet>
<h:outputText value="#{detOrdComp.ordSubparcial}"></h:outputText>
</rich:column>
</rich:dataTable>
豆:
// Underlying list. I used just @DataModel, then @DataModel(scope = ScopeType.PAGE), no results
@DataModel(scope = ScopeType.PAGE)
public List<OrdenCompraDetalle> getDetalleOrdenCompra() {
return detalleOrdenCompra;
}
而不是s:decorates我之前使用的是类似的东西(来自Livedemo),但它不起作用,
<rich:dataTable value="#{dataTableScrollerBean.allCars}" var="car" width="350px" columnClasses=",columns,columns,columns" rows="15" id="table" rowKeyVar="row">
<rich:column>
<f:facet name="header">
<h:outputText value="Price" />
</f:facet>
<rich:inplaceInput layout="block" value="#{car.price}"
id="inplace" required="true" selectOnEdit="true" editEvent="ondblclick">
<a4j:support event="onviewactivated" reRender="table, messages"/>
</rich:inplaceInput>
</rich:column>
我在这里缺少什么?任何帮助,将不胜感激。提前谢谢。
答案 0 :(得分:1)
我认为您的问题是ajaxSingle="true"
属性。此属性表示即使提交了表单中的所有输入元素,也只会处理触发提交的输入元素的输入。
如果这是问题,您可以尝试以下任何一种方法(我假设a
前缀是常见的a4j
前缀?):
将h:inputText
的ID添加到processed
属性<a:support>
。这将强制处理特定行的输入。例如(未测试):
<h:inputText value="#{detOrdComp.ordCostoUnitario}"
id="txtCostoUnitario" required="true">
<a:support event="onblur" reRender="columnaMonto"
immediate="true" bypassUpdates="false" ajaxSingle="true" processed="txtCostoUnitario" />
<a:support event="onviewactivated" reRender="columnaMonto" immediate="true"
bypassUpdates="false" ajaxSingle="true" processed="txtCostoUnitario"/>
</h:inputText>
移除ajaxSingle
,然后围绕<h:inputText>
中的a4j:region
(类似于已处理的ajaxSingle,此处处理最近/封闭区域中的所有输入):
<a4j:region>
<h:inputText value="#{detOrdComp.ordCostoUnitario}" id="txtCostoUnitario"
required="true">
<a:support event="onblur" reRender="columnaMonto"
immediate="true" bypassUpdates="false" />
<a:support event="onviewactivated" reRender="columnaMonto"
immediate="true" bypassUpdates="false" />
</h:inputText>
</a4j:region>
删除ajaxSingle
。这将导致表单中的所有元素都被处理。会花更多的时间。
在此输入代码