Results 1 to 3 of 3

Thread: finders with nullable arguments

  1. #1
    Join Date
    Jun 2009
    Posts
    5

    Default 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. #2
    Join Date
    Mar 2008
    Location
    Sydney, AU
    Posts
    974

    Default

    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

  3. #3
    Join Date
    Jun 2009
    Posts
    5

    Default

    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •