diff --git a/src/main/java/br/ufpr/c3sl/estacaojuventude/Municipio.java b/src/main/java/br/ufpr/c3sl/estacaojuventude/Municipio.java index 0b99bc1de819330bdd3c200f9377798acd28f4ae..288645803a363dc806ff12981548d428770f6dd4 100644 --- a/src/main/java/br/ufpr/c3sl/estacaojuventude/Municipio.java +++ b/src/main/java/br/ufpr/c3sl/estacaojuventude/Municipio.java @@ -29,4 +29,8 @@ public class Municipio { public static List<Municipio> findAllMunicipios() { return entityManager().createQuery("SELECT o FROM Municipio o ORDER BY nome", Municipio.class).getResultList(); } + + public static List<Municipio> findAllMunicipiosByUf(String uf) { + return entityManager().createQuery("SELECT o FROM Municipio o WHERE UF="+uf+" ORDER BY nome", Municipio.class).getResultList(); + } } diff --git a/src/main/java/br/ufpr/c3sl/estacaojuventude/web/OrgaoExecutorController.java b/src/main/java/br/ufpr/c3sl/estacaojuventude/web/OrgaoExecutorController.java index bf1ed34409842bf278626262ccb92969a6cf4b9a..9451fae01d321764d8b7e6c1257a35dce3b08003 100644 --- a/src/main/java/br/ufpr/c3sl/estacaojuventude/web/OrgaoExecutorController.java +++ b/src/main/java/br/ufpr/c3sl/estacaojuventude/web/OrgaoExecutorController.java @@ -15,6 +15,7 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestParam; +import br.ufpr.c3sl.estacaojuventude.Estado; import br.ufpr.c3sl.estacaojuventude.Municipio; import br.ufpr.c3sl.estacaojuventude.OrgaoExecutor; @@ -63,16 +64,33 @@ public class OrgaoExecutorController { return "redirect:/orgaoexecutores"; } + @RequestMapping(value = "/{id}", method = RequestMethod.GET, produces = "text/html") + public String get(@PathVariable(value = "id") String uf, @Valid OrgaoExecutor orgaoExecutor, BindingResult bindingResult, Model uiModel, HttpServletRequest httpServletRequest) { + repopulateMunicipios(uf, uiModel, orgaoExecutor); + return "municipios/selectmunicipios"; + } + + void repopulateMunicipios(String uf, Model uiModel, OrgaoExecutor orgaoExecutor) { + List<Municipio> lm = Municipio.findAllMunicipiosByUf(uf); + uiModel.addAttribute("municipios", lm); + } + void populateEditForm(Model uiModel, OrgaoExecutor orgaoExecutor) { uiModel.addAttribute("orgaoExecutor", orgaoExecutor); addDateTimeFormatPatterns(uiModel); - List<Municipio> lm = Municipio.findAllMunicipios(); - Municipio m = new Municipio(); - m.setId((long) 0); - m.setNome(""); - lm.add(0, m); - uiModel.addAttribute("municipios", lm); + List<Estado> le = Estado.findAllEstadoes(); + Estado e = new Estado(); + e.setNome(""); + le.add(0, e); + uiModel.addAttribute("estadoes", le); + +// List<Municipio> lm = Municipio.findAllMunicipios(); +// Municipio m = new Municipio(); +// m.setId((long) 0); +// m.setNome(""); +// lm.add(0, m); +// uiModel.addAttribute("municipios", lm); } } diff --git a/src/main/webapp/WEB-INF/i18n/application.properties b/src/main/webapp/WEB-INF/i18n/application.properties index dc49d2752472420321a898984ecd920ddbf194b9..26ebf9307f01b9ff7127be371ae6d975ef6b581e 100644 --- a/src/main/webapp/WEB-INF/i18n/application.properties +++ b/src/main/webapp/WEB-INF/i18n/application.properties @@ -69,6 +69,8 @@ label_br_ufpr_c3sl_estacaojuventude_orgaoexecutor_sigla=Sigla label_br_ufpr_c3sl_estacaojuventude_orgaoexecutor_site=Site label_br_ufpr_c3sl_estacaojuventude_orgaoexecutor_telefonecontato=Telefone do contato label_br_ufpr_c3sl_estacaojuventude_orgaoexecutor_version=Versão +label_br_ufpr_c3sl_estacaojuventude_orgaoexecutor_municipio.uf=UF +label_br_ufpr_c3sl_estacaojuventude_orgaoexecutor_estado=Estado label_br_ufpr_c3sl_estacaojuventude_programa=Programa label_br_ufpr_c3sl_estacaojuventude_programa_beneficios=Benefícios Associados diff --git a/src/main/webapp/WEB-INF/views/municipios/selectmunicipios.jspx b/src/main/webapp/WEB-INF/views/municipios/selectmunicipios.jspx new file mode 100644 index 0000000000000000000000000000000000000000..fb84e60970ccb56d18b7d4519775e5695bce4ac3 --- /dev/null +++ b/src/main/webapp/WEB-INF/views/municipios/selectmunicipios.jspx @@ -0,0 +1,9 @@ +<?xml version="1.0" encoding="UTF-8" standalone="no"?> +<div xmlns:c="http://java.sun.com/jsp/jstl/core" xmlns:field="urn:jsptagdir:/WEB-INF/tags/form/fields" xmlns:form="urn:jsptagdir:/WEB-INF/tags/form" xmlns:jsp="http://java.sun.com/JSP/Page" xmlns:spring="http://www.springframework.org/tags" version="2.0"> + <jsp:directive.page contentType="text/html;charset=UTF-8"/> + <jsp:output omit-xml-declaration="yes"/> + <form:create id="fc_br_ufpr_c3sl_estacaojuventude_OrgaoExecutor" modelAttribute="orgaoExecutor" path="/orgaoexecutores" render="${empty dependencies}" z="ySSBiOgc68ijzLxGB8mEHSqYtyU="> + <field:select field="municipio" id="c_br_ufpr_c3sl_estacaojuventude_OrgaoExecutor_municipio" itemValue="id" items="${municipios}" path="/municipios" z="TsmVkI/NlGQHwdhUUjgjQ8bprz4="/> + </form:create> + <form:dependency dependencies="${dependencies}" id="d_br_ufpr_c3sl_estacaojuventude_OrgaoExecutor" render="${not empty dependencies}" z="AAjeOEHmudaMpa7oWwH71C1aVn0="/> +</div> diff --git a/src/main/webapp/WEB-INF/views/municipios/views.xml b/src/main/webapp/WEB-INF/views/municipios/views.xml index 18109b6078f62730d091213fd2a8224931e2cbfb..1f1c7ff965480b36cdfa504cddee3e1df1646805 100644 --- a/src/main/webapp/WEB-INF/views/municipios/views.xml +++ b/src/main/webapp/WEB-INF/views/municipios/views.xml @@ -13,4 +13,7 @@ <definition extends="default" name="municipios/update"> <put-attribute name="body" value="/WEB-INF/views/municipios/update.jspx"/> </definition> + <definition extends="default" name="municipios/selectmunicipios"> + <put-attribute name="body" value="/WEB-INF/views/municipios/selectmunicipios.jspx"/> + </definition> </tiles-definitions> diff --git a/src/main/webapp/WEB-INF/views/orgaoexecutores/create.jspx b/src/main/webapp/WEB-INF/views/orgaoexecutores/create.jspx index d337c41cd01342448967b24745614b789b69812f..980cd2b7d7d7afc6cdde0ac482c5da38d574a7e4 100644 --- a/src/main/webapp/WEB-INF/views/orgaoexecutores/create.jspx +++ b/src/main/webapp/WEB-INF/views/orgaoexecutores/create.jspx @@ -10,11 +10,52 @@ <field:input field="logradouro" id="c_br_ufpr_c3sl_estacaojuventude_OrgaoExecutor_logradouro" z="k/1XFT6R2/obR+osepiqSAJabF8="/> <field:input field="bairro" id="c_br_ufpr_c3sl_estacaojuventude_OrgaoExecutor_bairro" z="C0AhYYllc9NQKj6P/OsWQ/cbgBs="/> <field:input field="cep" id="c_br_ufpr_c3sl_estacaojuventude_OrgaoExecutor_cep" widthcss="65px" z="user-managed"/> + + <field:select field="uf" + id="c_br_ufpr_c3sl_estacaojuventude_Municipio_uf" + itemValue="id" items="${estadoes}" path="/estados" + z="user-managed" + disableFormBinding="true" /> + <field:select field="municipio" id="c_br_ufpr_c3sl_estacaojuventude_OrgaoExecutor_municipio" itemValue="id" items="${municipios}" path="/municipios" z="TsmVkI/NlGQHwdhUUjgjQ8bprz4="/> + <field:input field="contato" id="c_br_ufpr_c3sl_estacaojuventude_OrgaoExecutor_contato" z="N464inkZDRkVnlMA8hpmvvyzs7g="/> <field:datetime dateTimePattern="${orgaoExecutor_ultimaalteracao_date_format}" field="ultimaAlteracao" id="c_br_ufpr_c3sl_estacaojuventude_OrgaoExecutor_ultimaAlteracao" render="false" z="user-managed"/> <field:input field="emailContato" id="c_br_ufpr_c3sl_estacaojuventude_OrgaoExecutor_emailContato" validationMessageCode="field_invalid_email" validationRegex="[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}" z="user-managed"/> <field:input field="telefoneContato" id="c_br_ufpr_c3sl_estacaojuventude_OrgaoExecutor_telefoneContato" mask="(##)####-####" max="13" validationMessageCode="field_invalid_integer" validationRegex="[(][0-9]*[)][0-9]*-[0-9]*" widthcss="85px" z="user-managed"/> </form:create> <form:dependency dependencies="${dependencies}" id="d_br_ufpr_c3sl_estacaojuventude_OrgaoExecutor" render="${not empty dependencies}" z="AAjeOEHmudaMpa7oWwH71C1aVn0="/> + + <script type="text/javascript"> + + Spring.addDecoration(new Spring.ElementDecoration({ + elementId : '_uf_id', + widgetType : "dijit.form.FilteringSelect", + widgetAttrs : { + onChange : function() { + + //ID of the chosen "estado" + 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.open("GET", "orgaoexecutores/"+uf ,false); + 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> + </div>