java - When saving data it stored only first iterated value -


here code:

form<tenantitem> tenantitemform = form(tenantitem.class).bindfromrequest(); string[] itemid = request().body().asformurlencoded().get("idd"); string[] postaction = request().body().asformurlencoded().get("action");  if (postaction == null || postaction.length == 0) {     return badrequest("you must provide valid action"); } else {     string action = postaction[0];     if ("add".equals(action)) {         (string item: itemid){             tenantitemform.get().name =  tenantitem.findbyid(item).name;             tenantitemform.get().description = tenantitem.findbyid(item).description;             tenantitemform.get().image_url = tenantitem.findbyid(item).image_url;             tenantitemform.get().price = tenantitem.findbyid(item).price;             tenantitemform.get().tenant_id = tenantitemform.get().tenant_id;             tenantitemform.get().tenant_location_id =  tenantitemform.get().tenant_location_id;             tenantitemform.get().tenant_page_id = tenantitemform.get().tenant_page_id;              tenantitemform.get().save();              system.out.println("name tenant_id"+tenantitemform.get().name);             system.out.println("name tenant_location_id"+tenantitemform.get().tenant_id);             system.out.println("name tenant_page_id"+tenantitemform.get().tenant_page_id);         }           return redirect(              routes.project.pts(loc_id,id)         );     } else if ("cancel".equals(action)) {         system.out.println("delete id:"+id);         return ok("deleted");     } else {         return badrequest("this action not allowed");     } } 

my views.scala:

  @helper.form(routes.project.addexist(loc_id,pageid,id,pageid)){         <div class="row-fluid" >             <div class="span3">              </div>             <div class="span9">                 <div class="form-inline" id="options1">                     <input type="button" class="btn"  id="togglein" value="selectall" onclick="do_thisin()"/>                     <label class="control-label offset1">                         filter name:                     </label>                     <input class="span3" type="text" placeholder="enter name">                 </div>                 <ol id="selectable1">                       <input type="checkbox" id="selectall" >                     <input type="hidden" name="tenant_id" value="@id"/>                      <input type="hidden" name="tenant_location_id" value="@loc_id"/>                      <input type="hidden" name="tenant_page_id" value="@pageid"/>                       @for(it <- item){                     @if(it.tenant_location_id == locid){                         <li>                             <div class="well">                                 <div class="row-fluid">                                     <div class="span1">                                         <input name="idd" class="case" value="@it.id" type="checkbox">                                     </div>                                     <div class="span5">                                         <img class="img-polaroid span7" src="http://p.imgci.com/db/pictures/cms/128400/128483.1.jpg">                                     </div>                                     <dl>                                         <dt>                                         <h4>name:</h4>                                         </dt>                                         <dd>                                             <input type="hidden" name="name" value="@it.name"/>                                             <h5>@it.name</h5>                                         </dd>                                         <dt>                                         <h4>price:</h4>                                         </dt>                                         <dd>                                             <input type="hidden" name="price" value="@it.price"/>                                             <h5>@it.price</h5>                                             <input type="hidden" name="description" value="@it.description"/>                                         </dd>                                     </dl>                                 </div>                             </div>                         </li>                      <hr>                     }                     }                  </ol>             </div>         </div>         <div class="row-fluid">             <div class="form-inline">                 <div class="span5 offset6" >                     <input  type="submit" name="action" class="btn" value="add"/>                      <input type="submit" name="action" class="btn " value="cancel">                 </div>             </div>         </div>         } 

my functionality: @views: step:1 -> need select multiple items using checkbox. step:2 -> , have tenant_id,tenant_location_id,tenant_page_id , item_id.

@controller: step:3 -> need values using bind request, , have find item name,description,price using item_id , @model. step:4 -> have store selected values(based on length in checkbox).

when saving data stored first iterated value , not stored remaining selected values. don't know happening, , have checked data receiving , saving 1 time

thanks help.

this code maybe hint you:

form<tenantitem> tenantitemform = form(tenantitem.class).bindfromrequest(); tenantitem tenantitem = tenantitemform.get(); // bind tenantitem object  string[] itemid = request().body().asformurlencoded().get("idd"); string[] postaction = request().body().asformurlencoded().get("action");  if (postaction == null || postaction.length == 0) {     ... // code } else {     ... // code     if ("add".equals(action)) {         // declare new variable store data submitted         tenantitem tenanttobesaved;          (string item: itemid) {             // asign item object?             tenanttobesaved = new tenantitem();             item item_assigned = tenantitem.findbyid(item)             tenanttobesaved.name = item_assigned.name;             tenanttobesaved.description = item_assigned.description;             tenanttobesaved.image_url = item_assigned.image_url;             tenanttobesaved.price = item_assigned.price;             tenanttobesaved.tenant_id = tenantitem.tenant_id;             tenanttobesaved.tenant_location_id = tenantitem.tenant_location_id;             tenanttobesaved.tenant_page_id = tenantitem.tenant_page_id;              tenanttobesaved.save();              ... // rest of code         }     }    } 

Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -