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.
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!
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 ?
posted 19 years ago
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?