This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
Help please! I have a form where the user checks any or all of 6 boxes, I then need to take the user's choices and use them in a SELECT statement in a query. the JSP looks like: <table border="2" style="background-color:#FFFF99;"> <tr> <TD WIDTH=85% ALIGN="LEFT"> <B>Check Departments To Include:</B><br> <INPUT TYPE=CHECKBOX NAME="dept" VALUE="csr">Customer Service<br> <INPUT TYPE=CHECKBOX NAME="dept" VALUE="clm">Claims<br> <INPUT TYPE=CHECKBOX NAME="dept" VALUE="bne">Billing & Enrollment<br> <INPUT TYPE=CHECKBOX NAME="dept" VALUE="adj">Adjustments<br> <INPUT TYPE=CHECKBOX NAME="dept" VALUE="apl">Appeals<br> <INPUT TYPE=CHECKBOX NAME="dept" VALUE="sub">Subrogation<br> <INPUT TYPE=CHECKBOX NAME="dept" VALUE="acg">Accounting<br> </td></tr> </table> This is passed to a controller, which then calls a method which contains the following select statement: sql.append("SELECT bla, bla, bla FROM bla, bla, bla"); sql.append("WHERE ( dept_code IN (?);
The selected department codes would replace the question mark. It seems like this should be easy, right? All help is Greatly appreciated!
each checkbox needs it own name if your going to allow more than one to be checked. then you use getParameter and if it returns something then they checked it and if it returns null then they didnt. then use a prepared statement to set the boolean value in your SQL
Kim Jong II (North Korea's Dear Leader) said:Nuclear weapons don't kill people, people kill people.
I'd change the following line: each checkbox needs it own name if your going to allow more than one to be checked. to: if you want to make retrieval easy, give each checkbox its own name
but then again, based on my last paragraph, this should be: sometimes retrieval is easier when giving each checkbox its own name - other times it's not
It's not a requirement to give mutually selectable checkboxes different names (unlike radio buttons).
You'd just have to make each checkbox value be the primary key of the department, and append it into the "in clause" string you're constructing
In fact, that might be easier, than requesting each and every department, and having to decide whether to include it or not (which you'd need to do if each checkbox had a different name). Also, if you add a department, you'd need to change the processing jsp. With checkbox of the same name, only the initial list of departments need change. [ December 05, 2003: Message edited by: Mike Curwen ]
If you need to have the full names of what the checkboxes mean, in the second page... that second page will query the database to retrieve the full name. If you weren't loading them from a database, then just use a bunch of if statements.
(This was prompted by a private message from the original poster: who has private messages turned off).
Joined: Nov 18, 2003
Yes, the full names are not coming from a database. Looks like I'll have to go with the multiple "if" statements. Thanks for your help.
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com
subject: Passing checkbox data from JSP to SELECT statement