Clear Cart button in Java - java

Hi I'm trying to make a "Clear Cart" button in my java code but i'm having difficulty.
I've been trying for a couple of hours but i can't get it to work
I think it has something to do mostly with the first part that has all the strings and variables.
Here's the code:
<%#page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<%# page errorPage="errorpage.jsp" %>
<jsp:useBean id="cart" scope="session" class="beans.ShoppingCart" />
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>the Game Store</title>
</head>
<body>
<%
String id = request.getParameter("id");
if ( id != null ) {
String desc = request.getParameter("desc");
Float price = new Float(request.getParameter("price"));
cart.addItem(id, desc, price.floatValue(), 1);
}
%>
Shopping Cart Quantity:
<%=cart.getNumOfItems() %>
<hr>
<center><h3>Games</h3></center>
<table border="1" width="300" cellspacing="0"
cellpadding="2" align="center">
<tr><th>Description</th><th>Price</th></tr>
<tr>
<form action="AddToShoppingCart.jsp" method="post">
<td>Goat Simulator</td>
<td>$11.95</td>
<td><input type="submit" name="Submit" value="Add"></td>
<input type="hidden" name="id" value="1">
<input type="hidden" name="desc" value="Goat Simulator">
<input type="hidden" name="price" value="11.95">
</form>
</tr>
<tr>
<form action="AddToShoppingCart.jsp" method="post">
<td>Metal Gear Solid V</td>
<td>$59.99</td>
<td><input type="submit" name="Submit" value="Add"></td>
<input type="hidden" name="id" value="2">
<input type="hidden" name="desc" value="Metal Gear Solid V">
<input type="hidden" name="price" value="59.99">
</form>
</tr>
<tr>
<form action="AddToShoppingCart.jsp" method="post">
<input type ="submit" name="empty" id="empty-button" value="Empty Cart"/>
</form>
Clear
</tr>
</table>
</body>
</html>
Here's the second page for the entire page
<%# page errorPage="errorpage.jsp" %>
<%# page import="java.util.*" %>
<jsp:useBean id="cart" scope="session" class="beans.ShoppingCart" />
<%#page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<title>Shopping Cart Contents</title>
</head>
<body>
<center>
<table width="300" border="1" cellspacing="0"
cellpadding="2" border="0">
<caption><b>Shopping Cart Contents</b></caption>
<tr>
<th>Description</th>
<th>Price</th>
<th>Quantity</th>
</tr>
<%
Enumeration e = cart.getEnumeration();
String[] tmpItem;
// Iterate over the cart
while (e.hasMoreElements()) {
tmpItem = (String[])e.nextElement();
%>
<tr>
<td><%=tmpItem[1] %></td>
<td align="center">$<%=tmpItem[2] %></td>
<td align="center"><%=tmpItem[3] %></td>
</tr>
<%
}
%>
</table>
</center>
Back to Catalog
</body>
</html>

Related

Problem with sending id from one jsp to another (update link)

I have a problm with update link for updating my transaction. At one jsp I have a list with transactions, and after pressing Update" which is link i wanted to pass transactionId, update it, save and get back to list. I've used c:param hidden and it doesnt work. I have no idea why it doesnt pass id and autofill forms. It seems like values are passed in session when ive clicked testing transaction:
http://localhost:8080/transaction/addTransaction?transactionId=64&userId=1
Here is transaction Controller:
#Controller
#RequestMapping("/transaction")
public class TransactionController {
#Autowired
TransactionService transactionService;
#Autowired
CategoryService categoryService;
#Autowired
UserService userService;
#GetMapping("/addTransaction")
public String transactionsList(Model theModel){
Transaction transaction = new Transaction();
theModel.addAttribute("user",userService.getAllUsers());
theModel.addAttribute("category", categoryService.getAllCategories());
theModel.addAttribute("newTransaction", transaction);
return "addTransaction";
}
#PostMapping("/saveTransaction")
public String saveTransaction(#ModelAttribute("newTransaction") Transaction
newTransaction,
BindingResult theBindingResult,
HttpServletRequest request) throws
ParseException {
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
String date = request.getParameter("transactionDate");
LocalDate localDate = LocalDate.parse(date, formatter);
Date formatedDate =
Date.from(localDate.atStartOfDay().toInstant(ZoneOffset.ofHours(-3)));
newTransaction.setTransactionDate(formatedDate);
transactionService.saveTransaction(newTransaction);
return "redirect:/user/userPage";
}
#GetMapping("/deleteTransaction")
public String deleteUser(#RequestParam("transactionId") int idFromTransactionToDelete,
#RequestParam("userId") int loggedUserId,
RedirectAttributes redirectAttributes){
transactionService.deleteTransactionById(idFromTransactionToDelete);
User loggedUser = userService.getUserById(loggedUserId);
redirectAttributes.addFlashAttribute("loggedUser", loggedUser);
return "redirect:/user/userPage";
}
#GetMapping("/updateTransaction")
public String updateUser(#RequestParam("transactionId") int
idFromTransactionToUpdate,
#RequestParam("userId") int loggedUserId,
RedirectAttributes redirectAttributes,
Model theModel){
Transaction transactionToUpdate = transactionService.getSingleTransactionById(idFromTransactionToUpdate);
transactionToUpdate.setUser(userService.getUserById(loggedUserId));
theModel.addAttribute("newTransaction",transactionToUpdate);
theModel.addAttribute("category", categoryService.getAllCategories());
User loggedUser = userService.getUserById(loggedUserId);
redirectAttributes.addFlashAttribute("loggedUser", loggedUser);
redirectAttributes.addFlashAttribute("newTransaction",
transactionToUpdate);
return "addTransaction";
}
}
Transactions list page:
<%# page contentType="text/html;charset=UTF-8" language="java" %>
<%# taglib prefix="mvc" uri="http://www.springframework.org/tags/form" %>
<%# taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<%# taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%# taglib prefix="fmt" uri="http://java.sun.com/jstl/fmt" %>
<html>
<head>
<title>User page</title>
</head>
<body>
<c:url var="addTransactionLink" value="/transaction/addTransaction"/>
<c:url var="addFixedTransactionLink"
value="/fixedTransaction/addFixedTransaction"/>
<h1>Welcome ${loggedUser.login} !</h1>
<br>
<h2>Here are your latest transactions:</h2>
<br>
<a href=${addTransactionLink}>
<input type="button" value="Add Transaction"/>
</a>
<a href=${addFixedTransactionLink}>
<input type="button" value="Add Fixed Transaction"/>
</a>
<table>
<tr>
<th>Category</th>
<th>Price</th>
<th>Description</th>
<th>Date</th>
</tr>
<c:forEach var="transaction" items="${userTransactions}">
<c:url var="deleteTransactionLink"
value="/transaction/deleteTransaction">
<c:param name="transactionId"
value="${transaction.transactionId}"/>
<c:param name="userId" value="${loggedUser.id}"/>
</c:url>
<c:url var="updateTransactionLink"
value="/transaction/addTransaction">
<c:param name="transactionId"
value="${transaction.transactionId}"/>
<c:param name="userId" value="${loggedUser.id}"/>
</c:url>
<tr>
<td>${transaction.category.categoryName}</td>
<td>${transaction.moneyAmount}</td>
<td>${transaction.description}</td>
<td>${transaction.transactionDate}</td>
<td>Delete </td>
<td>Update </td>
<td>${transaction.transactionId}</td>
</tr>
</c:forEach>
</table>
</body>
</html>
And add transaction formular:
<%# taglib prefix="mvc" uri="http://www.springframework.org/tags/form" %>
<%# taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<%# taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%# page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>Add Transaction Form</title>
<link rel="stylesheet"
href="${pageContext.request.contextPath}/resources/css/style.css"/>
</head>
<body>
<h1>Add transaction to database:</h1>
<form:form action="saveTransaction" modelAttribute="newTransaction"
method="post">
<form:hidden path="transactionId"/>
${newTransaction.toString()}
${newTransaction.transactionId}
<table>
<tr>
<td><label>Choose category:</label></td>
<td><form:select name="category.id" path="category.id">
<c:forEach items="${category}" var="category">
<form:option value="${category.id}">${category.categoryName}
</form:option>
</c:forEach>
</form:select>
</tr>
<tr>
<td><label>Choose user:</label></td>
<td><form:select name="user.id" path="user.id">
<c:forEach items="${user}" var="user">
<form:option value="${user.id}">${user.login}
</form:option>
</c:forEach>
</form:select>
</tr>
<tr>
<td><label>Amount:</label></td>
<td><form:input path="moneyAmount" />
</td>
</tr>
<tr>
<td><label>Transaction date:</label></td>
<td><form:input type = "date" path="transactionDate"/>
</td>
</tr>
<tr>
<td><label>Description:</label></td>
<td><form:input path="description" />
</td>
</tr>
<tr>
<label></label>
<td><input type="submit" value="Submit" class="save"/>
</td>
</tr>
</table>
</form:form>
</body>
</html>
Problem seems to be in your code. You have defined in jsp:
<c:url var="updateTransactionLink"
value="/transaction/addTransaction">
while in java code:
#GetMapping("/updateTransaction")
public String updateUser(#RequestParam("transactionId") int
In JSP Change it to :
<c:url var="updateTransactionLink"
value="/transaction/updateTransaction">

How can a execute a query in JSP on text change of input box

Now i am doing this code which is working on submit button click.
<%#page import="java.sql.CallableStatement"%>
<%#page import="javax.imageio.ImageIO"%>
<%#page import="java.io.ByteArrayOutputStream"%>
<%#page import="java.awt.image.BufferedImage"%>
<%#page import="java.io.InputStream"%>
<%#page import="java.sql.ResultSet"%>
<%#page import="connectionss.Connectionss"%>
<%# 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">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<form action="ShowUSerInfo.jsp" method="post">
<input type="text" name="tagID">
<input type="submit" value="Search" name="submit" >
</form>
<%
String TAGID="";
String y=request.getParameter("submit");
if("Search".equals(y))
{
TAGID = request.getParameter("tagID");
out.println(TAGID);
String GetUserpass = "{call sp_USerInfoByTagID(?)}";
//Connection conn = Connection.GetConnection();
CallableStatement cs;
cs = Connectionss.GetConnection().prepareCall(GetUserpass);
cs.setString(1,TAGID);
%>
<table border="1">
<th>First Name</th>
<th>last Name Name</th>
<th>Student ID</th>
<th>Address</th>
<th>NIC</th>
<%
ResultSet rs1;
rs1=cs.executeQuery();
while(rs1.next()){
String UserName=rs1.getString("fId_FirstName");
String UserID= rs1.getString("fId_User_UniversityID");
String Adress = rs1.getString("fId_Address");
String NIC = rs1.getString("fId_NIC");
String lastName = rs1.getString("fId_LastName");
%>
<tr >
<td><span style="color:red;"><%= UserName %></span></td>
<td> <span style="color:red;"><%= lastName %></span></td>
<td><span style="color:red;"><%= UserID %></span></td>
<td><span style="color:red;"><%= Adress %></span></td>
<td><span style="color:red;"><%= NIC %></span></td>
</tr>
</table>
<%}} %>
</body>
</html>
But i want to execute this code when text changes on input box. Basically text box is getting value from NFC cards. so when i tap my NFC card on Reader value is transfer to text box and at this time i want to execute my sql query that will take the user information against TAGID.
since jsp is server side you'll need to collect the input on client and make a ajax call.
<form action="ShowUSerInfo.jsp" method="post">
<input type="text" id="text" name="tagID">
<input type="submit" value="Search" name="submit" >
</form>
<div id="#res></div>
javascript :
$('#text').change(function(e){
$.ajax({url: "someurl", success: function(result){
$("#res").html(result);
}});
});
});
this will perfectly work in your case,
Let's say our HTML looks something like,
<form>
<input id="txt" type="text" name="name"/>
<input id="btn" type="button" value="change"/>
</form>
Java-Script like,
$(document).ready(function(){
$('#txt').keypress(function(e){
ontextchange();
});
$('#txt').keyup(function(e){
if(e.keyCode == 8)
{
//if user erase from text-box then comes here...
}
});
function ontextchange(){
//do whatever while text change, i.e. ajax call or something else...
}
});

Spring MVC JSP Form using multiple objects needs drop-down list

My Spring JSP Form uses 2 classes that I put in a wrapper class. The employee name part works. But now I need to create a drop-down list of Clients to choose from. I'm updating someone else's code, I believe "resultBoard.getFilteredResultsClients()" will return a List of Clients. Any tips or sample code of a Spring JSP Form that uses a drop-down to select from a List?
Java wrapper class with employee and client classes inside:
public class EmployeeFormWrapper {
private NewEmployeeVM employee = new NewEmployeeVM();
private ClientVM client = new ClientVM();
public NewEmployeeVM getEmployee(){
return this.employee;
}
public ClientVM getClient(){
return this.client;
}
}
My Controller class:
#Controller
#SessionAttributes({"resultBoard", "filterBoard"})
public class NewEmployeeController {
#Autowired
NewEmpDAO newEmpDAO;
#RequestMapping(value = "NewEmpInput", method = RequestMethod.GET)
public String promptEmployee(Model model)
{
model.addAttribute("myForm", new EmployeeFormWrapper());
return "NewEmpInput";
}
#RequestMapping(value = "NewEmpInput", method = RequestMethod.POST)
public String newEmployee(#ModelAttribute("myForm") EmployeeFormWrapper myForm)
{
NewEmployeeVM employee = myForm.getEmployee();
ClientVM client = myForm.getClient();
System.out.println("Employee = " + employee.getFirstName() + " " + employee.getLastName());
System.out.println("Client = " + client.getText());
try{newEmpDAO.writeNewEmployee(employee);}
catch (Exception e){
e.printStackTrace();
}
return "ConfirmNewEmp";
}
}
My JSP:
<%# page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%# taglib prefix="spring" uri="http://www.springframework.org/tags"%>
<%# taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
<%# taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%# page session="false"%>
<%# page import="com.model.FilterBoard"%>
<!DOCTYPE html>
<!-- <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> -->
<html>
<head>
<link rel="stylesheet"
href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
<link href="assets/css/bootstrap.css" rel="stylesheet">
<link href="assets/css/bootstrap-responsive.css" rel="stylesheet">
<link rel="stylesheet"
href="<c:url value='/resources/css/mainStyle.css'/>">
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<style type="text/css">
body {
color:#000000;
// background-color:#FFFFFF;
background-color:tan;
background-image:url('Background Image');
background-repeat:no-repeat;
}
a { color:#0000FF; }
a:visited { color:#800080; }
a:hover { color:#008000; }
a:active { color:#FF0000; }
</style>
<title>New Employee Proposed To Project</title>
</head>
<body class="NewEmpBody">
<p>New Employee</p>
<form:form commandName="myForm" modelAttribute="myForm">
<table>
<tr>
<td>First Name:</td>
<td><form:input path="employee.firstName" /></td>
<td>Middle Initial:</td>
<td><form:input path="employee.middleInitial" /></td>
</tr>
<tr>
<td>Last Name:</td>
<td><form:input path="employee.lastName" /></td>
</tr>
<tr>
<td>Clients:</td>
<td>
<ul>
<c:forEach items="${resultBoard.getFilteredResultsClients()}"
var="filteredResultsClient">
<li><form:button name="toggleClient" class="btn btn-link"
value='${filteredResultsClient.toJSON()}'>
${filteredResultsClient.getText()}
</form:button></li>
</c:forEach>
</ul>
</td>
</tr>
<tr>
<td colspan="3"><input type="submit" value="Submit" /></td>
</tr>
</table>
</form:form>
</body>
</html>
I got it, I changed my JSP to look like this and it gave me a nice drop-down list:
<body class="NewEmpBody">
<p>New Employee Proposed To Project Before Entered Into OpenAir</p>
<form:form commandName="myForm" modelAttribute="myForm">
<table>
<tr>
<td>First Name:</td>
<td><form:input path="employee.firstName" /></td>
<td>Middle Initial:</td>
<td><form:input path="employee.middleInitial" /></td>
</tr>
<tr>
<td>Last Name:</td>
<td><form:input path="employee.lastName" /></td>
</tr>
<tr>
<td>Client :</td>
<td><form:select path="client.text">
<form:option value="NONE" label="--- Select ---" />
<form:options items="${resultBoard.getFilteredResultsClients()}" />
</form:select>
</td>
</tr>
<tr>
<td colspan="3"><input type="submit" value="Submit" /></td>
</tr>
</table>
</form:form>
</body>

How to do validation in java script involve two jsp page?

First page's image
Second page's image
First page's code
<jsp:useBean id="labelBean" scope="session"
class="my.com.infopro.ibank.ui.bean.LabelBean" />
<jsp:useBean id="txLimitMaintBean" scope="session"
class="my.com.infopro.ibank.ui.bean.TxLimitMaintBean" />
<jsp:useBean id="lang" scope="session"
class="my.com.infopro.ibank.ui.bean.LanguageBean" />
<%# page import="java.util.Iterator"%>
<%# page import="my.com.infopro.ibank.dto.TxLimitMaintDto"%>
<%# page import="my.com.infopro.ibank.ui.bean.TxLimitMaintBean"%>
<%
request.getSession(true);
String contextPath = request.getContextPath();
txLimitMaintBean.queryTxList();
//String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>
<%
labelBean.getLabel("TRANSACTION_LIMIT");
%>
</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<jsp:include page="/ScriptHeader.jsp"/>
</head>
<body>
<form name="form" method="POST" action="" dir="<%=lang.getDir()%>">
<table width="500" border="0" align="center">
<tr>
<td colspan="4"> </td>
</tr>
<tr>
<td colspan="4">
<p align="left" class="mainHeader"><%=labelBean.getLabel("TRANSACTION_LIMIT")%>
</p>
</td>
</tr>
<tr>
<td colspan="4"> </td>
</tr>
<tr>
<td colspan="4">
<p align="left" class="subHeader"><%=labelBean.getLabel("CURR_TRNSCT_LMT")%></p>
</td>
</tr>
<tr>
<td colspan="3"><div align="center">
<p class="statusError">
<%if(request.getParameter("error") != null) out.println(labelBean.getLabel(request.getParameter("error"))); else out.println("");%>
</p>
</div></td>
</tr>
<tr>
<td colspan="4"> </td>
</tr>
<tr>
<td colspan="4">
<p align="left"><%=labelBean.getLabel("FILL_IN_NEWLMT")%></p>
</td>
</tr>
<tr>
<td colspan="4">
<p align="left"><%=labelBean.getLabel("MAX_LMT")%></p>
</td>
</tr>
</table>
<br />
<table align="center">
<tr class="table_header">
<td width="130" align="left" class="tableHeader"><%=labelBean.getLabel("LIMIT")%></td>
<td width="130" align="left" class="tableHeader"><%=labelBean.getLabel("EXISTING_LIMIT")%></td>
<td width="130" align="right" class="tableHeader"><%=labelBean.getLabel("MAX_LIMIT")%></td>
<td width="80" align="left" class="tableHeader"></td>
</tr>
<%
for (Iterator iter = txLimitMaintBean.getTxLimitMaintList().iterator(); iter
.hasNext();) {
TxLimitMaintDto txLimitMaintDto = (TxLimitMaintDto) iter.next();
%>
<tr class="tableRowEven">
<td><%=txLimitMaintDto.getTxType()%></td>
<td><%=txLimitMaintDto.getTxCurrLimit()%></td>
<td><%=txLimitMaintDto.getTxMaxLimit()%></td>
<td><%=labelBean.getLabel("UPDATE")%> </td>
</tr>
<%
}
%>
</table>
<br />
<br />
<table width="500" border="0" align="center">
<tr>
<td align="left" class="footer"><%=labelBean.getLabel("DISCLAIMER")%></td>
</tr>
<tr>
<td align="left" class="footer">
<ul>
<li><%=labelBean.getLabel("TRANSFER_SUCCESS")%></li>
</ul>
</td>
</tr>
</table>
<jsp:include page="/Footer.jsp" />
</form>
</body>
</html>
Second page's code
<jsp:useBean id="labelBean" scope="session"
class="my.com.infopro.ibank.ui.bean.LabelBean" />
<jsp:useBean id="txLimitMaintBean" scope="session"
class="my.com.infopro.ibank.ui.bean.TxLimitMaintBean" />
<jsp:useBean id="lang" scope="session"
class="my.com.infopro.ibank.ui.bean.LanguageBean" />
<%# page import="java.util.Iterator"%>
<%# page import="my.com.infopro.ibank.dto.TxLimitMaintDto"%>
<%# page import="my.com.infopro.ibank.ui.bean.TxLimitMaintBean"%>
<%
//request.getSession(true);
String contextPath = request.getContextPath();
//String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>
<%
labelBean.getLabel("TRANSACTION_LIMIT");
%>
</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<jsp:include page="/ScriptHeader.jsp"/>
<script language="JavaScript">
function back() {
document.form.action="<%=contextPath %>/TxLimitMaintServlet?tranx=start";
document.form.submit();
}
function validateAndSubmit() {
var msg1 = "<%=labelBean.getLabel("MSG_REQUIRED_FIELD")%>";
var msg2 = "<%=labelBean.getLabel("MSG_CANNOT_CONTAIN_CHARACTER")%>";
var msg3 = "<%=labelBean.getLabel("MSG_IN_THE_FIELD")%>";
var msg4 = "<%=labelBean.getLabel("MSG_PLEASE_ENTER")%>";
var msg5 = "<%=labelBean.getLabel("WITH")%>";
var msg6 = "<%=labelBean.getLabel("TO")%>";
var msg7 = "<%=labelBean.getLabel("MSG_CHARACTER")%>";
var msg8 = "<%=labelBean.getLabel("MSG_PLEASE_ENTER_VALID_NUMBER")%>";
var msg9 = "<%=labelBean.getLabel("MSG_REQUIRED_FIELD")%>";
var msg10 = "<%=labelBean.getLabel("MSG_WITH_EXACTLY")%>";
var msg11 = "<%=labelBean.getLabel("MSG_WITH_VALID_DATE")%>";
var msg12 = "<%=labelBean.getLabel("MSG_EXAMPLE_DATE")%>";
var msgNum11 = "<%=labelBean.getLabel("MSG_WITH_A_MINIMUM_VALUE_OF")%>";
var msgNum12 = "<%=labelBean.getLabel("MSG_WITH_A_MAX_VALUE_OF")%>";
var msgNum13 = "<%=labelBean.getLabel("MSG_PLEASE_ENTER_ROUND_INETEGER")%>";
var msgNum14 = "<%=labelBean.getLabel("MSG_PLEASE_ENTER_AT_MOST")%>";
var msgNum15 = "<%=labelBean.getLabel("MSG_DECIMAL_PLACES")%>";
var maxLimit = parseInt(form.maxLimit.value);
var newLimit = parseInt(form.txNewLimit.value);
if (! validateNumericEntry(form.txNewLimit, "<%=labelBean.getLabel("NEW_LIMIT")%>" + " ", true, 2, 1, <%=TxLimitMaintBean.getTotalMaxLimit()%>, msg9, msg8, msg4,
msgNum11, msgNum12, msgNum13, msgNum14, msgNum15))
return false;
if( newLimit > maxLimit){
alert("<%=labelBean.getLabel("MSG_CANNOT_EXCEED")%>");
return false;
}
return true;
}
</script>
</head>
<body>
<form name="form" method="POST" action="<%=contextPath%>/TxLimitMaintServlet?tranx=confirm" onsubmit="#" dir="<%=lang.getDir()%>">
<table width="500" border="0" align="center">
<tr>
<td colspan="4"> </td>
</tr>
<tr>
<td colspan="4">
<p align="left" class="mainHeader"><%=labelBean.getLabel("TRANSACTION_LIMIT")%>
</p>
</td>
</tr>
<tr>
<td colspan="4"> </td>
</tr>
<tr>
<td colspan="4">
<p align="left" class="subHeader"><%=labelBean.getLabel("CURR_TRNSCT_LMT")%></p>
</td>
</tr>
<tr>
<td colspan="4"> </td>
</tr>
<tr>
<td colspan="4">
<p align="left"><%=labelBean.getLabel("FILL_IN_NEWLMT")%></p>
</td>
</tr>
<tr>
<td colspan="4">
<p align="left"><%=labelBean.getLabel("MAX_LMT")%></p>
</td>
</tr>
</table>
<br />
<table align="center">
<tr class="table_header">
<td width="130" align="left" class="tableHeader"><%=labelBean.getLabel("LIMIT")%></td>
<td width="130" align="left" class="tableHeader"><%=labelBean.getLabel("EXISTING_LIMIT")%></td>
<td width="130" align="left" class="tableHeader"><%=labelBean.getLabel("NEW_LIMIT")%></td>
<td width="80" align="right" class="tableHeader"><%=labelBean.getLabel("MAX_LIMIT")%></td>
</tr>
<tr class="tableRowEven">
<td><%=txLimitMaintBean.getTxType()%></td>
<td><input name="txCurrLimit" + type="text"
value="<%=txLimitMaintBean.getTxCurrLimit()%>" readonly="readonly"></td>
<td><input name="txNewLimit" type="text"></td>
<td><%=txLimitMaintBean.getTxMaxLimit()%></td>
<td><input name="maxLimit" value="<%=txLimitMaintBean.getTxMaxLimit()%>" type="hidden"></input></td>
</tr>
</table>
<br />
<table align="center">
<tr>
<td align="right"><input type="button" class="button" value="Back" onclick="back();"></td>
<td align="right"><input type="reset" class="button"
value="Reset"></td>
<td align="left"><input type="submit" class="button" value="Next"
onClick="return validateAndSubmit();"></td>
</tr>
</table>
<br />
<table width="500" border="0" align="center">
<tr>
<td align="left" class="footer"><%=labelBean.getLabel("DISCLAIMER")%></td>
</tr>
<tr>
<td align="left" class="footer">
<ul>
<li><%=labelBean.getLabel("TRANSFER_SUCCESS")%></li>
</ul>
</td>
</tr>
</table>
<jsp:include page="/Footer.jsp" />
</form>
</body>
</html>
The problem is: how can I validate add up of both 3rd Party Transfer and Bill Payment can not exceed 10,000?
you wouldn't be able to javascript to get the values from the previous page. any reason why you can't access them from the session to compute? remember that if you want to use javascript to calculate the totals, you'll need to render the other value(s) on the page (you could use a hidden input so it doesn't show up).

How to access dynamically created text box in jsp page

How can I access the values in the textBox to pass it into a SQL database. What will be the text-box's unique name in each row?
The code is as follows:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%# page import="java.sql.*" %>
<%# page import="java.io.*" %>
<html>
<head><title>orderSample</title>
<script src="http://code.jquery.com/jquery-latest.min.js"></script>
<script>
$(document).ready(function() {
$('.add').click(function() {
$(this).closest('tr').find('.quantity').attr('disabled', !this.checked);
});
});
</script>
</head>
<body bgcolor="white">
<form method=post name=orderForm>
<h1>Data from the table 'item details' of database 'caffe' in sql </h1>
<%
System.out.println("adadadasasasasasasasasas");
int i = 0;
%>
<TABLE cellpadding="15" border="1" style="background-color: #ffffcc;">
<TR>
<TD>ORDER ID</TD>
<TD>ORDER PRICE</TD>
<TD>Quantity</TD>
<TD>Add Item</TD>
</TR>
<%do{
System.out.println("I am in Ob");
%>
<TR>
<TD>asdadsas</TD>
<TD>asdasdasd</TD>
<td><input type="checkbox" class="add" /></td>
<td><input type="text" class="quantity" /></td>
<!-- <td><INPUT TYPE="TEXT" NAME="NAME_TEXT<%=i%>" VALUE="" IsEnabled="{Binding ElementName=checkBox1, Path=IsChecked}"/></td>
<td><INPUT TYPE="TEXT" NAME="NAME_TEXT<%=i%>" VALUE="" /></td>
<td><input type="checkbox" name="others<%=i%>" onclick="enable_text(this.checked,<%=i%>)" ></td>-->
</TR>
<%i++; }while(i<2); %>
</TABLE>
</form>
</body>
</html>
Either give them all the same name
<td><input type="text" name="name" /></td>
so that you can use
String[] values = request.getParameterValues("name");
Or give them all the same prefix
<td><input type="text" name="name${someDynamicValue}" /></td>
so that you can use
for (Entry<String, String[]> entry : request.getParameterMap().entrySet()) {
if (entry.getKey().startsWith("name")) {
String value = entry.getValue()[0];
// Add to list?
}
}
Or when it is an incremental suffix
<td><input type="text" name="name${index}" /></td>
then use
for (int i = 0; i < Integer.MAX_VALUE; i++) {
String value = request.getParameter("name" + i);
if (value == null) {
break;
}
// Add to list?
}

Categories

Resources