On Tue, 20 Jul 2004 14:59:06 +0530, C.K, Shibin (Cognizant) wrote:
> check this out. i got this from QueryByCriteria class
>
> public Criteria buildCriteria (Object anExample) throws Exception{
> Criteria criteria = new Criteria();
> ClassDescriptor cld = MetadataManager.getInstance
> ().getRepository ().getDescriptorFor (anExample.getClass ());
> FieldDescriptor [] fds = cld.getFieldDescriptions ();
> PersistentField f;
> Object value;
>
> for (int i = 0; i < fds.length; i++){
> f = fds [i].getPersistentField ();
> value = f.get (anExample);
>
> if (value != null){
> criteria.addEqualTo (f.getName (), value);
> }
> }
> }
> return criteria;
> }
> }
> }
> change the addEqualTo to addLike accordingly
>
> shibin
>
> -----Original Message-----
> From: news [mailto:[EMAIL PROTECTED] Behalf Of Mike Young Sent:
> Tuesday, July 20, 2004 2:50 PM
> To: [EMAIL PROTECTED]
> Subject: How to Develop a Search Page using QueryByCriteria
>
>
> I am trying to develop a search page that allows users to input their
> search criteria into a form and after submitting this form the
> application will list all records that match the search criteria.
>
> I currently have a form that captures the users input and places it into
> a bean. The bean is the same bean that i would use for gettting data
> from the table (i.e. it has getters and setters for each column).
>
> Where I need help is in writing a generic class that will build up the
> search criteria using addLike for each property of the bean that is not
> null without individually calling each of the getters and testing
> whether it is null or not before adding its value onto my criteria using
> addlike.
>
> Could anyone please point me in the right direction on how to acheive
> this?
>
> thanks in advance
>
>
>
>
> --------------------------------------------------------------------- To
> unsubscribe, e-mail: [EMAIL PROTECTED] For additional
> commands, e-mail: [EMAIL PROTECTED]
>
>
> This e-mail and any files transmitted with it are for the sole use of
> the intended recipient(s) and may contain confidential and privileged
> information. If you are not the intended recipient, please contact the
> sender by reply e-mail and destroy all copies of the original message.
> Any unauthorised review, use, disclosure, dissemination, forwarding,
> printing or copying of this email or any action taken in reliance on
> this e-mail is strictly prohibited and may be unlawful.
>
> Visit us at http://www.cognizant.com
Thanks for this, its a great guide in the right direction and I am very
grateful for your suggestions and help. I have just tried to use implement
function but I hit a couple of problems.
My Objects contain Strings and an Integer
1) If the string is an empty string (which it always gets set to by jsp if
users don't enter a value) the comparison:
<code> if (value != null){</code> fails because null does not equal
empty string
2)If the value is of type Integer then the statement
<code> criteria.addEqualTo (f.getName (), value); <code>
fails with a ClassCastException
Any further thoughts or ideas ?
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]