• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1713
  • Last Modified:

Nested Dynamic variable names (Checkboxes & List boxes)

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.close();
    rsSubCnt = null;
  }
  incSvs = "subcategory"+rs.getString("id");
  out.println("<hr>incSvs : " + incSvs);
   if (myCnt>0 && isChecked) {
   db.inquire(sqlStrSub);
      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")+"";
           sts=sts+"</option>";
      }
          sts=sts+"</select><br>";
          //out.println("substids = "+rsSub.getString("selected").equals("Y"));
      rsSub.close();
      rsSub=null;
  }

}
      rs.close();
      rs=null;
  }

Thank you in advance
0
Fors
Asked:
Fors
1 Solution
 
arun_kuttzCommented:
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 ?

-KuTtZ
0
 
fargoCommented:
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[] ??
0
 
ForsProject ManagerAuthor Commented:
fargo:
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.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now