2016-10-13 4 views
0

私は、ユーザーのカートに製品を保管するテーブルを持っています。各行には、ユーザーがユーザーのカートから単一の製品を取り除くことを可能にするボタンがあります。ここで私のhtmlのコードスニペットです。htmlの表から行の単一のデータを返す方法は?

<form action="${pageContext.request.contextPath}/customer/removeProduct" method="post"> 
     <input type="hidden" name="page" value="${page}"> 
     <table class="table"> 
      <thead> 
       <tr> 
        <th>Name</th> 
        <th>Quantity</th> 
        <th>Amount</th> 
       </tr> 
      </thead> 
      <tbody> 
       <c:forEach items="${productsInCart}" var="product" 
        varStatus="status"> 
        <input type="hidden" class="form-control" name="upc" 
          value="${product.getUpc()}"> 
        <tr class="warning"> 
         <td>${product.getName()}</td> 
         <td>${product.getQuantity()}</td> 
         <td style="color: green;">&#8369; ${product.getTotal()}</td> 
         <td><input type="submit" class="btn btn-warning btn-xs" 
          value="Remove from cart"></td> 
        </tr> 
       </c:forEach> 
      </tbody> 
     </table> 
    </form> 

ここに出力があります。

Product in cart table

私が取得したい値が隠し入力タイプフィールドに格納されている製品のUPCです。ただし、「カートから削除」ボタンをクリックすると、カートに入っている製品のUPCがすべて返されます。ここにコントローラのコードスニペットがあります。

@RequestMapping(value="/customer/removeProduct", method=RequestMethod.POST) 
public String removeProduct(@RequestParam(value = "upc") String upc, HttpServletRequest request){ 

    System.out.println(upc); 
//  customerService.removeProductInCart(customer.getCustomer(request).getCartId(), upc); 

    return "customer_home"; 
} 

答えて

0

テーブル全体をラップする代わりに、各行に特定のupcを取得するために、すべての繰り返しでフォームを作成するとよいでしょう。

関連する問題