Announcement Announcement Module
Collapse
No announcement yet.
finders with nullable arguments Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • finders with nullable arguments

    Hi All

    is there a way to generate finders that accept a null able arguments for example
    Code:
    findFooByBarEqualsAndTarNotEquals(String bar, String Tar)
    returns all Foos that have bar == "test" when call
    Code:
    findFooByBarEqualsAndTarNotEquals("test" , null);
    instead of throwing IllegalArgumentException

  • #2
    BzOne,

    I am not quite sure I understand your use case but you can check for attributes that are null by using finders which use 'IsNull'

    So in your case that would look like so:

    Code:
    findFooByBarEqualsAndTarIsNull(String bar)
    That should return all Foos which have the specified bar (that equals to "test" for example) and where Tar is null.

    Cheers,
    Stefan

    Comment


    • #3
      Hi Stefan

      actually this is not what I meant the following use case may make it clear

      I need a search form has 2 inputs bar and Tar and searches for Foo
      if I entered Bar only it will show Foos with bar = form bar value
      and if I entered Tar it well show Foos with tar = form tar value
      and if I entered both bar and tar it well return Foos with bar and tar = form bar and tar values

      my problem is the finder
      Code:
      findFooByBarEqualsAndTarEquals(String bar, String tar)
      wont allow null parameter

      i've work around by using 3 finders

      Code:
      findFooByBarEquals(String bar)
      findFooByTarEquals(String tar)
      findFooByBarEqualsAndTarEquals(String bar, String tar)
      and the controller choose between them depending on the received form parameter

      but things got messy with forms that have 3 or more search parameters
      and I still need to create the form and controller method myself

      Comment

      Working...
      X