Hi,
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"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@ taglib prefix="s" uri="/struts-tags"%>
<%@ taglib prefix="sj" uri="/struts-jquery-tags"%>
<html>
<head>
<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").siblings().removeClass("rf-ord-sel");
$(this).closest("tr").toggleClass("rf-ord-sel", this.clicked);
}
});
$('#add').click(function() {
// alert("Inside add function");
$("#pr_type_table").find('tbody')
.append($('<tr>')
.append($('<td>')
.append($('<img>')
.attr('src','/adminScreens/images/delete.jpg')
.text('')))
.append($('<td>')
.append($('<input>')
.attr('id','data')
.attr('type','text')
.attr('size', 16)
.text('')))
.append($('<td>')
.append($('<select/>')
.attr('id','{#request.PrTypeList}')
)
)
);
});
$('#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
if(!data){
$(this).remove();
}
});
});
});
</script>
</head>
<body>
<s:include value="/pages/home.jsp"></s:include>
<s:if test="hasActionErrors()">
<div>
<s:actionerror/>
</div>
</s:if>
<s:if test="hasActionMessages()">
<div>
<s:actionmessage/>
</div>
</s:if>
<fieldset>
<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>
</tr>
</thead>
<tbody>
<tr>
<td><img id="deleteItemId" src='<s:url value="/images/delete.jpg"/>' /></td>
<td><s:textfield size="10" style="width:100px;" id="width"
name="prTypeName"></s:textfield></td>
<td><s:select name="prType" id="prType"
list ="#request.PrTypeList" headerKey=""></s:select></td>
</tr>
</tbody>
</table>
<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"/>
</s:div>
</sj:div>
<br />
</s:form>
</fieldset>
</body>
</html>
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(
PrTypeAction.class);
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;
}
//@org.apache.struts2.interceptor.validation.SkipValidation
//public String execute() throws Exception {
// System.out.println("<< PrTypeActionBase Action Starts here >>");
// populateDropDownValues();
// return "successPrType";
// }
@org.apache.struts2.interceptor.validation.SkipValidation
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{
prTypeBean_.setPrAction_(prType);
prTypeBean_.setPrType_(prTypeName);
System.out.println("CreatePrItem called with values: " + prTypeBean_.getPrType_() + "," + prTypeBean_.getPrAction_());
String PrType = null;
try{
PrType = prTypeService_.createItem(prTypeBean_);
}catch(Exception ex){
ex.printStackTrace();
}
prTypeBean_.setPrType_(PrType);
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()
{
populateDropDownValues();
}
public String addRow()
{
// logic goes here
return "successAddRow";
}
}
Thanks for your response in advance.