I want to create a page in which input field appears dynamically depends upon select tag. For this I create a jsp file name receiptBudget.jsp
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script src="http://localhost:8088/Gpms/js/jquery-1.9.1_1.js"></script>
<script src="http://localhost:8088/Gpms/js/jquery.inputlimiter.1.3.1.js"></script>
<script src="http://localhost:8088/Gpms/js/jquery-ui.js"></script>
<script src="http://localhost:8088/Gpms/js/jquery.inputlimiter.1.3.1.min.js">
<script language="javascript">
function getrecpHead() {
var recpLedHead = document.getElementById('recpLedHead').value;
$.get("budget.action", {recpLedHead: $("#recpLedHead").val()}, displayBlocks);
}
function displayBlocks(response) {
if (response) {
$("#divBudget").html(response);
}
}
</script>
</head>
<body>
<s:form method="post" name="receiptBudget">
<table border="1">
<tr>
<td colspan="1"><div align="center">Date</div></td>
<td><div align="center"><label for="transDate" id="transDate">
<%=dateFormat.format(calobj.getTime())%></label></div>
</td>
<td><div align="center">Financial Year </div></td>
<td colspan="2"><div align="center"><label for="finyear" id="finyear">
<%=financialYear%></label></div>
</td>
</tr>
<tr>
<td colspan="2"><div align="center">LedgerHead Head </div></td>
<td colspan="3"> <div align="center">
<select name="recpLedHead" id="recpLedHead" onchange="getrecpHead()">
<option value="0">Select Ledger Head</option>
<%
String ledgerName;
for (int i = 0; i < ledlist.size(); i++) {
ledgerName = ledlist.get(i);
%>
<option value="<%=ledgerName%>"><%=ledgerName%></option>
<%}%>
</select>
</div></td>
</tr>
<tr>
<td width="76" colspan="1"><div align="center">CollectionHead</div></td>
<td width="117"><div align="center">Preceeding Year</div></td>
<td width="114"><div align="center">Current Year </div></td>
<td width="112"><div align="center">Next Year </div></td>
<td width="112"><div align="center">Remarks </div></td>
</tr>
</table>
<table>
<s:form action="budgetSave">
<div id="divBudget">
</div>
<tr>
<td colspan="1"><s:submit value="save"></s:submit></td>
</tr>
</s:form>
</table>
</s:form>
</div>
</body>
</html>
--------------and calling jsp through action class is getRecpHead.jsp
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<table>
<s:iterator value="mxplist" id="mxplist">
<tr>
<td><s:textfield name="collectionHead" theme="simple"/></td>
<td><s:textfield name="receiptOn" theme="simple"/></td>
<td><s:textfield name="plan" theme="simple"/></td>
<td><s:textfield name="budgeted" theme="simple"/></td>
</tr>
</s:iterator>
</table>
</body>
action file is ReceiptBudget.java
public class ReceiptBudget extends ActionSupport {
private HttpServletRequest request;
private HttpServletResponse response;
List<MasterCollectionhead> mxplist;
public ReceiptBudget() {
}
#Override
public String execute() throws Exception {
HttpSession hs = request.getSession();
UserMaster user = (UserMaster) hs.getAttribute("user");
String recpHead = request.getParameter("recpLedHead");
System.out.println("receipt"+recpHead);
SessionFactory sf = GpmsHibernateUtil.getSessionFactory();
Session sess = sf.openSession();
Transaction tx = sess.beginTransaction();
Query qq = sess.createQuery("from MasterCollectionhead as mba where mba.ledgerId "
+ " in (SELECT mlh.id.ledgerId FROM MasterLedgerhead mlh WHERE mlh.admHead = ? and
+" mlh.id.gpCode = ?) "
+ " and mba.id.gpCode = ?");
qq.setString(0, recpHead);
qq.setString(1, user.getGpCode());
qq.setString(2, user.getGpCode());
mxplist = (List<MasterCollectionhead>)qq.list();
return "success";
}
public String save() throws Exception {
System.out.println("mxplist"+mxplist.size());
return "success";
}
public List<MasterCollectionhead> getMxplist() {
return mxplist;
}
public void setMxplist(List<MasterCollectionhead> mxplist) {
this.mxplist = mxplist;
}
#Override
public void setServletRequest(HttpServletRequest request) {
this.request = request;
}
#Override
public void setServletResponse(HttpServletResponse response) {
this.response = response;
}
}
and the struts.xml tag is
<action name="budget" class="com.gpms.ReceiptBudget" method="execute">
<result name="success">/budget/getRecpHead.jsp</result>
<result name="input">/budget/receiptBudget.jsp</result>
</action>
<action name="budgetSave" class="com.gpms.ReceiptBudget" method="save">
<result name="success">/budget/receiptBudget.jsp</result>
<result name="input">/budget/home.jsp</result>
</action>
finally i want to save data entered in textbox appeard through iterator
Related
i am creating the Asp.net MVC Project in Bank Balance Checking.if i enter the correct account no relevant balance want to display but not not displayed while i am running the programming i got the error was Additional information: The underlying provider failed on Open.
what i tried so far i attached below.
Index.cshtml
#{
ViewBag.Title = "Index";
}
<div class="row">
<div class="col-sm-8">
#using (Html.BeginForm("Index", "home", FormMethod.Post, new { id = "popupForm" }))
{
<table class="table table-bordered">
<caption> Add Products </caption>
<tr>
<th>Account No</th>
<th>Account Holder Name</th>
<th>Balance</th>
</tr>
<tr align="center">
<td>
<input type="text" class="form-control" placeholder="Account No" id="accno" name="accno" size="50px">
</td>
<td>
<input type="text" class="form-control" id="accname" size="25px" name="accname"
placeholder="price" disabled>
</td>
<td>
<input type="number" class="form-control" id="balance" name="balance"
placeholder="qty" size="25px" required>
</td>
</tr>
</table>
}
</div>
</div>
<hr />
#Scripts.Render("~/bundles/jquery")
#section scripts{
<script src="~/Scripts/jquery-3.4.1.js"></script>
<script src="~/Scripts/jquery-3.4.1.min.js"></script>
<script src="~/Scripts/jquery.validate.js"></script>
<script src="//cdn.datatables.net/1.10.19/js/jquery.dataTables.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-confirm/3.3.2/jquery-confirm.min.js"></script>
<script>
getProductcode();
function getProductcode()
{
$("#accno").empty();
$("#accno").keyup(function (e) {
var q = $("#accno").val();
if ($('#accno').val().length === 0) {
$.alert({
title: 'Error!',
content: "Please Enter the Barcode",
type: 'red',
autoClose: 'ok|2000'
});
return false;
}
$.ajax({
type: "POST",
url: '/home/Getid?id=' + $("#accno").val(),
dataType: "JSON",
success: function (data)
{
console.log(data);
$('#accname').val(data.accname);
$('#balance').val(data.balance);
},
error: function (xhr, status, error)
{
// alert("The barcode entered is not correct");
}
});
return true;
});
}
</script>
}
#section styles{
<link href="~/Content/bootstrap.css" rel="stylesheet" />
<link href="~/Content/bootstrap.min.css" rel="stylesheet" />
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/jquery-confirm/3.3.2/jquery-confirm.min.css">
<link rel="stylesheet" href="//cdn.datatables.net/1.10.19/css/jquery.dataTables.min.css">
}
HomeController
//you don't need this here except you want to use Dependency injection
bankEntities dc = new bankEntities();
public ActionResult Index()
{
return View();
}
public string accno { get; set; }
[HttpPost]
public JsonResult Getid(String Id)
{
var std = dc.accounts.Where(a => a.accno == Id).FirstOrDefault();
return Json(std, JsonRequestBehavior.AllowGet);
}
}
I want to change creating table conditions like this:
There is a way of creating table via list model. My aim, when input a number in Determine Number Text Box, then the table will change according to Determine Number.
Example: If DetermineNumber is 5, then the table's row is 5 and the structure of this table will be same like older (A column 0 and B column 0++).
Here is my code:
//My Home Controller
using Microsoft.AspNetCore.Mvc;
using MyWeb.Models;
using System.Collections.Generic;
namespace MyWeb.Controllers
{
public class HomeController : Controller
{
public IActionResult Index()
{
var send_class = new GetChecking();
var send_list = new List<MyClass>();
send_class.DetermineNumber = 10;
for (int i = 0; i < send_class.DetermineNumber; i++)
{
send_list.Add(new MyClass { A = 0, B = i });
}
send_class.GetMyList = send_list;
return View(send_class);
}
}
}
//My Class
using System.Collections.Generic;
namespace MyWeb.Models
{
public class GetChecking
{
public int DetermineNumber { get; set; }
public List<MyClass> GetMyList { get; set; }
}
public class MyClass
{
public double A { get; set; }
public double B { get; set; }
}
}
Lastly, here is my Index.cshtml:
<!-- My Index.cshtml -->
#model GetChecking
#{
Layout = null;
}
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>Index</title>
</head>
<body>
<div align="center">
<table id="tablex">
<tbody>
<tr>
<td>Tablex Row Count</td>
<td asp-for="#Model.DetermineNumber">#Html.TextBoxFor(m => Model.DetermineNumber)</td>
</tr>
</tbody>
</table>
</div>
<p></p>
<div align="center">
<table id="tablex">
<thead>
<tr><th colspan="2">My Main</th></tr>
<tr>
<th colspan="1">A</th>
<th colspan="1">B</th>
</tr>
</thead>
<tbody>
#for (int i = 0; i < Model.DetermineNumber; i++)
{
<tr>
<td asp-for="#Model.GetMyList[i].A">#Html.TextBoxFor(m => Model.GetMyList[i].A)</td>
<td asp-for="#Model.GetMyList[i].B">#Html.TextBoxFor(m => Model.GetMyList[i].B)</td>
</tr>
}
</tbody>
</table>
</div>
</body>
</html>
You could place the table in a partial view, when you change the input in Index view, it calls the action to return the partial view with corresponding model data.
It will not refresh the page each time you change the number.Refer to below demo:
1.Index View:
#model GetChecking
<div align="center">
<table id="tablex">
<tbody>
<tr>
<td>Tablex Row Count</td>
<td><input asp-for="#Model.DetermineNumber" id="number" name="number" oninput="changeNum()" /></td>
</tr>
</tbody>
</table>
</div>
<div align="center" id="indexWrapper">
<partial name="_IndexPartial" model="#Model" />
</div>
#section Scripts
{
<script>
function changeNum() {
var num = $("#number").val();
$.ajax(
{
type: "GET",
url: "/Home/GetTable?Num=" + num,
success: function (res) {
$("#indexWrapper").html(res)
}
});
}
</script>
}
2.Add a partial view _IndexPartial.cshtml in Shared folder
#model GetChecking
<table id="tablex">
<thead>
<tr><th colspan="2">My Main</th></tr>
<tr>
<th colspan="1">A</th>
<th colspan="1">B</th>
</tr>
</thead>
<tbody>
#for (int i = 0; i < Model.DetermineNumber; i++)
{
<tr>
<td asp-for="#Model.GetMyList[i].A">#Html.TextBoxFor(m => Model.GetMyList[i].A)</td>
<td asp-for="#Model.GetMyList[i].B">#Html.TextBoxFor(m => Model.GetMyList[i].B)</td>
</tr>
}
</tbody>
</table>
3.HttpGet method
public IActionResult GetTable(int num)
{
var send_class = new GetChecking();
var send_list = new List<MyClass>();
send_class.DetermineNumber = num;
for (int i = 0; i < send_class.DetermineNumber; i++)
{
send_list.Add(new MyClass { A = 0, B = i });
}
send_class.GetMyList = send_list;
return PartialView("_IndexPartial",send_class);
}
I try to this but cant work:
#model GetChecking
#{
Layout = null;
}
<div align="center">
<table id="tablex">
<tbody>
<tr>
<td>Tablex Row Count</td>
<td asp-for="#Model.DetermineNumber"><input id="number" name="number" type="text" oninput="changeNum()" /></td>
<td asp-for="#Model.Checking"><input id="mycheck" name="mycheck" type="checkbox" oninput="changeNum()" /></td>
</tr>
</tbody>
</table>
</div>
<div align="center" id="indexWrapper">
<partial name="_IndexPartial" model="#Model" />
</div>
<script src="~/lib/jquery/dist/jquery.js"></script>
<script>
function changeNum() {
var num = $("#number").val();
var che = $("#mycheck").val();
$.ajax(
{
type: "GET",
url:"/Home/GetTable?num=" + num + "&cont=" + che,
success: function (res) {
$("#indexWrapper").html(res)
}
});
}
</script>
I'm battling to make the transition from Classic ASP to ASP.NET. I have the code below that works if I hard code the start date and end date but gives the error: System.Data.SqlClient.SqlException: Must declare the scalar variable "#SDate" when I use parameters. There are may references to this error when I search for it, but I just can't find one that helps me. The page is designed to display two text boxes for the user to enter the start and end date for the search and then click the button to have the data exported to Excel.
<%# Page Language="C#" ContentType="text/html" ResponseEncoding="iso-8859-1" EnableViewStateMac="false"%>
<%# Import Namespace="System.Data" %>
<%# Import Namespace="System.Data.SqlClient" %>
<%# Import Namespace="System.Web.UI.WebControls" %>
<html>
<head>
<title>Export results to Excel</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script language="C#" runat="server">
protected void btnExportToExcel_Click(object sender, EventArgs e) {
ExportToExcel();
}
//Export to Excel from a GridView
protected void ExportToExcel() {
Response.Clear();
Response.Buffer = true;
Response.ContentType = "application/vnd.ms-excel";
Response.AddHeader("content-disposition", "attachment;filename=MyFiles.xls");
Response.Charset = "";
this.EnableViewState = false;
System.IO.StringWriter sw = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter htw = new System.Web.UI.HtmlTextWriter(sw);
gvData.RenderControl(htw);
Response.Write(sw.ToString());
Response.End();
}
public override void VerifyRenderingInServerForm(Control control) {
}
</script>
</head>
<body>
Export results to excel
</body>
<form id="form1" runat="server">
<div>
<h1>
My Files</h1>
<table border="0" cellpadding="0" cellspacing="0" style="width: 100%; height: 12%">
<tr>
<td>
Start date</td>
<td>
<asp:TextBox ID="StartDate" runat="server" Width="200px" Text="2000/01/01"></asp:TextBox>
</td>
</tr>
<tr>
<td>
End date</td>
<td>
<asp:TextBox ID="EndDate" runat="server" Width="200px" Text="2012/11/01"></asp:TextBox>
</td>
</tr>
<tr>
<td>
</td>
<td>
<asp:Button ID="btnExportToExcel" runat="server" Text="Export to Excel" onclick="btnExportToExcel_Click" />
</td>
</tr>
</table>
</div>
<asp:SqlDataSource ID="SqlDataSource" runat="server"
ConnectionString="<%$ ConnectionStrings:KpraxConn %>"
SelectCommand="SELECT Results.IDNumber, [FirstName], [LastName], [DOB], [Gender] FROM [Results] LEFT JOIN Login ON (Results.IDNumber=Login.IDNumber) where ([LogDate]>=#SDate and [LogDate]<=#EDate) ORDER BY [LastName]">
<asp:SelectParameters>
<asp:FormParameter FormField="StartDate" Name="SDate" DefaultValue="2000/01/01" />
<asp:FormParameter FormField="EndDate" Name="EDate" DefaultValue="2012/11/04" />
</asp:SelectParameters>
</asp:SqlDataSource>
<asp:GridView ID="gvData" runat="server" AutoGenerateColumns="False" DataKeyNames="IDNumber"
DataSourceID="SqlDataSource" PageSize="5">
<Columns>
<asp:BoundField DataField="IDNumber" HeaderText="IDNumber" ReadOnly="True"/>
<asp:BoundField DataField="FirstName" HeaderText="FirstName"/>
<asp:BoundField DataField="LastName" HeaderText="LastName"/>
<asp:BoundField DataField="DOB" HeaderText="DOB"/>
<asp:BoundField DataField="Gender" HeaderText="Gender"/>
</Columns>
</asp:GridView>
</form>
</html>
On the button click event call this method
protected void ExportToExcel()
{
Response.Clear();
Response.AddHeader("content-disposition", "attachment;filename=GridView1.xls");
Response.Charset = "";
Response.ContentType = "application/vnd.xls";
StringWriter StringWriter = new System.IO.StringWriter();
HtmlTextWriter HtmlTextWriter = new HtmlTextWriter(StringWriter);
GridView1.RenderControl(HtmlTextWriter);
Response.Write(StringWriter.ToString());
Response.End();
}
I have option of photo upload in my create.gsp page. I'm able to see the uploaded photo in my create page and able to upload my photo in database, but cannot see that photo in my show page.
This is create.gsp page
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta name="layout" content="billing-without-grid" />
<g:set var="entityName"
value="${message(code: 'skeletonBill.label', default: 'SkeletonBill')}" />
<title><g:message code="default.create.label"
args="[entityName]" /></title>
<script>
function showPhoto(imageFile) {
var fileReader = new FileReader();
var image = document.getElementById("uploadPhotoFile");
fileReader.onload = function(e) {
image.src = e.target.result;
}
fileReader.readAsDataURL(imageFile.files[0]);
}
</script>
</head>
<body>
<div class="body">
<div class="container-fluid">
<div class="row">
<div class="span6">
<img src="" name="uploadPhotoFile" id="uploadPhotoFile"
height="200" width="160" />
<table style="width: 25%">
<tbody>
<tr class="prop">
<td valign="top" class="name"><label for="uploadPhoto"><g:message code="uploadInformation.uploadPhoto.label" default="Upload Photo" /></label></td>
<td valign="top" class="value ${hasErrors(bean: uploadInformationInstance, field: 'uploadPhoto', 'errors')}">
<input type="file" id="uploadPhoto" name="uploadPhoto" onchange="showPhoto(this)" />
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
</body>
</html> '
Domain class that I created
class UploadInformation {
static constraints = {
uploadPhoto(nullable:true, maxSize: 16384 /* 16K */)
}
byte[] uploadPhoto
static transients = ["uploadPhoto"]
static mapping = {
uploadPhoto column:"uploadPhoto",sqlType: "blob"
}
}
Anuj.
The problem I see after quick look at your code is:
static transients = ["uploadPhoto"]
UploadPhoto will not be saved to database because it's declarated as transient.
See more details transient properties
can someone please tell me a running example of upload file in kendoui?
As I have tried to upload file and its uploading in view page but when I click on save button I can't find that file in show page.I searched on it on internet then I found some problem of server.So someone please tell me how to use server in my case.I'm working on a grails project
Code That I have Used.:--
<tr class="prop">
<td valign="top" class="name">
<label>File Upload</label>
<input name="photos[]" id="photos" type="file" /><script>$(document).ready(function ()$("#photos").kendoUpload({
autoUpload:true,
upload: onUpload,
error: onError
});
function onError(e) {
// Array with information about the uploaded files
var files = e.files;
if (e.operation == "upload") {
alert("Failed to uploaded " + files.length + " files");
}
// Suppress the default error message
e.preventDefault();
},
function onUpload(e) {
var files = e.files;
if (e.operation == "upload") {
alert("Successfully uploaded " + files.length + " files");
}
});</script>
</td>
</tr>
i'm ading the view file :- create.gsp
<%# page import="ten.SkeletonBill"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta name="layout" content="billing" />
<get var="entityName"
value="${message(code: 'skeletonBill.label', default: 'SkeletonBill')}" />
<title><g:message code="default.create.label"
args="[entityName]" /></title>
<script src="source/kendo.all.js"></script>
<link href="styles/kendo.common.css" rel="stylesheet" />
<link href="styles/kendo.default.css" rel="stylesheet" />
</head>
<body>
<content tag="menu-function">
<li><span class="k-link"><a href="#"
onclick="SkeletonBillForm.submit();return false;"><i
class="icon-plus-sign"></i>
<g:message code="default.button.save.label" /></a></span></li>
</content>
<div class="body">
<h1>
<g:message code="default.create.label" args="[entityName]" />
</h1>
<g:if test="${flash.message}">
<div class="message">
${flash.message}
</div>
</g:if>
<g:hasErrors bean="${skeletonBillInstance}">
<div class="alert alert-error">
<a class="close" data-dismiss="alert">×</a>
<g:renderErrors bean="${skeletonBillInstance}" as="list" />
</div>
</g:hasErrors>
<g:uploadForm name="SkeletonBillForm" action="save" method="post">
<div class="dialog">
<table>
<tbody>
<tr class="prop">
<td valign="top" class="name"><label for="bones"><g:message
code="skeletonBill.bones.label" default="Bones" /></label></td>
<td valign="top"
class="value ${hasErrors(bean: skeletonBillInstance, field: 'bones', 'errors')}">
<g:textField name="bones"
value="${fieldValue(bean: skeletonBillInstance, field: 'bones')}" />
</td>
</tr>
<tr class="prop">
<td valign="top" class="name"><label for="dateOfBirth"><g:message
code="skeletonBill.dateOfBirth.label" default="Date Of Birth" /></label>
</td>
<td valign="top"
class="value ${hasErrors(bean: skeletonBillInstance, field: 'dateOfBirth', 'errors')}">
<g:textField name="dateOfBirth"
value="${skeletonBillInstance?.dateOfBirth}" /> <script>$(document).ready(function () {$("#dateOfBirth").kendoDatePicker({format:"yyyy-MM-dd"})});</script>
</td>
</tr>
<tr class="prop">
<td valign="top" class="name">
<label>File Upload</label>
<input name="excelSheet" id="excelSheet" type="file" />
<script>
$(document).ready(function() {
$("#excelSheet").kendoUpload();
},
function onError(e) {
// Array with information about the uploaded files
var files = e.files;
if (e.operation == "upload") {
alert("Failed to uploaded " + files.length + " files");
}
// Suppress the default error message
e.preventDefault();
},
function onUpload(e) {
var files = e.files;
if (e.operation == "upload") {
alert("Successfully uploaded " + files.length + " files");
}
});
</script>
</td>
</tr>
</tbody>
</table>
</div>
</g:uploadForm>
</div>
</body>
</html>
And Also Controller.gsp
def save = {
def skeletonBillInstance = new SkeletonBill(params)
if(!skeletonBillInstance.empty){
println "Name: ${skeletonBill.bones}"
flash.message = "${message(code: 'default.created.message', args: [message(code: 'skeletonBill.label', default: 'SkeletonBill'), skeletonBillInstance.id])}"
redirect(action: "show", id: skeletonBillInstance.id)
}
} else {
render(view: "create", model: [skeletonBillInstance: skeletonBillInstance])
}
}
Couple of things
1) If you want to use KendoUI, I wouldn't use the gsp tags. Please use the normal form tags to define your form, if you do this grails resorts to using the prototype plugin for.
2) I will not mix the script code with the tags.
3) If you are using grails 2.0, you can use the KendoUI plugin, you can find more information at http://grails.org/plugin/kendo-ui
Hope that helps.