S
Stefan Richter
I am connecting to a database, and based on the values of the database
I am dynamically creating checked or unchecked checkboxes.
allTestsList = database.getTests(10);
for (Enumeration el = allTestsList.elements(); el.hasMoreElements();
) {
testBean = (TestBean)el.nextElement();
test = testBean.getTest();
out.println("<INPUT TYPE=CHECKBOX NAME=\""+
testBean.getTestShortName() +"\" ");
if (testBean.hasSignedUp()) {
out.println("CHECKED>");
}
else {
out.println(">");
}
out.println(test);
}
Then the user can check or uncheck them and I want to update the
database again.
For my sql string I first of all need a string that contains all
values seperated by commas and ''.
for (Enumeration el = request.getParameterNames();
el.hasMoreElements(); ) {
String param = (String)el.nextElement();
if (! "submit".equals(param)){
checkedTests += "'"+ param +"', ";
}
}
The problem now is that I will have one comma to much at the end when
I am doing it that way.
What's the best / easiest way to solve that?
Anyway, so I "clean up" like this:
if(checkedTests !=null && !"".equals(checkedTests ) ) {
checkedTests = checkedTests.substring(0, checkedTests.length() -2
);
}
But I think it looks pretty crappy coded.
Any way to do that in a better way?
Thanks,
Stefan
I am dynamically creating checked or unchecked checkboxes.
allTestsList = database.getTests(10);
for (Enumeration el = allTestsList.elements(); el.hasMoreElements();
) {
testBean = (TestBean)el.nextElement();
test = testBean.getTest();
out.println("<INPUT TYPE=CHECKBOX NAME=\""+
testBean.getTestShortName() +"\" ");
if (testBean.hasSignedUp()) {
out.println("CHECKED>");
}
else {
out.println(">");
}
out.println(test);
}
Then the user can check or uncheck them and I want to update the
database again.
For my sql string I first of all need a string that contains all
values seperated by commas and ''.
for (Enumeration el = request.getParameterNames();
el.hasMoreElements(); ) {
String param = (String)el.nextElement();
if (! "submit".equals(param)){
checkedTests += "'"+ param +"', ";
}
}
The problem now is that I will have one comma to much at the end when
I am doing it that way.
What's the best / easiest way to solve that?
Anyway, so I "clean up" like this:
if(checkedTests !=null && !"".equals(checkedTests ) ) {
checkedTests = checkedTests.substring(0, checkedTests.length() -2
);
}
But I think it looks pretty crappy coded.
Any way to do that in a better way?
Thanks,
Stefan