Created
February 20, 2019 05:07
-
-
Save endymuhardin/8eb432c05539dda4543c67edf1633d57 to your computer and use it in GitHub Desktop.
Contoh Dynamic Input Field
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<form method=post> | |
Bobot Tugas 1 : <input type=text name=tugas1> % <br> | |
Bobot Tugas 2 : <input type=text name=tugas2> % <br> | |
Bobot Tugas 3 : <input type=text name=tugas3> % <br> | |
<input type=submit> | |
</form> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Controller | |
public class DynamicInputController { | |
@GetMapping("/dynamic-input") | |
public void displayForm(){} | |
@PostMapping("/dynamic-input") | |
public String processForm(@RequestParam Map<String, String> semuaParameter){ | |
// penampungan hasilnya | |
Map<Integer, Integer> bobotTugas = new HashMap<>(); | |
// ambil data dari request param | |
String prefix = "tugas"; | |
for(int i = 0; i < semuaParameter.size(); i++) { | |
Integer bobot = semuaParameter.get(prefix + i); | |
if(bobot != null){ | |
bobotTugas.put(i, bobot); | |
} | |
} | |
// selesai | |
return "redirect:/dynamic-input?success=true"; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment