When customer makes a deposit, this inserts a request in the database. When this happens, I want send an alert or play an alarm on a separate jsp (admin page containing list of approvals). Any ideas?
In case anyone is interested, I solved this by creating a polling function that runs on the header that sits on all pages via tiles framework.
var alert = document.createElement('audio');
var count2 = $.cookie('list');
function poll(){
setTimeout(function(){
$.ajax({
url: url
,type: "GET"
,success: function(data){
var count1 = data.info;
if(count1>count2){
count2 = count1;
alert.play();
$.cookie("list",count2,{path:'/'});
$("#approvalCount").html($.cookie("list"));
}else if(count1<count2){
count2 = count1;
$.cookie("list",count2,{path:'/'});
}
}
,dataType: "json"
,complete: poll
,timeout: 2000
})
}, 30000);
};
Once its inserted write a script to display an alert:
out.println("<script><script>alert('Value Got inserted successfully')</script>");
OR you can do it like this aswell:
%><script>alert("Value Got inserted successfully")</script><%
Related
I'm trying to call a function that returns me a json object from a servlet through a link.
My HTML link, call fTest function:
<td>ver</td>
My controller:
app.controller('minaplantaCtrl', function($scope, $http, $window) {
$scope.fTest = function(idDescarga){
$http.get("http://localhost:8080/BD_INTEGRADA/UnionMinaPlanta?idDescarga="+idDescarga)
.success(function (response) {$scope.descargas = response.descargas;});
$window.alert(JSON.stringify($scope.descargas));
};
});
when I press for the first time the link appears "undefined" in the alert
but when I press a second time if I can see the json object that returns in the alert
What may be happening when I press first the link? please help
thanks
The problem here is your are alerting $scope.descargas outside of the success callback therefore it truly is not defined yet try modifying it like this.
app.controller('minaplantaCtrl', function($scope, $http, $window) {
$scope.fTest = function(idDescarga){
$http.get("http://localhost:8080/BD_INTEGRADA/UnionMinaPlanta?idDescarga="+idDescarga)
.success(function (response) {
$scope.descargas = response.descargas;
$window.alert(JSON.stringify($scope.descargas));
});
};
});
Since every server side request using $http in Angular is an AJAX i.e. an asynchronous call to server, you are assuming that your alert method will be called after the success response execution complete. But this is wrong.
This is where the concept of promises comes in Angular.
app.controller('minaplantaCtrl', function($scope, $http, $window) {
$scope.fTest = function(idDescarga) {
console.log("1");
$http.get("http://localhost:8080/BD_INTEGRADA/UnionMinaPlanta?idDescarga="+idDescarga)
.success(function (response) {
$scope.descargas = response.descargas;
console.log("2");
});
console.log("3");
$window.alert(JSON.stringify($scope.descargas));
};
});
So when you execute this code with a delay at server side, you will see the order of console log as: 1, 3 and 2.
So, your success function is executed when the response received from the server. So for the first time, the value in descargas variable is null but get's stored using first server response and next time, value from previous call is being displayed.
Actually I've been reading about this for a while but I couldn't understand it very well.
Here is a snippet of the Servlet "ProcessNurseApp" :
if (dbm.CheckExRegNumber(Candidate.getRegNumber()) == true) {
// Show him an alert and stop him from applying.
out.println("<script>\n"
+ " alert('You already Applied');\n"
+ "</script>");
out.println("<script>\n"
+ " window.history.go(-1);\n"
+ "</script>");
}
So when the form named "ApplicationForm" in the "Nurses.jsp" get submitted it goes to that method in servlet after some Javascript validation.
My issue is that I want to call that method
if (dbm.CheckExRegNumber(Candidate.getRegNumber()) == true)
in the JSP page without getting to servlet so I can update values without refreshing the page. I've been reading that using ajax with jQuery would be the best way to do that, so can anyone help me of calling the above if statement from jQuery by AJAX.
Try an ajax call to the servlet(not possible without calling servlet) to check whether the function returns true or false then return a flag according to the value(true or false). On that basis you can show an alert or anything else.
For ajax call, you can use:
$.post( "ajax/Servlet_Url", function( data ) { if(data==true) alert("You already Applied"); else window.history.go(-1);});
Refer to following Link for more details about jQuery post request.
https://api.jquery.com/jquery.post/
jQuery(document).ready(function($) {
$("#searchUserId").attr("placeholder", "Max 15 Chars");
$("#searchUserName").attr("placeholder", "Max 100 Chars");
$.ajax({
url:"../../jsp/user/userMaster.do",
data: { drpType : 'userType',lookType : "1" },
success: function (responseJson) {
var myvalue = document.getElementById("userTypeKey");
for(var val in responseJson)
{
valueType = val;
textOptions = responseJson[val];
var option = document.createElement("option");
option.setAttribute("value",valueType);
option.text = textOptions;
myvalue.add(option);
if(valueType == myvalue.value)
{
option.selected = "selected";
}
}
}
});
});
I have a dynamic form on submit I call the plugin like below
var method = "post"; // Set method to post by default if not specified.
var path = "downloadExcel.obj";
var formDownload = document.createElement("form");
formDownload.setAttribute("method", method);
formDownload.setAttribute("action", path);
formDownload.setAttribute("id", "fileDownloadForm");
var custhiddenField = document.createElement("input");
custhiddenField.setAttribute("type", "hidden");
custhiddenField.setAttribute("name", "customerId");
custhiddenField.setAttribute("value", customerId); // VALUE IS GETTING UPDATED HERE
formDownload.appendChild(custhiddenField);
...............................................................................
//On printing the form here on console I get the updated formDownload
...........................................................................
formDownload.submit =
$.fileDownload($('#fileDownloadForm').prop('action'), {
httpMethod: "POST",
data: $('#fileDownloadForm').serialize(),
preparingMessageHtml: "We are preparing your report, please wait...",
failMessageHtml: "There was a problem generating your report, please try again."
});
Now I am able to download the file first time successfully but when I try to download second time [without refreshing the page], my variable formDownload is having the updated data but when I debug inside jquery.fileDownload [settings.data] still have the old data. Henceforth downloading the file for previous customer again and again
In the code where you say:
//re-intialize variables
var custInfoArray = ($('#customerId').val()).split("-");
var customerId = custInfoArray[0];
var regionInfoArray = ($('#regionId').val()).split("-");
.....
You don't reinitialize them. if you have them defined somewhere else, you define new variables in the function scope. Try removing var in front of customerid and other variables used in POST.
Try the following instead:
//re-intialize variables
custInfoArray = ($('#customerId').val()).split("-");
customerId = custInfoArray[0];
regionInfoArray = ($('#regionId').val()).split("-");
.....
It was a stupid mistake, correct code should be:
$.fileDownload($('#fileDownloadForm').prop('action'), {
httpMethod: "POST",
data: $(formDownload).serialize(), //this is changed
preparingMessageHtml: "We are preparing your report, please wait...",
failMessageHtml: "There was a problem generating your report, please try again."
});
I'm developing a web application that uses SOAP to communicate with JIRA. I have a custom field that contains several checkboxes, and I can get this field through SOAP, but I can't get to the actual checkboxes it contains. Is there a way to do this?
Since nobody has answered this so far, here is an old copy of some JavaScript I did for JIRA, reading customfields.
var unitlist_val = $("#unitList_0").val();
var errorlist_val = $("#errorList_0").val();
var larmlist_val = $("#larmList_0").val();
var URL= ""+jira+"/sr/jira.issueviews:searchrequest-xml/temp/SearchRequest.xml jqlQuery=project+%3D+"+problem+
"+AND+%22Symptom+1+-+Component%22+~+%22+"+unitlist_val+"%22+AND+%22Symptom+2+-+State%22+~+%22"+errorlist_val+
"%22+AND+%22Symptom+3+-+alarm%22+~+%22"+larmlist_val+
"%22&tempMax=1000&field=title&field=link&field=customfield_10422&field=customfield_10423&field=customfield_10424&field=customfield_10420&field=resolution&field=customfield_10440";
$.ajax({
type: "GET",
url: URL,
dataType: "xml",
cache: false,
beforeSend: function(request) {
request.setRequestHeader("Accept", "text/xml; charset=utf-8");
},
success: function(data){
$(data).find("item").each(function(){
// Make sure swedish chars, are handled properly. Append to page first, then get value.
var unitList = $("<div/>").html($(this).find("#customfield_10422 customfieldvalue").text()).text().split(",");
var errorList = $("<div/>").html($(this).find("#customfield_10423 customfieldvalue").text()).text().split(",");
var alarmList = $("<div/>").html($(this).find("#customfield_10424 customfieldvalue").text()).text().split(",");
var knownerror = $("<div/>").html($(this).find("#customfield_10420 customfieldvalue").text()).text() || "None";
var resolution = $("<div/>").html($(this).find("resolution").text()).text() || "None";
}
});
You can probably do something similar in Java and use a simple GET request. I cut out quite a lot of code, so some parts might be syntax error on.
I have a spring controller with a request mapping as follows
#RequestMapping("/downloadSelected")
public void downloadSelected(#RequestParam String[] ids) {
// retrieve the file and write it to the http response outputstream
}
I have an html table of objects which for every row has a checkbox with the id of the object as the value. When they submit, I have a jQuery callback to serialize all ids. I want to stick those ids into an http request parameter called, "ids" so that I can grab them easily.
I figured I could do the following
var ids = $("#downloadall").serializeArray();
Then I would need to take each of the ids and add them to a request param called ids. But is there a "standard" way to do this? Like using jQuery?
I don't know about "standard way", but this is how I would do it.
var ids = $("#downloadall").serializeArray();
will give you a dataset on the form (only the checked items presented):
[{name:"foo1", value:"bar1"}, {name:"foo2", value:"bar2"}]
To feed this to jQuery's .ajax() just:
$.ajax({
url: <your url>,
data: ids.map(function (i) {return i.name+'='+i.value;}).join('&')
});
The Array.map() is not compatible with all browsers yet so you better have this code on your page too:
if (!Array.prototype.map) {
Array.prototype.map = function(fun /*, thisp*/) {
var len = this.length >>> 0;
if (typeof fun != "function")
throw new TypeError();
var res = new Array(len);
var thisp = arguments[1];
for (var i = 0; i < len; i++) {
if (i in this)
res[i] = fun.call(thisp, this[i], i, this);
}
return res;
};
}
This code snippet I got from mozilla developer center.
I didn't put them in a ?ids=... param, but this way they are easy to access on server side. You can always just modify the map function to fit your needs.