Fors
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.getPar ameterStri ngs(subsrv s_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).toSt ring();
String subsrvs_S = "subcategory"+business_val ues; // Create the dynamic name
String subsrvs_id[] = Utils.removeNull(uf.getPar ameterStri ngs(subsrv s_S));
for (int j = 0;subsrvs_id!=null && j < subsrvs_id.length && subsrvs_id[j]!=null; j++) {
db.insert("insert into bid_service_type"+tableVer sion+"(bid _id,servic e_type_id, subservice _type_id)v alues("+id +","+ business_values+","+subsrv s_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.getS tring("id" )+",")>=0) {
sts=sts+" checked";
isChecked = true;
}
sts=sts+"> "+rs.getString("service_ty pe_name")+ "<br>";
/* CREATE LIST BOXES */
sqlStrSub = "select id,service_type_id,subserv ice_type_n ame, selected ";
sqlStrSub= sqlStrSub + "from subservice_type"+tableVers ion+" where service_type_id="+rs.getSt ring("id") ;
sqlStrSubCnt = "select count(*) as myCnt ";
sqlStrSubCnt= sqlStrSubCnt + "from subservice_type"+tableVers ion+" where ";
sqlStrSubCnt= sqlStrSubCnt + "service_type_id="+rs.getS tring("id" );
//out.println("<br>sqlStrS ubCnt: " + 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("i d");
if ((substids.indexOf(","+rsS ub.getStri ng("id")+" ,")>=0) && (isSelected.equals("Y"))) {
sts=sts+" selected";
}
sts=sts+"> "+rsSub.getString("subserv ice_type_n ame")+"";
sts=sts+"</option>";
}
sts=sts+"</select><br>";
//out.println("substids = "+rsSub.getString("selecte d").equals ("Y"));
rsSub.close();
rsSub=null;
}
}
rs.close();
rs=null;
}
Thank you in advance
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.getPar
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).toSt
String subsrvs_S = "subcategory"+business_val
String subsrvs_id[] = Utils.removeNull(uf.getPar
for (int j = 0;subsrvs_id!=null && j < subsrvs_id.length && subsrvs_id[j]!=null; j++) {
db.insert("insert into bid_service_type"+tableVer
}
}
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
ResultSet rs = db.getResultSet();
while (rs.next()) {
sts=sts+"<input name=x_service_type type=checkbox value="+rs.getString("id")
if (stids.indexOf(","+rs.getS
sts=sts+" checked";
isChecked = true;
}
sts=sts+"> "+rs.getString("service_ty
/* CREATE LIST BOXES */
sqlStrSub = "select id,service_type_id,subserv
sqlStrSub= sqlStrSub + "from subservice_type"+tableVers
sqlStrSubCnt = "select count(*) as myCnt ";
sqlStrSubCnt= sqlStrSubCnt + "from subservice_type"+tableVers
sqlStrSubCnt= sqlStrSubCnt + "service_type_id="+rs.getS
//out.println("<br>sqlStrS
if(db.inquire(sqlStrSubCnt
ResultSet rsSubCnt = db.getResultSet();
if (rsSubCnt.next()){
myCnt = rsSubCnt.getInt("myCnt");
}
rsSubCnt.close();
rsSubCnt = null;
}
incSvs = "subcategory"+rs.getString
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("i
if ((substids.indexOf(","+rsS
sts=sts+" selected";
}
sts=sts+"> "+rsSub.getString("subserv
sts=sts+"</option>";
}
sts=sts+"</select><br>";
//out.println("substids = "+rsSub.getString("selecte
rsSub.close();
rsSub=null;
}
}
rs.close();
rs=null;
}
Thank you in advance
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.
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.
-KuTtZ