{"id":16676,"date":"2024-07-01T09:52:52","date_gmt":"2024-07-01T15:52:52","guid":{"rendered":"https:\/\/sada.services\/?p=16676"},"modified":"2024-07-01T10:53:19","modified_gmt":"2024-07-01T16:53:19","slug":"sigesa-validaciones-en-bean","status":"publish","type":"post","link":"https:\/\/sada.services\/?p=16676","title":{"rendered":"SIGESA: Validaciones en Bean"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">Tipo 1: Validaci\u00f3n tipo required<\/h2>\n\n\n\n<figure class=\"wp-block-image size-large\"><img fetchpriority=\"high\" decoding=\"async\" width=\"1024\" height=\"254\" src=\"https:\/\/sada.services\/wp-content\/uploads\/2024\/07\/Captura-de-pantalla-2024-07-01-155302-1024x254.png\" alt=\"\" class=\"wp-image-16678\" srcset=\"https:\/\/sada.services\/wp-content\/uploads\/2024\/07\/Captura-de-pantalla-2024-07-01-155302-1024x254.png 1024w, https:\/\/sada.services\/wp-content\/uploads\/2024\/07\/Captura-de-pantalla-2024-07-01-155302-300x74.png 300w, https:\/\/sada.services\/wp-content\/uploads\/2024\/07\/Captura-de-pantalla-2024-07-01-155302-768x191.png 768w, https:\/\/sada.services\/wp-content\/uploads\/2024\/07\/Captura-de-pantalla-2024-07-01-155302.png 1286w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Para mostrar mensajes de error de tipo requiered (Cuadro rojo)<\/li>\n\n\n\n<li>Vamos a hacer un ejemplo de la fecha final no puede ser anterior a la fecha inicial<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">objetivoOperativoAnualInstitucionalEditForm.xhtml<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Asi queda fecha inicial<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;!-- Fecha Inicial -->\n                    &lt;p:outputLabel id=\"fechaInicialOutputLabel\"\n                                   for=\"fechaInicialCalendar\"\n                                   value=\"#{i18n.objetivoPOAI_fechaInicial_label}\" \/>\n                    &lt;p:outputPanel id=\"fechaInicialOutputPanel\">\n                        &lt;p:calendar id=\"fechaInicialCalendar\"\n                                    value=\"#{objetivoPOAIBean.metaPOAI.fechaInicial}\"\n                                    required=\"#{not empty param&#91;agregar.clientId]}\"\n                                    showOn=\"button\"\n                                    locale=\"es\"\n                                    pattern=\"dd\/MM\/yyyy\"\n                                    navigator=\"true\"\n                                    timeZone=\"America\/Costa_Rica\"\n                                    mindate=\"#{objetivoPOAIBean.calendarioFechaInicio}\"\n                                    maxdate=\"#{objetivoPOAIBean.calendarioFechaFin}\">\n                            &lt;p:ajax event=\"dateSelect\"\n                                    process=\"@this\" \n                                    listener=\"#{objetivoPOAIBean.onFechaInicialSelect}\"\n                                    update=\"fechaFinalCalendar\"\/>\n                        &lt;\/p:calendar>\n                    &lt;\/p:outputPanel>\n                    &lt;p:message id=\"fechaInicialMessage\"\n                               for=\"fechaInicialCalendar\" \/><\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Aqui lo que destaca es que debemos hacer un metodo que cuando se seleccione una fecha incial limpie la fecha final <\/li>\n\n\n\n<li>Y ademas que actualice el componente fecha final<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;p:ajax event=\"dateSelect\"\n                                    process=\"@this\" \n                                    listener=\"#{objetivoPOAIBean.onFechaInicialSelect}\"\n                                    update=\"fechaFinalCalendar\"\/><\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li>El componente de fecha final queda as\u00ed <\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;!-- Fecha Final -->\n                    &lt;p:outputLabel id=\"fechaFinalOutputLabel\"\n                                   for=\"fechaFinalCalendar\"\n                                   value=\"#{i18n.objetivoPOAI_fechaFinal_label}\" \/>\n                    &lt;p:outputPanel id=\"fechaFinalOutputPanel\">\n                        &lt;p:calendar id=\"fechaFinalCalendar\"\n                                    value=\"#{objetivoPOAIBean.metaPOAI.fechaFinal}\"\n                                    required=\"#{not empty param&#91;agregar.clientId]}\"\n                                    showOn=\"button\"\n                                    locale=\"es\"\n                                    pattern=\"dd\/MM\/yyyy\"\n                                    navigator=\"true\"\n                                    timeZone=\"America\/Costa_Rica\"\n                                    mindate=\"#{objetivoPOAIBean.calendarioFechaInicio}\"\n                                    maxdate=\"#{objetivoPOAIBean.calendarioFechaFin}\"\n                                    disabled=\"#{empty objetivoPOAIBean.metaPOAI.fechaInicial}\"\n                                    >\n                            &lt;p:ajax event=\"dateSelect\"\n                                    process=\"@this, @form\" update=\"fechaFinalMessage\" \/>\n                            &lt;f:validator binding=\"#{objetivoPOAIBean.fechaFinalValidator}\" \/>\n                        &lt;\/p:calendar>\n                    &lt;\/p:outputPanel>\n                    &lt;p:message id=\"fechaFinalMessage\"\n                               for=\"fechaFinalCalendar\" \/><\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Aqu\u00ed lo que destaca es que que cuando se seleccione una fecha actuilice el mensaje <\/li>\n\n\n\n<li>Y ademas la creaci\u00f3n de un validator binding <\/li>\n\n\n\n<li>Y que este deshabilitado hasta que se seleccione una fecha inicio <\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>disabled=\"#{empty objetivoPOAIBean.metaPOAI.fechaInicial}\"\n\n&lt;p:ajax event=\"dateSelect\"\n                                    process=\"@this, @form\" update=\"fechaFinalMessage\" \/>\n\n&lt;f:validator binding=\"#{objetivoPOAIBean.fechaFinalValidator}\" \/><\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">ObjetivoPOAIBean.java<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Aqu\u00ed agregamos los imports necesarios<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>import java.util.Date;\nimport javax.faces.application.FacesMessage;\nimport javax.faces.event.AjaxBehaviorEvent;\nimport javax.faces.validator.ValidatorException;\nimport javax.faces.validator.Validator;\nimport javax.faces.component.UIComponent;<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Metodos<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>public Validator getFechaFinalValidator() {\n\n        ObjetivoPOAIBean bean = this;\n        \n        return new Validator() {\n            @Override\n            public void validate(FacesContext context, UIComponent component, Object value) throws ValidatorException {\n                Date fechaFinal = (Date) value;\n                Date fechaInicial = bean.getMetaPOAI().getFechaInicial();\n\n                if (fechaInicial != null &amp;&amp; fechaFinal != null &amp;&amp; fechaFinal.before(fechaInicial)) {\n                    FacesMessage msg = new FacesMessage(FacesMessage.SEVERITY_ERROR, \"Fecha final no puede ser anterior a la fecha inicial\", null);\n                    throw new ValidatorException(msg);\n                }\n            }\n        };\n    }\n\n    public void onFechaInicialSelect(AjaxBehaviorEvent event) {\n        \/\/ Al Seleccionar una fecha Inicial limpiamos la fecha final\n        this.getMetaPOAI().setFechaFinal(null);\n    }<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Tipo 1: Validaci\u00f3n tipo required objetivoOperativoAnualInstitucionalEditForm.xhtml ObjetivoPOAIBean.java<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[443],"tags":[632,633,465],"class_list":["post-16676","post","type-post","status-publish","format-standard","hentry","category-sigesa","tag-bean","tag-requiered","tag-validacion-2"],"blocksy_meta":[],"_links":{"self":[{"href":"https:\/\/sada.services\/index.php?rest_route=\/wp\/v2\/posts\/16676","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/sada.services\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/sada.services\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/sada.services\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/sada.services\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=16676"}],"version-history":[{"count":2,"href":"https:\/\/sada.services\/index.php?rest_route=\/wp\/v2\/posts\/16676\/revisions"}],"predecessor-version":[{"id":16679,"href":"https:\/\/sada.services\/index.php?rest_route=\/wp\/v2\/posts\/16676\/revisions\/16679"}],"wp:attachment":[{"href":"https:\/\/sada.services\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=16676"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/sada.services\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=16676"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/sada.services\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=16676"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}