java - How to store values that dynamic column generated based on which on table and pass to querystring -
my title might not clear enough, let me explain senario first. have dropdownlist fetches table list table. if choose 1 of tables, show columns following code:
<% string columnsql = "select column_name columnname information_schema.columns " + "where table_name = '"+ tablename + "' order ordinal_position"; printdebug.println("table:" + tablename); resultset myrs = adbmanager.retrieverec(columnsql); int count =0; //string[] arraycolumn; //boolean[] arraycheckbox; //string[] arraysearch; while (myrs2.next()) { columnname = myrs2.getstring("columnname"); //printdebug.println("column"+count+": " + columnname); %> <label id="lblcolumnname<%=count %>" value=<%=columnname%>> <%=columnname%></label> <input id="chkcheckbox<%=count %>" type="checkbox" value=<%=columnname %>> <input id="txtsearch<%=count %>" type="text"> <br> <% count++; } myrs2.close(); %>
so code above generate every column in table selected. use javascript refresh onchanged.
question here: how should store columns, irrespective of whether checkbox checked or not, , search textbox in querystring.
sorry poor english, confusing find out logic should use on dynamic generate , store passing others page/servlet processing querystring checkbox checked or not decide show column or not, search textbox "" or got value filtering.
was thinking solution array, possible when come dynamic? because have retrieve on other side process query. thanks.
from have understood, if column checked want column name , respective value thing when form submitted.
add name
both check box , text field.
<input id="chkcolumn<%=count %>" name="columnnames" type="checkbox" value=<%=columnname %>> <input id="txtsearch<%=count %>" name="val_<%=columnname%>" type="text">
also, add table name hidden parameter. so, submitted
<input type="hidden" name="tablename" value="<%=tablename%>" />
now, when form gets submit in servlet / jsp (not recommended).
you can access checked check boxes
string tablename = request.getparametervalues('tablename'); string[] colnames=request.getparametervalues('columnnames');
process each item in array , search value each column like
string strprefix = "val_"; string strval = strprefix + colnames [0]; // value each column
Comments
Post a Comment