Combobox in JSP
How to set the first value in the Combobox as the default value in JSP.?
Using Struts Framework.
Thanks.
I'm not sure I quite understand your question. Is the combobox dynamically created?
Similar Messages
-
Populating combobox in jsp page from javabean using jsp:getProperty tag
hi,
i am new to jsp, so i don;t know how to populate a combobox in jsp page with productid attribute from a javabean called Bid . i want to have a code to automatically populating combobox using the attribute value from javabean.
please reply me.
<jsp:useBean id="bidpageid" class="RFPSOFTWARE.Bid" scope="session" />
<jsp:setProperty name="bidpageid" property="*"/>
<table width="50%" align="center" border="0">
<tr>
<td width="30%" align="left"><h4><b><label>Date (dd/mm/yyyy) </label></b></h4> </td>
<td><input type="text" name="date" size="11" maxlength="10" readonly="readonly" value="<jsp:getProperty name="bidpageid" property="date"/>" > </td>
</tr>
<tr> <td > </td> </tr>
<tr>
<td width="30%" align="left"><h4><b><label>ProductId </label></b></h4> </td>
<td><select name="productid" tabindex="1" size="1" >
<option value="<jsp:getProperty name=bidpageid" />Sachin</option>
<option value="Hello">Vishal</option>
</select></td>
</tr> and the javabean for Bid is as follow :
import java.util.Date;
import RFPSOFTWARE.Product;
public class Bid{
private Product product;
private Integer bid_id;
private String description;
private Date date= new Date();
public Integer getBid_id() {
return bid_id;
public Date getDate() {
return date;
public String getDescription() {
return description;
public Product getProduct() {
return product;
public void setBid_id(Integer bid_id) {
this.bid_id = bid_id;
public void setDate(Date date) {
this.date = date;
public void setDescription(String description) {
this.description = description;
public void setProduct(Product product) {
this.product = product;
}No Sir,
I think I did not explained clearly.what I try to say is I dont want to use JSTL.I am using only Scriptlets only.I can able to receive the values from the database to the resultset.But I could not populate it in Combobox.
My code is :
<tr>
<td width="22%"><font color="#000000"><strong>Assign To Engineer</strong></font></td>
<td width="78%">
<select NAME="Name" size="1">
<option><%=Username%></option>
</select> </td>
</tr>
in HTML
and in Scriptlets:
ps1 = con.prepareStatement
("SELECT Username FROM Users");
rs2=ps1.executeQuery();
System.out.println("SECOND Succesfully Executed");
while(rs2.next())
System.out.println("Coming inside rs2.next loop to process");
Username=rs2.getString("Username");
System.out.println("Success");
System.out.println("The value retrieved from UsersTable Username is:"+Username);
In the server(Jboss console) I can able to display the username but I could not populate it in the Combobox .
Can you now suggest some changes in my code,Please..
Thanks a lot
With kind Regds
Satheesh -
Filling comboBox in JSP from Oracle tbl
Hello,
Can anybody help, how to fill comboBox (in JSP page)
<select name="types"></select><br>
...from Oracle DB. Types values sould come directly from Oracle tbl.
Thanks in advance.
A.hai here is the ex code.
here iam populating client name from MySQL table. hope this will help u.
<select name="Client">
<option value="SELECT">SELECT</option>
<%
try
Class.forName("com.mysql.jdbc.Driver");
Connection connection = DriverManager.getConnection("jdbc:mysql://localhost:3307/s4", "root", "root");
Statement statement = connection.createStatement();
ResultSet rs = statement.executeQuery("select client_name from client");
while(rs.next())
%>
<option value="<%=rs.getString("client_name")%>"><%= rs.getString("client_name") %> </option>
<%
%>
</select> -
HI All,
This is very urgent for me please help me to come out of this.
I just want to display the values in combobox from database using jsp,but i have difficulty in doing it can any one help me for this.I will be thankfull if any one gives me a code for the same.
Ramesh.Rvery simple example
<%@ page import="java.sql.*" %>
Add Item:
<SELECT NAME="item">
<ol>
<%
Connection con5 =
DriverManager.getConnection("url","user","password");
String q5 = "query" ;
Statement stmt5 = (Statement)con5.createStatement();
ResultSet rs5 = stmt5.executeQuery(q5);
while(rs5.next()){
String str5= rs5.getString("field");
%>
<li> <% out.print("<OPTION>" + str5); %>
<% } %>
</ol>
</SELECT> -
I am new to jsp programming. I have no idea how to navigate if there is two dropdownlist. Here second one depends on the first one then should i have to design two pages with sam dessign?
I have checked the url
http://forum.java.sun.com/editwatches!default.jspa
thsi page contains two comboboxes. I have selected java essentials from first combo. Then it got redirected to another page.
with the url
http://forum.java.sun.com/editwatches!default.jspa?filterCat=5
When I checked the view source of http://forum.java.sun.com/editwatches!default.jspa
I have seen something like this...
<select name="filterForum"
onchange="location.href='editwatches!default.jspa?filterForum='+this.options[this.selectedIndex].value+'&filterCat='+this.form.filterCat.options[this.form.filterCat.selectedIndex].value;">
In the above code what do they mean by location?
Please reply me
Thanks in advanceHi,
Well if you are looking for Dependent Dropdown problem...
There are many solutions in order acheive this...
checkout some of those...
1).Save the present of the Form in a Bean with the scope of session and onChange of the first Combo box redirect it to a Controller(Servlet) Query the Database and save the results in the FormBean which we saved in the scope session and then redirect the formBean to the same JSP again...and now repopulate the second combo with new obtained results from the database and repopulate the rest of the form according to present FormBean state from the session.
Here is a Typical example for you
Assuming that a Servlet had already preloaded the first drop-down values from the database in a FormBean
FormBean.java
=============
public class FormBean{
private String firstDDValue = new String("");
private ArrayList firstDDOptions = new ArrayList();
private String secondDDValue = new String();
private ArrayList secondDDOptions = new ArrayList();
// Setters & getters for all the bean properties.
}Form.jsp:
=========
<jsp:useBean id="formBean" class="com.formbeans.FormBean" scope="session"/>
<%
ArrayList fristDD = formBean.getFirstDDOptions();
ArrayList secondDD = formBean.getSecondDDOptions();
String firstDDValue = formBean.getFirstDDValue();
String secondDDValue = formBean.getSecondDDValue();
int FDSIZE = fristDD.size();
int SDSIZE = secondDD.size();
%>
<form name="formBean">
First DropDown:
<select name="firstDropDown" onChange="if(this.value != '-1')window.location.href='ControlerServlet?firstDropDown='+escape(this.value);" >
<option value="-1">Pick One</option>
<%for(int i = 0;i < FDSIZE ; i++){
String value = ((String[])firstDDOptions.get(i))[0];
String text = ((String[])firstDDOptions.get(i))[1];
%>
<%if(value.equals(firstDDValue){)%>
<option value="<%=value%>" selected="selected"><%=text%></option>
<%}else{%>
<option value="<%=value%>"><%=text%></option>
<%}%>
<%}%>
</select>
<BR/>
<BR/>
Second DropDown:
<select name="secondDropDown">
<option value="-1">Pick One</option>
<%for(int i = 0;i < FDSIZE ; i++){
String value = ((String[])secondDDOptions.get(i))[0];
String text = ((String[])secondDDOptions.get(i))[1];
%>
<%if(value.equals(secondDDValue){)%>
<option value="<%=value%>" selected="selected"><%=text%></option>
<%}else{%>
<option value="<%=value%>"><%=text%></option>
<%}%>
<%}%>
</select>
<BR/>
<BR/>
</form> NOTE: It would be a better practise if you can make use of JSTL tags to render the page in to make your View Page look more cleaner
ControlerServlet.java
=====================
public doGet(request,response){
String firstDropDown = request.getParameter("firstDropDown");
HttpSession session = request.getSession();
FormBean fb = (FormBean) session.getAttribute("formBean");
fb.setFirstDDValue(firstDropDown);
fb.setSecondDDOptions(DAODelegate.getSecondDropDownData(firstDropDown));
session.setAttribute(""formBean",fb);
response.sendRedirect("/Form.jsp");
}2).Make use of a Hidden IFrame by using which you reload the page and then Reload a Page after getting values from the database update the parent frame combo accordingly.
3).Take help of AJAX call a Controller get the Response in XML/JSON and parse it and then update the second combo by the XML/JSON response.
checkout an example by you can achieve this.
index.jsp:
=======
<%@page language="java" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Automatic Dependent Drop-Down Updation</title>
<script language="javascript">
// Global Variable for XmlHttp Request Object
var xmlhttp
// Timer Variables
var c = 0
var t
/* A function which calls a servlet named AjaxServlet to get XmlData using XmlHttpObject */
function refreshCombo(txt){
xmlhttp = null
// code for initializing XmlHttpRequest Object On Browsers like Mozilla, etc.
if (window.XMLHttpRequest){
xmlhttp = new XMLHttpRequest()
// code for initializing XmlHttpRequest Object On Browsers like IE
else if (window.ActiveXObject) {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP")
if (xmlhttp != null){
// Setting the Servlet url to get XmlData
url = "AjaxServlet?req="+txt;
// Course of Action That Should be Made if their is a change in XmlHttpRequest Object ReadyState NOTE : it is 4 when it has got request from CGI
xmlhttp.onreadystatechange = getResponseAction;
// Open the Request by passing Type of Request & CGI URL
xmlhttp.open("GET",url,true);
// Sending URL Encoded Data
xmlhttp.send(null);
else{
// Only Broswers like IE 5.0,Mozilla & all other browser which support XML data Supports AJAX Technology
// In the Below case it looks as if the browser is not compatiable
alert("Your browser does not support XMLHTTP.")
/* Used for verifing right ReadyState & Status of XmlHttpRequest Object returns true if it is verified */
function verifyReadyState(obj){
// As Said above if XmlHttp.ReadyState == 4 then the Page Has got Response from WebServer
if(obj.readyState == 4){
// Similarly if XmlHttp.status == 200 it means that we have got a Valid response from the WebServer
if(obj.status == 200){
return true
else{
alert("Problem retrieving XML data")
/* Action that has to take place after getting reponse */
function getResponseAction(){
// Verifying State & Status
if(verifyReadyState(xmlhttp) == true){
// Building a DOM parser from Response Object
var response = xmlhttp.responseXML.documentElement
// Deleting all the Present Elements in the Drop-Down Box
drRemove()
// Checking for the Root Node Tag
var x = response.getElementsByTagName("option")
var val
var tex
var optn
for(var i = 0;i < x.length; i++){
optn = document.createElement("OPTION")
var er
// Checking for the tag which holds the value of the Drop-Down combo element
val = x.getElementsByTagName("val")
try{
// Assigning the value to a Drop-Down Set Element
optn.value = val[0].firstChild.data
} catch(er){
// Checking for the tag which holds the Text of the Drop-Down combo element
tex = x[i].getElementsByTagName("text")
try{
// Assigning the Text to a Drop-Down Set Element
optn.text = tex[0].firstChild.data
} catch(er){
// Adding the Set Element to the Drop-Down
document.SampleForm.state.options.add(optn)
/* Function removes all the elements in the Drop-Down */
function drRemove(){
document.SampleForm.state.options.length = 0;
</script>
</head>
<body>
<pre> <h1>Refresh Drop-Down <div id='txt'> </div> </h1></pre>
<form name="SampleForm">
<table align="center">
<tr>
<td>Country:</td>
<td>
<select name="country" onchange="refreshCombo(this.value)">
<option value="india">INDIA</option>
<option value="US">United States</option>
<option value="UK">United Kingdom</option>
<option value="Saudi">Saudi</option>
</select>
</td>
</tr>
<tr>
<td>State:</td>
<td>
<select name="state">
<option value="-1">Pick One</option>
</select>
</td>
</tr>
</form>
</body>
</html>
AjaxServlet.java:
=============
* AjaxServlet.java
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
* @author RaHuL
* @version
public class AjaxServlet extends HttpServlet {
/** Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
* @param request servlet request
* @param response servlet response
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
// Sets the content type made to xml specific
response.setContentType("text/xml");
response.setHeader("pragma","no-cache");
response.setHeader("Cache-Control","no-cache");
response.setHeader("Cache-Control","no-store");
//Initializing PrintWriter
PrintWriter out = response.getWriter();
String req = request.getParameter("req");
// Creating an instance of XmlBean Which generates XmlData From Business Logic specified
XmlBean xml = new XmlBean(req);
// Method to Generate XMLDATA
String buffer = xml.getXmlData();
// If Close of DB connections are succefull then write the content to the printstream
if(xml.close() == true)
out.write(buffer);
out.flush();
out.close();
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
// Calls a Method called processRequest Which Processes the request which was made by the Browser Page
processRequest(request, response);
}XmlBean.java:
===========
* XmlBean.java
import java.sql.*;
import java.util.*;
import java.io.*;
* @author RaHuL
public class XmlBean {
private Connection con = null;
private PreparedStatement pstmt = null;
private ResultSet rs = null;
private String req;
// Setting CLASSURL path to TYPE I Driver
private String CLASSURL = "sun.jdbc.odbc.JdbcOdbcDriver";
/* Specifing CONNECTION PATH to a DSN named TestDsn
* Please Make Sure you create a DSN Named TestDsn to your database which holds EMP table
private String CONNECTIONURL = "jdbc:odbc:TestDsn";
boolean IS_ESTABLISHED = false;
/** Creates a new instance of XmlBean and also establishes DB Connections */
public XmlBean(String req) {
try{
this.req = req;
Class.forName(CLASSURL);
con = DriverManager.getConnection(CONNECTIONURL,"admin","");
IS_ESTABLISHED = true;
} catch(SQLException sqe){
sqe.printStackTrace();
} catch(Exception exp){
exp.printStackTrace();
/* Generates XmlData For the Business Logic Specified */
public String getXmlData(){
String XmlBuffer = "";
if(IS_ESTABLISHED == true){
try{
pstmt = con.prepareStatement("SELECT stateid,statename FROM EMP where countryid=' "+req+" ' " );
rs = pstmt.executeQuery();
if(rs != null){
XmlBuffer = XmlBuffer + "<?xml version=\"1.0\" encoding=\"ISO-8859-1\" ?>";
XmlBuffer = XmlBuffer + "<!-- Edited by Rahul Sharma -->";
// Root Node
XmlBuffer = XmlBuffer + "<dropdown>";
while(rs.next()){
String value = rs.getString(1);
String text = rs.getString(2);
// Sub-root Node
XmlBuffer = XmlBuffer + "<option>";
// node which holds value of drop-down combo
XmlBuffer = XmlBuffer + "<val>"+value+"</val>";
// node which holds text for drop-down combo
XmlBuffer = XmlBuffer + "<text>"+text+"</text>";
XmlBuffer = XmlBuffer + "</option>";
XmlBuffer = XmlBuffer + "</dropdown>";
}catch(SQLException sqe){
sqe.printStackTrace();
} catch(Exception exp){
exp.printStackTrace();
return(XmlBuffer);
/* Closes the DB Connection Conmpletely */
public boolean close(){
if(IS_ESTABLISHED == true){
try{
pstmt.close();
con.close();
return(true);
} catch(SQLException sqe){
sqe.printStackTrace();
} catch(Exception exp){
exp.printStackTrace();
return(false);
}Sample XML Reponse generated:
<?xml version=\"1.0\" encoding=\"ISO-8859-1\" ?>
<!-- Edited by Rahul Sharma -->
<dropdown>
<option>
<val>DEL</val>
<val>New Delhi</val>
</option>
<option>
<val>HAR</val>
<val>HARYANA</val>
</option>
</dropdown>for further reference you may use the below articles
http://www.it-eye.nl/weblog/2005/12/13/ajax-in-struts-implementing-dependend-select-boxes/
http://www.it-eye.nl/weblog/2006/04/04/implementing-dependent-select-boxes-in-jsf/
Hope this might help,if that does do not forget to assign/distribute Duke Stars which you have promised :)
REGARDS,
RaHuL -
Flex with Java - DB data access
Hello, folks,
I am developing a Java application and realized that I need
some advice. My application is simple:
I have a MSSQL server, tomcat 5.5 ,flex data services.
In my application , i have two combo boxes.. country, town..
i have populated the country combobox with the values from
DB(country table) obtained using the fill(List ListArgs) in
Assembler Class.
Now, based on the country selected in have to populate my
town combobox from (town table)
How can i populate the town combobox from the DB based on the
country code?
Is there any function to pass the selected index and populate
the town combo box..????
My code is as below:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="
http://www.adobe.com/2006/mxml"
layout="absolute" >
<mx:DataService id="ds" destination="quick-search-country"
autoCommit="false" autoSyncEnabled="false"/>
<mx:DataService id="tds" destination="quick-search-town"
autoCommit="false" autoSyncEnabled="false"/>
<mx:ArrayCollection id="cntry_list"/>
<mx:ArrayCollection id="town_list"/>
mx:Panel layout="absolute" backgroundColor="#c6daf5"
verticalCenter="0" horizontalCenter="0">
<mx:Form id="SearchForm">
<mx:TabNavigator >
<mx:Canvas label="Hotel" width="339" height="234"
backgroundColor="#ffffff">
<mx:Label x="10" y="91" text="Country :" alpha="0.12"
/>
<mx:ComboBox x="93" y="89" fontSize="10" id="Country"
dataProvider="{cntry_list}"
labelField="countryName"
creationComplete="ds.fill(cntry_list)"
change="tds.getItem(Country.selectedItem)" prompt="United
Kingdom" >
</mx:ComboBox>
<mx:Label x="10" y="126" text="Town / City :"
fontFamily="Georgia" alpha="0.12"/>
<mx:ComboBox id="town" x="94" y="124" fontSize="10"
dataProvider="{town_list}"
labelField="townName" prompt="London WC1" >
</mx:ComboBox>
</mx:Canvas>
</mx:TabNavigator>
</mx:Form>
</mx:Panel>
</mx:Application>
this is my main.mxml . I have CountryAssembler to fill the
country combo and a DAO class . Have a Town assembler..
Please advice me on how to populate the town combo based on
country selected from the DB...
I am really stuck up... and also dont have any documentation
on Flex data services with Java support..
please give me some suggestions on this.
Thanks in Advance,
AmbiliHi Mete,
Thanks for ur reply , Mete. Your reply helped me a lot. Am
using FDS 2.0.
I have a doubt in combo box area itself.
I have two tables by name country_list and town_list
country_list consists of identity column , country_name and
country_code
town_list has identity column, country_code, town_code and
town_name
Normally while we use combobox in jsp, we have key value
pairs for combo box..
For eg:- if we have a Country combo , we have the country
name(United States) as text displayed and its country code (US) as
key.
So if i select the United States , i will be returned with
the value 'US' so that i can use it in query directly as
Select town_name, town_code from town_list where country_code
='US'
But while using flex , am not able to retieve the
country_code from country combo. its only returning the text and
the id.
Here am forced to write a nested query as follows
Select town_name, town_code from town_list where country_code
=( Select country_code from country_list where country_name='United
States')
Is there any way to get the country_code as key while i
select the country from country combo .
And also how to keep 'United States' as selected during the
intial load of the page.
<mx:ArrayCollection id="cntry_list"/>
<mx:ComboBox x="93" y="89" fontSize="10" id="Country"
dataProvider="{cntry_list}"
labelField="countryName"
creationComplete="ds.fill(cntry_list)"
prompt="Select Country" />
please give me some suggestions on this.
Thanks in Advance,
Ambili -
JSF, HtmlSelectOneMenu not updating selectitems
Hi all,
I've 2 select boxes in my jsp called countries and cities. If I select country then cities should be loaded.. I could able to invoke bean method with AJAX then setting SelectItems list to cities combobox.
but not able to get newly added select items in cities combobox in jsp
pls find piece of code i used
UIViewRoot root = FacesContext.getCurrentInstance().getViewRoot();
HtmlSelectOneMenu sMenu = (HtmlSelectOneMenu) root
.findComponent("form1:lstCity");
sMenu.getChildren().clear();
sMenu.getChildren().addAll(mastBean.getCitiestems());
System.out.println(sMenu.getChildren().size());
pls help me..
thnx in adv.In Jdev 10.1.3,there is no operations folder directly under the Application data module control.
there is only constructors,merge entity,persist entity,refresh entity,remove entity and findalldepartments(),findallemployeeas() nodes under the application data module control.
In findalldepartments,findallemplloyees the operations node is there.under that i don't have the commit .i have only create,execute,first,previous,last,next,delete,removerowwithkey,setcurrentRowWithkey,setcurrentRowWithkeyValue under the operation node.
so how can i commit the operations in database.
Please help me. -
How to get the values of 2 dynamic comboboxes in one jsp to another jsp?
I have 2 comboboxes and one submit button on my jsp page.I select a value in 1st combobox then the values in the second combobox populated from the database. next i select 2nd combobox and then submit the button.After submit the button call the next jsp page. In that page i want to display the values of two comboboxes. but my problem is , in that page only 2nd combobox value is displayed.1st combobox is displayed as null. plz tell me, how to get the values of two comboboxes at a time?
Select.jsp:
<%@ page language="java" import="java.sql.*" %>
<%!
Connection con = null;
Statement st = null;
ResultSet rs = null;
String sql = null;
void addItems(javax.servlet.jsp.JspWriter out, String sql)
try{
rs = st.executeQuery(sql);
while( rs.next() )
out.println("<option>" + rs.getString(1) + "</option>");
}catch(Exception e)
System.out.println(e);
%>
<HTML>
<HEAD>
<TITLE>JSP WITH MULTIPLE FORMS</TITLE>
<script language="javascript">
function checking()
form1.submit();
</script>
</HEAD>
<body>
<center>
<b><font size="5" color="#333399">Staff ID:</font></b></center>
<FORM NAME="form1" METHOD="POST" ACTION="Select.jsp">
<p align=center>
Details of Staff :
<SELECT 1 NAME="type" onchange="checking();">
<option> Administrator </option>
<option> OfficeAssistent </option>
<option> Clerk </option>
</SELECT 1>
</p>
</FORM>
<FORM NAME="form2" METHOD="POST" action="welcome1.jsp">
<center>
<TABLE><TR><TD>Staff ID:</TD>
<TD><SELECT 2 NAME="staff_id">
<%
String type = request.getParameter("type");
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con = DriverManager.getConnection("jdbc:odbc:java","system","manager");
catch (ClassNotFoundException ex) {
System.out.println(ex);
catch (SQLException ex)
System.out.println(ex);
st = con.createStatement();
sql = "select staff_id from "+type+"";
addItems(out, sql);
%>
</SELECT 2>
</TD>
</TR>
</table></center>
<h2> Details of <%= type + "s" %> </h2>
<center><input type=submit value=ok onclick="submit();"></center>
</FORM>
</BODY>
</HTML>
welcome1.jsp
<center><h1>WEL COME</h1></center>
<%
String type = request.getParameter("type");
String sid = request.getParameter("staff_id");
%>
<h2> Details of <%= type + "s" %> </h2>
<h2> Details of <%= sid %> </h2><SELECT 1 NAME="type" onchange="checking();">
<option value = "0"> Administrator </option>
<option value = "1"> OfficeAssistent </option>
<option value = "2"> Clerk </option>
</SELECT 1> -
How To Pupulate A Combobox on Page Load in JSP
Hi All,
How to populate a combobox on a JSP Page load.
Please help.
Regards,
DineshThanks,
My current coding in jsp is :
To get the ArrayList from my DAOImpl class.
<%
newAppDAOImpl dao = new newAppDAOImpl();
dao.populateCombo(request);
ArrayList filetypes = (ArrayList)request.getAttribute("FILETYPES");
if(filetypes==null)
filetypes=new ArrayList();
pageContext.setAttribute("vecFileType" ,filetypes) ;
%>
For populating the combo:
<html:select property="retailer" onclick="/search">
<html:option value="----Select----"/>
<html:options collection="vecFileType" property="value"
labelProperty="label"/>
</html:select>
The above code is working for me.
Regards,
Dinesh -
Dinamic Combobox in jDeveloper using JSP
What is the most simple way to do a JSP page with two dinamic combobox like the classic Countries and Cities ... That is.. When I select a Country then all the cities of the country selected are loaded from a Data Base... I'm working in jDeveloper..
This is how you used to do it in 10.1.2
http://www.oracle.com/technology/products/jdev/tips/mills/cascading_lists.html -
Java(jsp) problem....of combobox event
hai here jai.....
i m doing a project in jsp with backend postgresql.......
my problem is.....i hv a combobox where i display department code from database....i hv done this.....now when i select a dept code in the combobox,then there is a textbox on the same page where corresponding ddo code of that dept code will be displayed from the database.....and the dept code and ddo code are 4m the same table of the database.....i can't do this......please help....give me the code in jsp......Try with the code below...I just implemented teh logic.You have to modify the code accoring to your need...............lemme know if it works or not...........
<html>
<head><script>
function subit(){
document.combo_chk.action='firstpage.jsp?combo='+document.combo_chk.combo.value;
//alert(document.combo_chk.action);
document.combo_chk.submit();
function selit(){
//alert(document.getElementById('<%=request.getParameter("combo")%>').value);
document.getElementById('<%=request.getParameter("combo")%>').selected='true'
</script>
</head><%if(request.getParameter("combo")!=null){%>
<body onload="selit()">
<%}else{%>
<body>
<%}%>
<form name="combo_chk" method="post" action="secondpage">
<%
String value="";
if(request.getParameter("combo")!=null){
//your code will go here..
//dummy value for test
value="edu1,edu2...................";
//End dummy value for test
}%>
<select name="combo" onchange="subit()">
<option value="home" id="home">HOME</option>
<option value="education" id="education">EDUCATION</option>
</select>
empid<input type="text" name="empid" value="<%=value%>">
</form>
</body>
<html> -
Looking documentation about filling comboboxes in bc4j JSP´s edit pages.
Im looking documentation about filling comboboxes in bc4j JSP pages (bc4j forms). My case is as follows:
I have an edit JSP form. This edit jsp form needs two comboboxes. The values in the second combo box depends of the choice selected in the first combo box. Both combos are bounded to its respective tables.
How can i do that?
Thank u.It is possible to use Javascript to refresh, but the code in Javascript is not entirely trivial.
Here is an example of a dependent select control which uses javascript to refresh the dependent list.
One use BC4J tags to populate a similar dependent list dynamically:
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script type="text/javascript">
// Create arrays containing state cities
// Note: These arrays could be created dynamically
var arrStates, arrFlorida, arrNewYork, arrTennessee
arrFlorida = ["Daytona Beach", "Miami", "Orlando", "Tampa"]
arrNewYork = ["Albany","New York", "Oakland", "Rochester"]
arrTennessee = ["Gatlinburg", "Knoxville", "Memphis", "Nashville"]
arrStates =[arrFlorida, arrNewYork, arrTennessee]
// Function to handle dynamically altering the contents of the City List box
function handleChange(newDisplay)
{ var StateSelect, CitySelect, NumEntries, i
StateSelect = document.frm.States
CitySelect = document.frm.Cities
// Delete all entries in the cities list box
for (i = CitySelect.length; i > 0; i--)
CitySelect.options[i-1] = null
// Add comment option to City List box
CitySelect.options[0] = new Option("-- Select City --",0)
// If state is selected add its cities to the City List box
if (newDisplay >= 0)
NumEntries = arrStates[newDisplay].length
for (i = 1; i <= NumEntries; i++)
CitySelect.options[i] = new Option((arrStates[newDisplay])[i-1],(i))
CitySelect.selectedIndex = 0
</script>
</head>
<body bgcolor="#FFFFFF" text="#000000">
<p>This is a test.. </p>
<p> </p>
<form name="frm" action="">
States:
<select name="States" onChange="handleChange(this[this.selectedIndex].value)">
<option value="-1">-- Select State --
<option value="0">Florida
<option value="1">New York
<option value="2">Tennessee
</select>
<p>
Cities:
<select name="Cities">
<option value="-1">-- Select City --
<option>
<option>
<option>
<option>
</select>
<script type="text/javascript">
handleChange(-1)
</script>
</form>
</body>
</body>
</html> -
How to display a combobox(dropdown menu) in a jsp page?
Hi friends,
I need to create a jsp page which contains three text fields and a single dropdown menu,,, . and my functionality is while loading the page itself that dropdown menu gets the data from database and holds in it..... i mean the data in theat combo box must gets from Database and based on the particular selection the remaing fields has to be filled ...... so plz helpme to solv this and any help is appriciated....
regards
priya......Hi,
Google should definitely help you with this. I am sure that there may be people here who will guide you through each step in this forum. But, you learn only when you do things yourself. Please take some time to go through the links in google. You will definitely find all the things required to solve your problem.
1) JDBC examples to populate your dropdown.
2) DHTML+Javascript to handle selection/display of fields.
You can come here for help only after you have tried to some extent and not able to proceed with something. Trust me, you should be able to do it yourself.
Karthik. -
Ways to retrieve data into Jsp page on ComboBox (or any other event ) event
Hi all,
I want to retrieve records from database and display it in Text field.
Can any one tell me the ways to do it, i know i can do this by using javascript (javascript to submit the form), but i dont want to use javascript any where in my code,
what i want to know is there any other ways to implement this functionality, and which is the best one.
Kindly help me,
Thanks in advanced.With plain webapps, there is no way. In one way or another, the server needs to be invoked to be able to provide the data, so that is either a submit or through an Ajax call. Both would involve javascript. Why are you scared of Javascript anyway?
-
Fund transfer module for online banking in jsp
i am working on safe and secured internet banking project . currently working on fund transfer module. any particular user can transfer money from his/her account to any account.my first jsp file for this is:- fundtrans.jsp
in this jsp page there are 2 comboboxes :- from account and to account , i m getting accounts in these comboboxes from database.in my case i m using saving table where all information about user's saving account is placed.
fundtrans.jsp:-
<%@ page import="java.util.*, java.lang.*, java.sql.*" %>
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<table width="1024" border="0" cellpadding="0" cellspacing="0">
<!--DWLayoutTable-->
<tr>
<td width="119" height="164"></td>
<td width="152"></td>
<td width="162"></td>
<td width="147"></td>
<td width="444"></td>
</tr>
<tr>
<td height="32"></td>
<td valign="top">From Account</td>
<td></td>
<td valign="top">
<form name="form1" method="post" action="">
<label>
// combobox 1 which gets account_no from database from which transfer to be made
<select name="select2">
<%
// code for getting account_no from database table saving
try {
Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection con = DriverManager.getConnection("jdbc:mysql://mridul:3306/bank","root" ,"root");
PreparedStatement ps;
Statement st=con.createStatement();
ResultSet rs = st.executeQuery("select * from saving where saving.username = '" + session.getAttribute( "theName" ) + "'");
%>
<%
while(rs.next())
String Account =rs.getString("account_no"); %>
<option value=""> <%= Account %> </option>
<%}%>
<%
rs.close();
st.close();
con.close();
}%><%
catch(Exception e)
e.printStackTrace();
%>
</select>
</label>
</form> </td>
<td></td>
</tr>
<tr>
<td height="81"></td>
<td> </td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td height="34"></td>
<td valign="top">To Account </td>
<td></td>
<td valign="top"><form name="form2" method="post" action="">
<label>
// combobox 2 which gets account_no from database to which transfer is made
<select name="select">
<%
//this gets account_no from database table saving and placed in combobox
try {
Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection con = DriverManager.getConnection("jdbc:mysql://mridul:3306/bank","root" ,"root");
Statement st=con.createStatement();
PreparedStatement ps1 = con.prepareStatement("select distinct account_no from saving");
ResultSet rs=ps1.executeQuery();
System.out.println("SECOND Succesfully Executed");
%>
<%
while(rs.next())
String Accountno = rs.getString("account_no"); %>
<option value=""> <%=Accountno %> </option>
<%}%>
<%
rs.close();
st.close();
con.close();
}%><%
catch(Exception e)
e.printStackTrace();
%>
</select>
</label>
</form> </td>
<td></td>
</tr>
<tr>
<td height="52"></td>
<td> </td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td height="34"></td>
<td valign="top">Amount</td>
<td></td>
<td valign="top"><form name="form3" method="post" action="">
<label>
// this is text box in which user gives amount to be transfered
<input type="text" name="bal">
</label>
</form> </td>
<td></td>
</tr>
<tr>
<td height="83"></td>
<td> </td>
<td> </td>
<td></td>
<td></td>
</tr>
<tr>
<td height="37"></td>
<td> </td>
//this is a submitt type button which goes to the update.jsp for further processing
<td valign="top"><form name="form4" method="post" action="update.jsp">
<label>
<input type="submit" name="b4" value="continue">
</label>
</form>
</td>
<td></td>
<td></td>
</tr>
<tr>
<td height="467"></td>
<td> </td>
<td> </td>
<td></td>
<td></td>
</tr>
</table>
</body>
</html>
update.jsp:- in this file i wrote sql query for fund transfer. in this i m subtracting balance from one account_no and want to show updated saving table. i m not using query for addition of balance in another account_no becoz i m getting problem here.
<%@ page import="java.util.*, java.lang.*, java.sql.*" %>
<%
String name,pwd;
boolean found=false;
String acc= request.getParameter("select2");
String acc1= request.getParameter("select");
String ammount= request.getParameter("bal");
Integer ammount1 = Integer.valueOf((String)session.getAttribute("bal"));
//Establish connection
try
Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection con = DriverManager.getConnection("jdbc:mysql://mridul:3306/bank","root" ,"root");
Statement st=con.createStatement();
// ResultSet rs = st.executeQuery("update saving set balance = balance-ammount1 where saving.account_no = '" + acc +"'");
ResultSet rs = st.executeQuery("select * from saving");
while ( rs.next() ) {%>
<tr>
<td valign="top" height="43"><%=rs.getString(1) %></td>
<td valign="top"> <%=rs.getString(2) %></td>
<td valign="top"> <%= rs.getString(3) %></td>
<td valign="top"> <%=rs.getString(4) %></td>
<td valign="top"> <%=rs.getString(5) %></td>
<td></td>
</tr>
<%}
rs.close();
st.close();
con.close();
catch(Exception e)
e.printStackTrace();
%>
my prob is i m not able to print updated saving table i found 1 blank page or sometimes i find "sever is not capable for fulfilling the request". i m able to understand that whether my sql query is wrong or i m getting value from combobox via request.getParameter. please help me as soon as possible.can u give me table name with attribute.
because i couldn't get it <%=rs.getString(1) %>
Edited by: prakash83 on Mar 8, 2008 9:22 PM
Maybe you are looking for
-
Tables in which LSMW data is stored?
Hi Gurus, I would like to know the base tables that LSMW uses. My actual requirement is to fetch the action log of the LSMW object. No option is provided in R/3 to download Action Log of an LSMW object into Excel. Hence I am trying to find the tables
-
Why is there no color on my new color ipod?? The screen is EXACTLY like the old version.
-
Deleting Plantes replicated from R/3.
Hi, I replicated plant for mR/3 into SRM using BBP_LOCATIONS_GET_ALL. This worked as expected. However, I replicated more plants that I wanted. Guess I should have used BBP_LOCATIONS_GET_SELECTED. My question: Is there a way to delete the plants w
-
Verification error when run the game after download the jad/jar by OTA on BB 8300
On BB 8800, the jad/jar can be downloaded to the device, when run the game, there is a error msg "Error starting xxxx Module xxxx has verification error xxxx at offset xxxx", the version is OK on BB 8310, but failed on BB 8800 and 8300. I make the ve
-
Hi All, I want to calculate a formula, depending on that formula, I want to hide and make the column visible. I have a column called SN. I want to make it visible when the value of the parameter called @section is "GCG" otherwise I want to make it