Skip to content

Instantly share code, notes, and snippets.

@endymuhardin
Created February 20, 2019 05:07
Show Gist options
  • Save endymuhardin/8eb432c05539dda4543c67edf1633d57 to your computer and use it in GitHub Desktop.
Save endymuhardin/8eb432c05539dda4543c67edf1633d57 to your computer and use it in GitHub Desktop.
Contoh Dynamic Input Field
<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>
@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