[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now


Nested Dynamic variable names (Checkboxes & List boxes)

Posted on 2006-05-02
Medium Priority
Last Modified: 2012-06-21
Hi Experts,
I have a JSP page that populates Checkboxes dynamically from the database the for each checkbox there is a listbox (multiple selection is available).
The error I am receiving is this:

Incompatible type for method. Can't convert java.lang.String[] to java.lang.String.
String subsrvs_id[] = Utils.removeNull(uf.getParameterStrings(subsrvs_S));

While I am trying to read the arrays like this:
// uf is an upload file class and getParameterStrings is used to read getParameterValues
// I have another getParameterValues that returns an ArrayList instead of an array[]

  for (int i = 0; i < x_service_type.size(); i++) {
    String business_values = x_service_type.get(i).toString();
    String subsrvs_S = "subcategory"+business_values; // Create the dynamic name
    String subsrvs_id[] = Utils.removeNull(uf.getParameterStrings(subsrvs_S));
      for (int j = 0;subsrvs_id!=null && j < subsrvs_id.length && subsrvs_id[j]!=null; j++) {
        db.insert("insert into bid_service_type"+tableVersion+"(bid_id,service_type_id,subservice_type_id)values("+id+","+ business_values+","+subsrvs_id[j]+")");

This is so urgent; I would really appreciate any help or ideas

If you need further explanation please let me know.

Here is my code that has the check boxes and list boxes:

  String sqlStrSub = "";
  String sqlStrSubCnt ="";
  int myCnt = 0;
  String incSvs = "";
  boolean isChecked = false;
  String isSelected = "";

/*    CREATE CHECK BOXES      */

   if (db.inquire("select id,service_type_name from service_type"+tableVersion+" where visible='Y' order by service_type_name")) {
      ResultSet rs = db.getResultSet();
      while (rs.next()) {
                               sts=sts+"<input name=x_service_type type=checkbox value="+rs.getString("id");
          if (stids.indexOf(","+rs.getString("id")+",")>=0) {
          sts=sts+" checked";
          isChecked = true;
           sts=sts+"> "+rs.getString("service_type_name")+"<br>";

/*    CREATE LIST BOXES      */

  sqlStrSub = "select id,service_type_id,subservice_type_name, selected ";
  sqlStrSub= sqlStrSub + "from subservice_type"+tableVersion+" where service_type_id="+rs.getString("id");

  sqlStrSubCnt = "select count(*) as myCnt ";
  sqlStrSubCnt= sqlStrSubCnt + "from subservice_type"+tableVersion+" where ";
  sqlStrSubCnt= sqlStrSubCnt + "service_type_id="+rs.getString("id");
  //out.println("<br>sqlStrSubCnt: " + sqlStrSubCnt);
  if(db.inquire(sqlStrSubCnt)) {
    ResultSet rsSubCnt = db.getResultSet();
    if (rsSubCnt.next()){
    myCnt = rsSubCnt.getInt("myCnt");
    rsSubCnt = null;
  incSvs = "subcategory"+rs.getString("id");
  out.println("<hr>incSvs : " + incSvs);
   if (myCnt>0 && isChecked) {
      ResultSet rsSub = db.getResultSet();
      //rsSub = db.getResultSet();
      sts=sts+" <select multiple name="+incSvs+">";
      sts=sts+"<option value=\"0\">Select One</option>";
      while (rsSub.next()) {
      isSelected = rsSub.getString("selected");
                               sts=sts+"<option value="+rsSub.getString("id");
  if ((substids.indexOf(","+rsSub.getString("id")+",")>=0) && (isSelected.equals("Y"))) {
            sts=sts+" selected";
           sts=sts+"> "+rsSub.getString("subservice_type_name")+"";
          //out.println("substids = "+rsSub.getString("selected").equals("Y"));


Thank you in advance
Question by:Fors

Expert Comment

ID: 16593027
Tell me something bout the Utils class. More specifically bout the removeNull() API. give some info on the "uf" objects Class. Could you please give the stack trace of the exception as well ?

LVL 11

Accepted Solution

fargo earned 2000 total points
ID: 16593833
String subsrvs_id[] = Utils.removeNull(uf.getParameterStrings(subsrvs_S));

the Utils class removeNull method accepts a String parameter and you are passing the String[] to it.
Is it that uf.getParameterStrings(subsrvs_S) returns String[] ??

Author Comment

ID: 16605076
You are absolutely right; I took that class for granted as I use almost with every thing. Thank you soooooooooooooooooooooo much.
I am not receiving the error any more; that does not mean that my code is doing what I want but close.
The problem now that it is not going inside the loop at all.

Featured Post


Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Often times it's very very easy to extend a volume on a Linux instance in AWS, but impossible to shrink it. I wanted to contribute to the experts-exchange community a way of providing a procedure that works on an AWS instance. It can also be used on…
Strategic internal linking is often considered an SEO power technique, especially for content marketing. Do you need to hire an SEO agency to optimize you internal linking? No, this article will help you understand the basics of internal linking and…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Suggested Courses

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question