Meaningless Drivel is fun!
The moose likes Struts and the fly likes How can i get the data to a drop down box from database Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "How can i get the data to a drop down box from database" Watch "How can i get the data to a drop down box from database" New topic

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

Meenakshi Devi

Joined: May 31, 2011
Posts: 19
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.
I agree. Here's the link:
subject: How can i get the data to a drop down box from database
It's not a secret anymore!