This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Five Lines of Code and have Christian Clausen on-line!
See this thread for details.
Win a copy of Five Lines of Code this week in the OO, Patterns, UML and Refactoring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

A method with many parameters.........

 
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I'm creating a query based on values entered by the user. I have 10 input boxes on the jsp page, and correspondingly 10 list boxes. The input boxes will allow them to enter a string value and the list boxes choose filters like "contains","begins with","ends with","equals",not equals". I want to send all the entered string values and filter values to an underlying java class, which will construct a query string depending on what the user enters,and get the resultset. For every input box, I should be having two parameters, one for the string value entered, and one for the filter value chosen. This amounts to a method with 20 PARAMETERS....which makes no sense to me. Is there a better way to approach this ? If they do enter all the values, which is not the usual case, then how can we construct the query string without making it a mile long ?
Suggestions will be veru helpful.
Thanks.
 
mister krabs
Posts: 13974
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, create a class that holds the 20 parameters and pass an object of that class. This will also be useful if later you need to add more parameters. Don't forget your get and set methods for each variable!
 
Mallika Kumar
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot Thomas. I'm trying it out.
 
Mallika Kumar
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Thomas,
I have a class with all 20 parameters. Now, if I have to check and see if each one is null or not(for the 10 input strings), and then construct the query based on the ones which are not null, its getting ugly. I mean, if I have to check for each and every value, then construct the query string,and there definately will be a combination of strings entered each time,then what ? I want to be able to check for null values in the beginning itself, say in the jsp page, and then send only the ones which are not null.What if the first and last parameters have some value, and all the rest are null ?
Am I thinking in the wrong direction here ?
 
Thomas Paul
mister krabs
Posts: 13974
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would send everything along and then check for nulls in the class that will analyze the parameters. The less the JSP knows the better. Besides, you have to check somewhere so why not where the brains of building the query is?
 
We should throw him a surprise party. It will cheer him up. We can use this tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic