Link to home
Start Free TrialLog in
Avatar of Fors
ForsFlag for United Arab Emirates

asked on

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
Avatar of arun_kuttz
arun_kuttz

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
ASKER CERTIFIED SOLUTION
Avatar of fargo
fargo

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Fors

ASKER

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.