-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: ObjectDataSource.SelectMethod with variable number of parms
PostPosted: Thu Dec 08, 2005 5:20 pm 
Newbie

Joined: Thu Dec 08, 2005 4:58 pm
Posts: 2
What would be the best approach to following situation:

GridView is bound to ObjectDataSource via DataSourceID pointing to a processing class. Query to populate ObjectDataSource is based on user-entered criteria, which is then used in HQL by the method associated with ObjectDataSource.SelectMethod.
The problem is - user can choose to use several (or none) different criteria fields. Upon post-back we can custom-tune SelectParameters nad their number, but what do we do with Select method? We can't pass any classes to it, because Parameter accepts only primitive types (and even those are in a string format). This leaves us with either declaring multiple Select methods for all possible number of parameters or encode all parameters into some class and serialize it to string. Both approaches seem ugly - any suggestions?

On a same note - what do you, guys, usually do to indicate names of named HQL arguments - pass names as a separate parameter?

TIA,

Sam


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 09, 2005 11:27 am 
Newbie

Joined: Sun Sep 25, 2005 9:11 am
Posts: 13
Location: Bergen, Norway
You can pass references to objects with ObjectDataSource. Add an eventhandler to ObjectDataSource.Selecting, and pass the reference there.

For example:

Code:
protected void ObjectDataSource1_Selecting(object sender, ObjectDataSourceSelectingEventArgs e)
{
    e.InputParameters["paramName"] = someObject;
}


Both Select and SelectCount will trigger this event.

About HQL. IMHO, you shouldnt use HQL to do this select. Check out the ICriteria API, which is much easier to work with when you are dealing with multiple search criterias. Building strings is just bad. :)


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 12, 2005 11:08 am 
Newbie

Joined: Thu Dec 08, 2005 4:58 pm
Posts: 2
Thank you - works great.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.