Advertisement
Guest User

Untitled

a guest
Mar 31st, 2015
216
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 KB | None | 0 0
  1. package br.com.espacobrasil.converter;
  2.  
  3. import javax.faces.component.UIComponent;
  4. import javax.faces.context.FacesContext;
  5. import javax.faces.convert.Converter;
  6. import javax.faces.convert.FacesConverter;
  7.  
  8. /**
  9. * <b>Converter para CPF.</b>
  10. *
  11. * @author Dilnei Cunha
  12. */
  13. @FacesConverter("cpfConverter")
  14. public class CPFConverter implements Converter {
  15.  
  16. /**
  17. * <b>Método que remove a mascara do CPF.</b>
  18. *
  19. * @param facesContext
  20. * @param uIcomponent
  21. * @param cpf
  22. * @return Object
  23. */
  24. @Override
  25. public Object getAsObject(FacesContext facesContext, UIComponent uIcomponent, String cpf) {
  26. if (cpf.trim().equals("")) {
  27. return null;
  28. } else {
  29. cpf = cpf.replace("-", "");
  30. cpf = cpf.replace(".", "");
  31. return cpf;
  32. }
  33. }
  34.  
  35. /**
  36. * <b>Método que retorna a String do CPF.</b>
  37. *
  38. * @param facesContext
  39. * @param uIcomponent
  40. * @param object
  41. * @return String
  42. */
  43. @Override
  44. public String getAsString(FacesContext facesContext, UIComponent uIcomponent, Object object) {
  45. return object.toString();
  46. }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement