6 Replies Latest reply on Dec 23, 2007 4:29 PM by Menashe D

    Search entity doesn't need to be validated

    Menashe D Newbie

      After looking at the seam examples and seamgen code on how the search is done. It seams to me that there is a shortcoming in seam, since, seam search uses a new entyty of the search class but if it works only if there are no validation on the class. When this is used with any class that uses validation then validation errors occur.
      Say, a simple person class with just firstname and lastname both are notnull and are 3 to 20 chars long.
      Now, when user searches for any person by lastname 'smith', seam complains that firstname is null or if user tries to search for person with a firstname (that starts with) 'ja' (as in jane or jack) it also complains that the firstname is too short.

      Is there a way do disable the validation?

      Other then creating a duplicate class without validation (since, AFAIK, it is not possible to extend original class and then overwrite the validation annotations there, it can be said that can be done backwards to first create class that will be used for search and then extend it to create an entity class but it doesn't sound like the right approch to me for some reason.) I will like to know what is the best practice in this situation, since this is a very basic issue I am sure many users have delt with it or will be working on it at some later time?

      Thanks for your time.

        • 1. Re: Search entity doesn't need to be validated
          Daniel Young Novice

          I don't use seam-gen, and my project doesn't use entity fields to carry across search values... but I wonder, why would you even have your search fields inside s:validate in your UI?

          "menashe" wrote:
          After looking at the seam examples and seamgen code on how the search is done. It seams to me that there is a shortcoming in seam, since, seam search uses a new entyty of the search class but if it works only if there are no validation on the class. When this is used with any class that uses validation then validation errors occur.
          Say, a simple person class with just firstname and lastname both are notnull and are 3 to 20 chars long.
          Now, when user searches for any person by lastname 'smith', seam complains that firstname is null or if user tries to search for person with a firstname (that starts with) 'ja' (as in jane or jack) it also complains that the firstname is too short.

          Is there a way do disable the validation?

          Other then creating a duplicate class without validation (since, AFAIK, it is not possible to extend original class and then overwrite the validation annotations there, it can be said that can be done backwards to first create class that will be used for search and then extend it to create an entity class but it doesn't sound like the right approch to me for some reason.) I will like to know what is the best practice in this situation, since this is a very basic issue I am sure many users have delt with it or will be working on it at some later time?

          Thanks for your time.


          • 2. Re: Search entity doesn't need to be validated
            Menashe D Newbie

            it is not s:validate it is hibernate validator that is the problem

            • 3. Re: Search entity doesn't need to be validated
              Daniel Young Novice


              From my understanding, you need s:validate to trigger hibernate validator at the JSF level. Otherwise, the validations only trigger when you try to persist an entity? I could be wrong, however.

              Another thing I'd point out is that using an entity for search values only works in the simplest of cases - you can't easily do date ranges, for example.

              "menashe" wrote:
              it is not s:validate it is hibernate validator that is the problem


              • 4. Re: Search entity doesn't need to be validated
                Menashe D Newbie

                date range point well-taken

                "jazir1979" wrote:

                Another thing I'd point out is that using an entity for search values only works in the simplest of cases - you can't easily do date ranges, for example.

                "menashe" wrote:
                it is not s:validate it is hibernate validator that is the problem


                • 5. Re: Search entity doesn't need to be validated
                  Pete Muir Master

                   

                  "jazir1979" wrote:
                  From my understanding, you need s:validate to trigger hibernate validator at the JSF level. Otherwise, the validations only trigger when you try to persist an entity? I could be wrong, however.


                  No, you are completely correct. Don't use s:validate/s:validateAll in your search form, and don't try to persist the entity you are using to hold your search data and it won't be validated.

                  And yes, I found I normally had to do

                  @Name("exampleFoo")
                  public class ExampleFoo extends Foo {
                  
                   private Date startOfDateRange;
                   private Date endOfDateRange;
                   ...
                  


                  when using example entities for searching - you get both the fields from the entities for basic fields and can add extras.

                  I want to get a tutorial into the docs at some point - "Working with your seam-gen'd app" which should include stuff like this.

                  • 6. Re: Search entity doesn't need to be validated
                    Menashe D Newbie

                     

                    "pete.muir@jboss.org" wrote:

                    No, you are completely correct. Don't use s:validate/s:validateAll in your search form, and don't try to persist the entity you are using to hold your search data and it won't be validated.


                    Oh, I was using the template="edit.xhtm" and it has s:validateAll, fix it now.

                    Thank you jazir1979 and pete