Skip to content
Snippets Groups Projects
Commit 6cd58c7e authored by Bruno Nocera Zanette's avatar Bruno Nocera Zanette
Browse files

Update Municipio option's list based on the Estado

Update Municipio option's list based on the Estado chosen.

Steps:
1) Client sends a request to the server using estado as parameter.
2) Server receives the request, generates the list based on the Estado
   and sends as response a complete view/page ("orgaoexecutores/create")
   containing that list
3) Client receive the response, processes it to get only the list,
   and exchanges the list of the page for the response list.
parent 99f108f5
Branches
No related tags found
No related merge requests found
...@@ -64,16 +64,15 @@ public class OrgaoExecutorController { ...@@ -64,16 +64,15 @@ public class OrgaoExecutorController {
return "redirect:/orgaoexecutores"; return "redirect:/orgaoexecutores";
} }
@RequestMapping(method = RequestMethod.GET, produces = "text/html") @RequestMapping(value = "/{id}", method = RequestMethod.GET, produces = "text/html")
public String get(@RequestParam(value = "uf") String uf, @Valid OrgaoExecutor orgaoExecutor, BindingResult bindingResult, Model uiModel, HttpServletRequest httpServletRequest) { public String get(@PathVariable(value = "id") String uf, @Valid OrgaoExecutor orgaoExecutor, BindingResult bindingResult, Model uiModel, HttpServletRequest httpServletRequest) {
System.out.println("GET_MUNICIPIO COM A ID: "+uf);
repopulateMunicipios(uf, uiModel, orgaoExecutor); repopulateMunicipios(uf, uiModel, orgaoExecutor);
return "orgaoexecutores/create"; return "orgaoexecutores/create";
} }
void repopulateMunicipios(String uf, Model uiModel, OrgaoExecutor orgaoExecutor) { void repopulateMunicipios(String uf, Model uiModel, OrgaoExecutor orgaoExecutor) {
uiModel.addAttribute("municipios", Municipio.findAllMunicipiosByUf(uf)); List<Municipio> lm = Municipio.findAllMunicipiosByUf(uf);
System.out.println("__AKI__"); uiModel.addAttribute("municipios", lm);
} }
void populateEditForm(Model uiModel, OrgaoExecutor orgaoExecutor) { void populateEditForm(Model uiModel, OrgaoExecutor orgaoExecutor) {
...@@ -86,12 +85,12 @@ public class OrgaoExecutorController { ...@@ -86,12 +85,12 @@ public class OrgaoExecutorController {
le.add(0, e); le.add(0, e);
uiModel.addAttribute("estadoes", le); uiModel.addAttribute("estadoes", le);
List<Municipio> lm = Municipio.findAllMunicipios(); // List<Municipio> lm = Municipio.findAllMunicipios();
Municipio m = new Municipio(); // Municipio m = new Municipio();
m.setId((long) 0); // m.setId((long) 0);
m.setNome(""); // m.setNome("");
lm.add(0, m); // lm.add(0, m);
uiModel.addAttribute("municipios", lm); // uiModel.addAttribute("municipios", lm);
} }
} }
...@@ -33,22 +33,29 @@ ...@@ -33,22 +33,29 @@
widgetType : "dijit.form.FilteringSelect", widgetType : "dijit.form.FilteringSelect",
widgetAttrs : { widgetAttrs : {
onChange : function() { onChange : function() {
uf=document.getElementsByName("uf")[0].value;
console.log("REPOPULANDO A PARTIR DE UF(ID) = "+uf);
// var element = document.getElementsByName("_municipio_id_popup"); //ID of the chosen "estado"
// console.log(element); uf=document.getElementsByName("uf")[0].value;
//Create and send to server a request of
//the list of "Municipios" that belongs to the "Estado" chosen
xmlhttp = new XMLHttpRequest(); xmlhttp = new XMLHttpRequest();
xmlhttp.open("GET", "orgaoexecutores?uf="+uf ,true); xmlhttp.open("GET", "orgaoexecutores/"+uf ,false);
xmlhttp.send(); xmlhttp.send();
//Create a temporary html document to store the html code
//sent by the server containing the list of "Municipios"
var responseDoc = document.implementation.createHTMLDocument("XMLHttpResponse");
responseDoc.documentElement.innerHTML = xmlhttp.responseText;
//Copy the list of the response to the real page
var PageElem = document.getElementById("_c_br_ufpr_c3sl_estacaojuventude_OrgaoExecutor_municipio_id");
var RespElem = responseDoc.getElementById("_c_br_ufpr_c3sl_estacaojuventude_OrgaoExecutor_municipio_id");
PageElem.innerHTML = RespElem.innerHTML;
} }
} }
})); }));
</script> </script>
</div> </div>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment