Nested Dynamic variable names (Checkboxes & List boxes)

Posted on 2006-05-02
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 ( {
                               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 ({
    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 ( {
      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
    LVL 3

    Expert Comment

    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

    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[] ??
    LVL 3

    Author Comment

    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

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    Not sure what the best email signature size is? Are you worried about email signature image size? Follow this best practice guide.
    Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
    Sending a Secure fax is easy with eFax Corporate ( First, Just open a new email message.  In the To field, type your recipient's fax number You can even send a secure international fax — just include t…
    This video discusses moving either the default database or any database to a new volume.

    730 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

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now