1 Reply Latest reply on May 14, 2008 12:07 PM by Pete Muir

    Problem implementing search features with EntityQuery Object

    Joe Dean Newbie

      I'm implementing a feature where a user enters a search string and it uses this to query the database to filter the list of objects returned in the UI table.  (Exactly like the hotelSearch.find() feature in the booking example.)  The problem is when I use the EntityQuery object I cannot retrieve all 'hotels' by submitting an empty search string.  This is because of the following method in the Query object:


      protected boolean isRestrictionParameterSet(Object parameterValue)
         {
            return parameterValue!=null && !"".equals(parameterValue);
         }



      So, I got my code to work by overriding this method in my subclass as follows:


      @Override
      protected boolean isRestrictionParameterSet(Object parameterValue)
         {
            return parameterValue!=null;
         }



      Note: Not sure if this is relevant, but I'm referencing my searchString directly in the getEjbql() method instead of in the RESTRICTIONS variable via EL value
        This is because I need to search across many different DB attributes. For example: first name, last name, address, etc) so an OR is required instead of an AND in my query.


      My question:


        Why does isRestrictionParameterSet consider an empty string an unset parameter value?  Will overriding this method cause problems for me?

        • 1. Re: Problem implementing search features with EntityQuery Object
          Pete Muir Master

          The problem is when I use the EntityQuery object I cannot retrieve all 'hotels' by submitting an empty search string.


          Why does isRestrictionParameterSet consider an empty string an unset parameter value? Will overriding this method cause problems for me?

          You need the restriction parameter to be omitted to search all hotels. Otherwise you would be restricting your search!



          Not sure if this is relevant, but I'm referencing my searchString directly in the getEjbql() method instead of in the RESTRICTIONS variable via EL value

          And probably leaving yourself open to SQL injection.