dimanche 19 avril 2015

java spring with call diferent selector

I have this code html:



<html>
<body>
<script src="http://ift.tt/Plit8R"> </script>
<form action="#" th:action="@{/}" th:object="${person}">
<select id="person" th:field="*{name}">
<option th:each="p : ${list}" th:value="${p.getName()}" th:text="${p.getName()}"></option>
</select>
<input type="submit" onclick="cargaDatos()" value="CargarDatos"/>
</form>
<div th:fragment="selector">
<form action="#" th:action="@{/prueba}" th:object="${prueba}">
<select id="prueba">
<option th:each="p : ${lista}" th:value="${p.getName()}" th:text="${p.getName()}"></option>
</select>
</form>
</div>
<button type="submit">informe</button>
<script type="text/javascript"> function cargaDatos() {
$.ajax({ type: "GET",
url: "http://localhost:8080/prueba", success:
function(data){ alert("Ejecutado correctamente"); }, error: function
(data){ alert("Error en la ejecucion"); } }); } </script>
</body>
</html>


And this code in Java:



@RequestMapping(value="/", method=RequestMethod.GET)
public String showForm(Person person, Model model) {

System.out.println("/");
List<Person> list = new ArrayList<Person>();
Person p1 = new Person();
p1.setName("John");
p1.setAge(46);
Person p2 = new Person();
p2.setName("Helen");
p2.setAge(34);
list.add(p1);
list.add(p2);
model.addAttribute("list",list);
return "form";
}
@RequestMapping(value="/prueba", method=RequestMethod.GET)
public String showForm(Person person, Prueba prueba, Model model) {

System.out.println("/prueba");
List<Prueba> lista = new ArrayList<Prueba>();
Prueba p11 = new Prueba();
p11.setName("prueba1");
Prueba p22 = new Prueba();
p22.setName("prueba2");
lista.add(p11);
lista.add(p22);
model.addAttribute("lista",lista);
return "form :: selector";
}

@RequestMapping(value="/", method=RequestMethod.POST)
public String checkPersonInfo(Person person1) throws InterruptedException {

persona = person1.getName();
System.out.printf("1-el nombre seleccionado es: %s \n", persona);
return "redirect:/prueba";
}

@RequestMapping(value="/prueba", method=RequestMethod.POST)
public String checkPersonInfo(Prueba prueba) {
System.out.printf("2-el nombre seleccionado es: %s \n", prueba.getName());
return "redirect:/prueba";
}


And I want when the user press bottom, the selector 2 show options in function option selection in selector 1. But I want the screen show always selectors.


What is the problem? I don't know how I do this.


Aucun commentaire:

Enregistrer un commentaire