2016-08-05 2 views
0

Ich kann die abgerufenen Tabellenzeilen nicht aus meiner Datenbank (MySQL) bearbeiten, wenn ich auf den Editierbleistift drücke bekomme ich nichts in meiner Form, aber zum Löschen funktioniert es in jeder gewünschten Zeile. HierSo bearbeiten Sie abgerufene Daten aus der Datenbank und geben die Daten der Tabelle in die Textfelder des Formulars zurück

screenshot of my table row ist die history.scala.html Datei, wo ich Tabellendaten erhalten

@(formList: List[Users],form: Form[Users]) 

@main("history") { 

    @for(i <- mtnUsers.all()) { 

     @if(i.client.equalsIgnoreCase("potato")) { 
     <table> 
      <tbody> 
       <tr> 
        <td> <a href="/#"><i>@i.firstname @i.lastname </i></a></td> 
        <td> <a href="/#"><i>@i.phonenumber</i></a></td> 
        <td> <a href="/#"><i>@i.amount</i></a></td> 
        <td> <a href="/#"><i>@i.doneAt</i></a></td> 
        <td> <a href="@routes.Application.edit(i.id)"><i><span class="glyphicon glyphicon-pencil"></span></i></a></td> 
        <td> <a href="@routes.Application.delete(i.id)"><i><span class="glyphicon glyphicon-trash"></span></i></a></td> 
       </tr> 
      </tbody> 
     </table> 
     } 
    } 
} 

Das Folgende ist mein Controller Methoden bearbeiten und derjenige des Abrufens

public static Result history(long id) { 
    Form<Users> taskData = form(Users.class); 
    return ok(history.render(Users.MTN(), taskData)); 
} 

public static Result edit(Long id) { 
    Form<Users> content = form(Users.class).fill(
    Users.find.byId(id)); 

    return ok(views.html.edit.render(id,content)); 
} 

public static Result update(Long id) { 
    Form<Users> updateForm = form(Users.class).bindFromRequest(); 
    if (updateForm.hasErrors()) { 
     return badRequest(edit.render(id, updateForm)); 
    } 
    updateForm.get().update(id); 

    return redirect(routes.Application.profile()); 
} 

Und edit.scala.html, das Formular, das sollte Daten zum Ändern erhalten

<form action="@routes.Application.update(id)" method="post"> 

    <div class="form-group row"> 
     <label class="col-sm-2 form-control-label">Phone Number</label> 
     <div class="col-sm-10"> 
     <input name="phonenumber" class="form-control" type="text" placeholder="Phone Number"> 
     </div> 
    </div> 

    <div class="form-group row"> 
     <label class="col-sm-2 form-control-label">First Name</label> 
     <div class="col-sm-10"> 
     <input name="firstname" id="firstname" minValue="2" class="form-control" type="text" placeholder="First Name"> 
     </div> 
    </div> 

    <div class="form-group row"> 
     <label class="col-sm-2 form-control-label">Last Name</label> 
     <div class="col-sm-10"> 
     <input name="lastname" id="lastname" class="form-control" type="text" placeholder="Last Name"> 
     </div> 
    </div> 

    <div class="form-group row"> 
     <label class="col-sm-2 form-control-label">User</label> 
     <div class="col-sm-10"> 
     <select class="form-control" name="client" id="client" value="client"> 
      <option value="select">select ..</option> 
      <option value="potato">potato</option> 
      <option value="kamagaju">kamagaju</option> 
     </select> 
     </div> 
    </div> 
    <div class="form-group row"> 
     <label class="col-sm-2 form-control-label">Amount</label> 
     <div class="col-sm-10"> 
     <input name="amount" id="" value="" class="form-control" type="number" placeholder="Rwfr"> 
     </div> 
    </div> 

    <div class="panel-footer"> 
     <input type="submit" class="btn btn-danger" value="Send"> 
     <input type="reset" class="btn btn-warning" value="Reset"> 
    </div> 
</form> 
+0

Was ich bemerkt, alles funktioniert sehr gut, ich meine, zu bearbeiten und aktualisieren jede Reihe von MySQL-Tabelle. nur ein Problem, bei dem ich bleibe, ist, wie man nach dem Drücken des Stiftes einen Textwert in den Bearbeitungstext bringt. –

Antwort

0

Was ich letztendlich getan habe, ist das Hinzufügen der folgenden fett gedruckten Skripte in meiner edit.scala.html Vorlage. und in jedem Text bearbeiten Wert i hinzugefügt:

value = "@ data.id_of_this_filed"

@(data:Users,customerForm: Form[Users]) 

@main("edit") { 

    <form ... > 

..... 

<div class="form-group row "> 
           <label class="col-sm-2 form-control-label">Amount</label> 
           <div class="col-sm-10"> 
            <input 
              name="amount" 
              id="" 
              **value="@data.amount"** 
              class="form-control" 
              type="number" 
              placeholder="Rwfr"> 
           </div> 
          </div> 

....... 

    </form> 
     } 
Verwandte Themen