1 Reply Latest reply on Jul 26, 2007 10:56 AM by valtoni

    Validator in Bean

    demetrio812

      Hi,
      I'm using Seam 2.0 B1, I wrote a validator function in a seam managed bean (stateful), this is the code:

       public void validaEmailNewsletter(FacesContext context, UIComponent toValidate, Object value) {
       if (isEmailInserita((String)value)) { // se c'è già
       FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_ERROR, "Attenzione: l'indirizzo email è già stato registrato", "Attenzione: l'indirizzo email è già stato registrato");
       throw new ValidatorException(message);
       }
       }
      


      validation works good but the only problem is that the message is very verbose and not only with my personalized message and it's like it happens a EJBTransactionRolledbackException, it looks like:

      /home.xhtml @96,280 validator="#{newsletterHelper.validaEmailNewsletter}": javax.ejb.EJBTransactionRolledbackException: Attenzione: l'indirizzo email è già stato registrato

      What's the problem?

      Thanks

      Demetrio Filocamo

        • 1. Re: Validator in Bean
          valtoni

           

          "demetrio812" wrote:
          Hi,
           public void validaEmailNewsletter(FacesContext context, UIComponent toValidate, Object value) {
           if (isEmailInserita((String)value)) { // se c'è già
           FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_ERROR, "Attenzione: l'indirizzo email è già stato registrato", "Attenzione: l'indirizzo email è già stato registrato");
           throw new ValidatorException(message);
           }
           }
          



          Demetrio, don't use throws in methods exposed in Seam context session: jsf catch this exception and the enviroment will catch this, showing the page error wich you post here. You must throw exception like a "Blog Application", wich come with seam distribution; you must declare the Throwable class, like the example:

          @ApplicationException(rollback=true)
          @HttpError(errorCode=HttpServletResponse.SC_NOT_FOUND)
          public class EntryNotFoundException extends Exception
          {
           EntryNotFoundException(String id)
           {
           super("entry not found: " + id);
           }
          }


          and mark your method like

           public void validaEmailNewsletter(FacesContext context, UIComponent toValidate, Object value) throws EntryNotFoundException
          


          And demark your right annotations to be rightly redirected. Ok?