0

I have an element inside a list which i populate with jstl. the problem i have is that i a have a button with a form inside each loop. when a user clicks i need to know what object he has selected. any tips would be awesome.

<c:forEach items="${productos}" var="producto"> 
 <li class="media ">
     <a class="pull-left " href="verinfoproducto">
     <img class="media-object" src="${producto.imagen}" height="128 " width="128"></a>
     <div class="media-body ">
     <h4 class="media-heading ">${producto.nombreP}</h4>
      <p>${producto.descripcion}</p>
      <h4>Precio: ${producto.precio}</h4>
       <div class="row">
      <c:choose>
         <c:when test="${not empty sessionScope.cliente }" >
        <form method="post" action="generarpedido">

           <c:set var="productoSel" value="${producto}" scope="session"/>
            <div class="col-md-2">
             <input type="text" name="cantidad" class="form-control text-center" placeholder="Cantidad">
           </div>
           <div class="col-md-1">
           <button type="submit"> 
            <i class="fa fa-2x fa-cart-plus"></i></button>
          </div>
      </form>


     </c:when>
    </c:choose>


   </div>
  </div>
  </li>
 </c:forEach>
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
S.Regusci
  • 63
  • 6

1 Answers1

1

Please do the following changes into your code,

<form method="post" action="Servletname1?name=${producto.name}">

And at Servletname1,

request.getParameter("name"); // it will return result what you want...
Vishal Gajera
  • 4,137
  • 5
  • 28
  • 55
  • uhmm... how you know `producto.name` exists? I woul.d bet `producto.nombre` according other properties in spanish... also a question... ¿The names of the objects in your tables are unique and used as `ID's` usually? that does not seem a very good practice... – Jordi Castilla Nov 30 '15 at 09:17
  • you can use whatever properties you want, i just guess it's name. so just replace it by your choice value form list or anything else. – Vishal Gajera Nov 30 '15 at 09:19
  • agreee with that, I just wanted to point is better to manage entities by id... ;) – Jordi Castilla Nov 30 '15 at 09:40