【问题标题】:Update shopping cart when change spinner value更改微调器值时更新购物车
【发布时间】:2013-06-30 08:19:48
【问题描述】:

我有一个购物车,在我的应用程序中有一个数据表。我有一个微调器来显示该产品的数量,我希望当微调器值发生变化时,刷新我的购物车,这是我的代码:

<p:dataTable var="carro" value="#{productoBean.productos}">
  <f:facet name="header">
    <h:outputText value="Carrito de la Compra" />
  </f:facet>
  <p:column headerText="Producto">
    <h:outputText value="#{carro.producto.nombre}" />
  </p:column>
  <p:column headerText="Cantidad">
    <p:spinner value="#{carro.cantidad}">
      <p:ajax listener="#{productoBean.refreshCantidad}" update="@this" />
    </p:spinner>
  </p:column>
  <p:column headerText="Precio/Unidad">
    <h:outputText value="#{carro.producto.precioUnidad} €" />
  </p:column>
  <p:column headerText="Valor">
    <h:outputText value="#{carro.valor} €" />
  </p:column>
</p:dataTable>

我不知道如何获取微调器更改并更新其值的项目。

我需要帮助,在此先感谢。

您好。

【问题讨论】:

    标签: ajax jsf-2 primefaces datatable spinner


    【解决方案1】:

    我终于做到了:

    <p:column headerText="Cantidad">
      <p:spinner value="#{carro.cantidad}" valueChangeListener="#{productoBean.updateCantidad}">
        <p:ajax event="change" listener="#{productoBean.refreshCantidad(carro)}" update=":formCarrito" />
      </p:spinner>
    </p:column>
    

    productoBean.updateCantidad 我有:

    public void updateCantidad(ValueChangeEvent event) {
      cantidad = (Integer) event.getNewValue();
    }
    

    而在productoBean.refreshCantidad(carro) 中可以看出,carro 是方法的参数:

    public void refreshCantidad(Compra compra) {
      carritoBean.addProduct(compra.getProducto(), cantidad);
    }
    

    这样我知道微调器的最后一个值是什么,我可以更新我的购物车。

    您好。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-08-29
      • 1970-01-01
      • 2021-04-19
      • 1970-01-01
      • 2020-11-27
      • 2018-12-28
      • 2017-01-16
      相关资源
      最近更新 更多