Code to build dropbox with java online help

Asked By 10 points N/A Posted on -
qa-featured

I want to build a dropbox with java. Can I get help online? I don't just want the code. I need the explanation as well, a sort of a tutorial so that I understand the code, and use it myself in the future.

SHARE
Answered By 5 points N/A #135483

Code to build dropbox with java online help

qa-featured

 

You can include below code in a CSS file.
 
.classTableRowColor{
 background-color:#E0E0DC;
}
 
 
You can include below code in a JSP file.
 
<select class="classTableRowColor" name="selectCprType" id="selectCprType" onchange="javascript:submitform();">
 <option class="classFontNormal" value="-1">—Select—</option>                     
 <option class="classFontNormal"  value="1"> New Facility </option>
 <option class="classFontNormal"  value="2"> Re-New Facility </option>
 <option class="classFontNormal"  value="3"> Addition Facility </option>    
</select> 
 
classTableRowColor , classFontNormal :  included in the CSS file.
selectCprType : drop down box identification.
onchange="javascript:submitform();" : when selecting an option from the drop down box we can add a JavaScript to performe.
 
 
Instead of hard coding, we can get values from a table like MySQL database table
& then you can fill up those values into a vector.
Then in the JSP page, by using a for loop, you can retrieve those values 
and display in the drop down box. Here is an example code.
 
 
Below is the example method which retrieves data from MySQL Database table
and fill into a vector. 
    
public Vector getCPRTypesAll() throws DasException {
     
    String sql;
    ResultSet rs;
    PreparedStatement stmt1;
    Vector vList;
    sql = "";
    rs = null;
    stmt1 = null;
    CPRType cprType = null;
    vList = new Vector();
    try
    {
        con = dbConnect.getConnection();
 
        sql = "SELECT * FROM cprtype WHERE status=1";
        
        stmt1 = con.prepareStatement(sql);
        rs = stmt1.executeQuery();
        try
        {
            while(rs.next()) 
            {
                cprType = new CPRType();
                cprType.setID(rs.getInt("cprtypeid"));
                cprType.setCprType(rs.getString("cprtype"));
                vList.add(cprType);
            }
        }
        catch(Exception e)
        {
            
            throw new DasException(errorManupilation.GetErrorMessage(e, "getCPRTypesAll "));
        }
        stmt1.close();
        rs.close();
    }
    catch(Exception e)
    {
        
        throw new DasException(errorManupilation.GetErrorMessage(e, "getCPRTypesAll "));
    }
 
    try
    {
        stmt1.close();
        rs.close();
        con.close();
    }
    catch(SQLException ex)
    {
        
        throw new DasException(errorManupilation.GetErrorMessage(ex, "getCPRTypesAll "));
    }
    
    try
    {
        stmt1.close();
        rs.close();
        con.close();
    }
    catch(SQLException ex)
    {
        
        throw new DasException(errorManupilation.GetErrorMessage(ex, "getCPRTypesAll "));
    }
    cprType = null;
    return vList;
}
 
 
Below code can be included in a JSP page.
<%
Vector vCprTypes = new Vector();
CPRMasterTxn cprmt = new CPRMasterTxn();
 
try{
 //Retrieving vector by calling the method.
 vCprTypes = cprmt.getCPRTypesAll();
}catch(Exception e){System.out.println(e.getMessage());}
%>
 
 
 
Applying to a drop down list for dynamic change.
 
<select class="classTableRowColor8" name="selectCprType<%=cprmd.getID()%>" id="redirecturl<%=cprmd.getID()%>" onchange="javascript:submitform('<%=cprmd.getID()%>');">
 <option value="-1">—Select—</option>                     
 <% try{
 if(vCprTypes != null){
  cprType = new CPRType();
  for (int k=0; k< vCprTypes.size() ; k++){           
   cprType = (CPRType)vCprTypes.elementAt(k);    
 %>
   <option class="classFontNormal"  value="<%=cprType.getID()%>"><%=cprType.getCprType()%></option>
 <%}}
 }catch(Exception e){System.out.println("Looping error = "+e.getLocalizedMessage());}
 %>    
</select> 
 

Related Questions