View Full Version : finders with nullable arguments
BzOne
Nov 12th, 2009, 02:06 PM
Hi All
is there a way to generate finders that accept a null able arguments for example
findFooByBarEqualsAndTarNotEquals(String bar, String Tar) returns all Foos that have bar == "test" when call
findFooByBarEqualsAndTarNotEquals("test" , null);
instead of throwing IllegalArgumentException
Stefan Schmidt
Nov 12th, 2009, 03:53 PM
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:
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
BzOne
Nov 12th, 2009, 04:59 PM
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
findFooByBarEqualsAndTarEquals(String bar, String tar)
wont allow null parameter
i've work around by using 3 finders
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
Powered by vBulletin® Version 4.2.1 Copyright © 2013 vBulletin Solutions, Inc. All rights reserved.