Esempio n. 1
0
 public void validatePhoneOrEmail(FacesContext ctx, UIComponent toValidate, Object value) {
   if (value != null
       && parsePhone(value.toString()) == null
       && parseEmail(value.toString()) == null) {
     ((UIInput) toValidate).setValid(false);
     ctx.addMessage(
         toValidate.getClientId(ctx),
         Bundles.Common.message(FacesMessage.SEVERITY_ERROR, "error.phoneOrEmail.malformed"));
   }
 }
Esempio n. 2
0
 public void validateUsername(FacesContext ctx, UIComponent toValidate, Object value) {
   if (!currentPlayer.getName().equals(value)) {
     String username = value.toString();
     try {
       new MessageFormat(Bundles.Common.message("reg.newbie.login")).parse(username);
       ((UIInput) toValidate).setValid(false);
       ctx.addMessage(
           toValidate.getClientId(ctx),
           Bundles.Common.message(FacesMessage.SEVERITY_ERROR, "error.username.reserved"));
     } catch (ParseException e) {
       if (cem.findByAttribute(Player_.name, username) != null) {
         ((UIInput) toValidate).setValid(false);
         ctx.addMessage(
             toValidate.getClientId(ctx),
             Bundles.Common.message(FacesMessage.SEVERITY_ERROR, "error.username.occupied"));
       }
     }
   }
 }