Win a copy of Five Lines of Code this week in the OO, Patterns, UML and Refactoring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
  • Piet Souris
  • Frits Walraven
  • Carey Brown

How can i get the data to a drop down box from database

Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can some one help me with this issue, I have a JSP page with 3 buttons, Add, Create and Cancel, and three columns, one with dropdown list. This list i should get from database table. First time when i deploy this page, initially row is getting this dropdown list from table. But when i click on add button, it is not getting any drop down values.
Here is my JSP code:
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "">;
<%@ taglib prefix="s" uri="/struts-tags"%>
<%@ taglib prefix="sj" uri="/struts-jquery-tags"%>
<sj:head />
<%-- <style type="text/css">
.vMenu {
height: 100%;
float: left;
overflow: hidden;
align: top;
vertical-align: top;
</style> --%>

<!-- sidemenu, style, topmenu -->
<link rel="stylesheet" type="text/css"
href="<%=request.getContextPath()%>/css/collapsible.css" />
<link rel="stylesheet" type="text/css"
href="<%=request.getContextPath()%>/css/general.css" />
<link rel="stylesheet" type="text/css"
href="<%=request.getContextPath()%>/css/button.css" />
<link rel="stylesheet" type="text/css"
href="<%=request.getContextPath()%>/css/dropdownmenu.css" />
<link rel="stylesheet" type="text/css"
href="<%=request.getContextPath()%>/css/orderingList.css" />
<link rel="stylesheet" type="text/css"
href="<%=request.getContextPath()%>/css/primefaces.css" />
<link rel="stylesheet" type="text/css"
href="<%=request.getContextPath()%>/css/popup.css" />
<link rel="stylesheet" type="text/css"
href="<%=request.getContextPath()%>/css/popupPanel.css" />
<link rel="stylesheet" type="text/css"
href="<%=request.getContextPath()%>/css/toolbar.css" />
<link rel="stylesheet" type="text/css"
href="<%=request.getContextPath()%>/css/skinning.css" />
<link rel="stylesheet" type="text/css"
href="<%=request.getContextPath()%>/css/aristo.css" />
<link rel="stylesheet" type="text/css"
href="<%=request.getContextPath()%>/css/window.css" />
<link rel="stylesheet" type="text/css"
href="<%=request.getContextPath()%>/css/login.css" />
<link rel="stylesheet" type="text/css"
href="<%=request.getContextPath()%>/css/panel.css" />
<link rel="stylesheet" type="text/css"
href="<%=request.getContextPath()%>/css/commonstyles.css" />
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>CPM - Container Program Management</title>
<script type="text/javascript" src="<%=request.getContextPath()%>/js/jquery-1.8.2.js"></script>
<script type="text/javascript">

$(document).ready(function() {
$(".cell").live('click', function(event) {
if (event.ctrlKey) {
$(this).closest("tr").toggleClass("rf-ord-sel", this.clicked);
} else {
$(this).closest("tr").toggleClass("rf-ord-sel", this.clicked);
$('#add').click(function() {

// alert("Inside add function");
.attr('size', 16)



$('#cancel').click(function() {
$("#pr_type_table tr:gt(0)").each(function() {
//iterates through each row in a table
var data = $(this).find("input").val(); //value of inputfield




<s:include value="/pages/home.jsp"></s:include>

<s:if test="hasActionErrors()">

<s:if test="hasActionMessages()">

<legend class="breadCrumbs"><s:label key="label.maintainPRType"></s:label></legend>
<s:form id="itemForm" theme="simple">
<sj:div cssClass="rf-p">
<s:div cssClass="rf-p-hdr"><s:label key="label.addPRType"></s:label></s:div>
<s:div cssClass="rf-p-b">
<table id = "pr_type_table" class="searchFields">
<thead class="rf-ord-lst-hdr">
<tr class="rf-ord-hdr">
<th class="rf-ord-hdr-c">Delete</th>
<th class="rf-ord-hdr-c">PR Types</th>
<th class="rf-ord-hdr-c">PR Action</th>

<td><img id="deleteItemId" src='<s:url value="/images/delete.jpg"/>' /></td>
<td><s:textfield size="10" style="width:100px;" id="width"
<td><s:select name="prType" id="prType"
list ="#request.PrTypeList" headerKey=""></s:select></td>
<input id = "add" type="button" value="Add"/>
<!-- <input id = "create" type="button" value="Create"/> -->
<td><s:submit key = "Create" action = "createPrItem" /></td>
<input id = "cancel" type="button" value="Cancel"/>
<br />


Here is my Action Class:

public class PrTypeAction extends BaseAction implements Preparable {

private static final long serialVersionUID = 1L;
private static final FrameworkLog LOG = FrameworkLogFactory.getFactory().getInstance(
private PrTypeBean prTypeBean_;
private PrTypeService prTypeService_;
private String prTypeName;
private String prType;
/* private List<prType> Actions;
Actions = request.PrTypeList;*/

public String getPrTypeName() {
return prTypeName;

public void setPrTypeName(String prTypeName) {
this.prTypeName = prTypeName;

public String getPrType() {
return prType;

public void setPrType(String prType) {
this.prType = prType;

//public String execute() throws Exception {
// System.out.println("<< PrTypeActionBase Action Starts here >>");
// populateDropDownValues();
// return "successPrType";
// }

public String newPrType()
return "successPrType";

* @return the itemToolService_
public PrTypeService getPrTypeService_() {
return prTypeService_;

* @param itemToolService_ the itemToolService_ to set
public void setPrTypeService_(PrTypeService prTypeService_) {
this.prTypeService_ = prTypeService_;

* @return the itemToolBean_
public PrTypeBean getPrTypeBean_() {
return prTypeBean_;

* @param itemToolBean_ the itemToolBean_ to set
public void setPrTypeBean_(PrTypeBean prTypeBean_) {
this.prTypeBean_ = prTypeBean_;

* populateDropDownValues is to get the dropdown values from cache
private void populateDropDownValues() {
request.setAttribute(CpmConstants.PRTYPE, cache.get(CpmConstants.PRTYPE));


public String createPrItem () throws CpmServiceException{

System.out.println("CreatePrItem called with values: " + prTypeBean_.getPrType_() + "," + prTypeBean_.getPrAction_());
String PrType = null;
PrType = prTypeService_.createItem(prTypeBean_);
}catch(Exception ex){
System.out.println("Leaving createPrItem Method.");
return "successPrType";

public void validate()
if ((prTypeBean_.getPrType_() == null) || (prTypeBean_.getPrType_().trim().isEmpty()))
addActionError("PR Type is required.");

public void prepare()

public String addRow()
// logic goes here
return "successAddRow";

Thanks for your response in advance.
Just the other day, I was thinking ... about this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
    Bookmark Topic Watch Topic
  • New Topic