2013-07-02 3 views
0

장바구니가 있습니다. 내 응용 프로그램에 장바구니가 있습니다. Datatable입니다. 나는 아이템을 얻을 방법을 모르는변경 회 전자 값

<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> 

회 변화 : 그 제품의 수를 표시하는 스피너를 가지고 있고, 나는 스피너 값이 변경, 내 쇼핑 카트를 새로 고칠 때 원하는이 내 코드입니다 그 값을 갱신한다.

제발 도와 줘서 고마워요.

인사말.

답변

0

마지막으로 내가 그랬어 : productoBean.updateCantidad에서

<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> 

내가 가진 :

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

:

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

그리고 볼 수 있듯이 productoBean.refreshCantidad(carro)에, carro이 방법의 PARAM입니다 이렇게하면 회 전자의 마지막 가치가 무엇인지 알 수 있으며 쇼핑 카트를 업데이트 할 수 있습니다. rt.

인사말.