Last active
April 6, 2021 12:21
-
-
Save kauanmocelin/39e684e2386bd79d875833b2767092f0 to your computer and use it in GitHub Desktop.
[Atualizar lista request e tratar mensagem de erro no response] #struts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public ActionForward adicionarEtiqueta(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws IOException, ApplicationException { | |
try{ | |
setActionForward(mapping.findForward("pgAjaxEtiqueta")); | |
String etiqueta = request.getParameter("etiqueta"); | |
// Inicio Validações | |
if(StringUtils.isBlank(etiqueta)){ | |
throw new ApplicationException("errors.required",new String[]{"Etiqueta"}, ApplicationException.ICON_AVISO); | |
} | |
if (StringUtils.isNotBlank(etiqueta) && etiqueta.length() > 10) { | |
throw new ApplicationException("errors.maxlength",new String[]{"Etiqueta","100"}, ApplicationException.ICON_AVISO); | |
} | |
// Fim Validações | |
SortedSet<String> listaEtiquetasDocumento = null; | |
if (request.getSession().getAttribute(LISTA_ETIQUETAS_DOCUMENTO) != null) { | |
listaEtiquetasDocumento = (SortedSet<String>) request.getSession().getAttribute(LISTA_ETIQUETAS_DOCUMENTO); | |
} else { | |
listaEtiquetasDocumento = new TreeSet<String>(); | |
} | |
listaEtiquetasDocumento.add(etiqueta); | |
request.getSession().setAttribute(LISTA_ETIQUETAS_DOCUMENTO, listaEtiquetasDocumento); | |
return getActionForward(); | |
} catch (Exception e) { | |
setActionForward(null); | |
response.setStatus(HttpServletResponse.SC_BAD_REQUEST); | |
response.getWriter().append(e.getMessage()); | |
throw new ApplicationException(e); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment