how can i set and display another filed in local database? - java

i am trying the example todo app,i download that example in ionic and i tried that it is working, and i trued to add another filed inside newTask.html and add in local database as same as previous value,but it is not working can you please help me how can i add another filed in the local database and get results in list html file....
NewTask.html
------------
<div class="modal" ng-controller="newTaskCtrl">
<ion-header-bar class="bar-stable">
<h1 class="title">Add New Task</h1>
<button class="button button-clear button-positive" ng-click="closeNewTask()">Cancel</button>
</ion-header-bar>
<ion-content>
<form ng-submit="createTask(task)">
<div class="list">
<!--label class="item item-input">
<input type="text" placeholder="Title What do you need to do?" ng-model="task.title">
</label-->
<label class="item item-input item-stacked-label">
<span class="input-label">Title</span>
<input type="text" placeholder="What do you need to do?" ng-model="task.title">
<span class="input-label">Lasr Name</span>
<input type="text" placeholder="Firstname?" ng-model="task.firstname">
</label>
<!--div class="row">
<label class="col">
<input type="" ng-model="time">
</label>
<label class="col">
<input type="text" placeholder="End?" >
</label>
</div-->
</div>
<div class="padding">
<button type="submit" class="button button-block button-positive">Create Task</button>
</div>
</form>
</ion-content>
</div>
NewTaskCtrl.js
-------------------
todoApp.controller('newTaskCtrl', function($scope, $ionicModal, $ionicPopup, SQLService) {
// Called when the form is submitted
$scope.createTask = function(task) {
SQLService.set(task.title,task.firstname);
$scope.loadTask();
$scope.taskModal.hide();
task.title = "";
task.firstname = "";
};
SQLService.js
------------------
todoApp.factory("SQLService", function ($q) {
var db;
var task='';
var deltask;
function createDB() {
try {
db = window.openDatabase("todoDB", "1.0", "ToDoApp", 10*1024*1024);
db.transaction(function(tx){
tx.executeSql("CREATE TABLE IF NOT EXISTS tasks (id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, title VARCHAR(100), firstname VARCHAR(100) )",[]);
});
} catch (err) {
alert("Error processing SQL: " + err);
}
console.log('database created');
}
function setTasks(title,firstname){
return promisedQuery("INSERT INTO tasks(title,firstname) VALUES ('" + title + "','" + firstname + "')", defaultResultHandler, defaultErrorHandler);
}
function getTasks(){
return promisedQuery('SELECT * FROM tasks', defaultResultHandler, defaultErrorHandler);
}
function defaultResultHandler(deferred) {
return function(tx, results) {
var len = results.rows.length;
var output_results = [];
for (var i=0; i<len; i++){
var t = {'id':results.rows.item(i).id,'title':results.rows.item(i).title,'firstname':results.rows.item(i).firstname};
output_results.push(t);
}
deferred.resolve(output_results);
}
}
function defaultErrorHandler(deferred) {
return function(tx, results) {
var len = 0;
var output_results = '';
deferred.resolve(output_results);
}
}
function promisedQuery(query, successCB, errorCB) {
var deferred = $q.defer();
db.transaction(function(tx){
tx.executeSql(query, [], successCB(deferred), errorCB(deferred));
}, errorCB);
return deferred.promise;
}
return {
setup: function() {
return createDB();
},
set: function(title,firstname) {
return setTasks(title,firstname);
},
all: function() {
return getTasks();
}
}
});
PLease see the SQL Service and help me,is it correct what i add the filed name in "setTasks function.."

Ok, so you had tried the example that you had downloaded, now you have added another field in NewTask.html. But the new field that you added is not getting added to the table right??
Did you try to change the version of the DB opened??
db = window.openDatabase("todoDB", "1.0", "ToDoApp", 10*1024*1024);
to
db = window.openDatabase("todoDB", "2.0", "ToDoApp", 10*1024*1024);

Related

Upload file excel and read with JAX-RS 2.0 in java

I have upload file excel function that run normally in Websphere server 8.5 with JAX-RS 1.1. But when I update to Websphere 9.0 using JAX_RS 2.0, I cannot use #FormParam to upload file, I tried using #MultiPart to replace but it can read .csv file right only, with .xls and .xlsx file it create wrong temp file, so HSSFWorkbook of Apache Poi cannot read inputstream of file normally.
This is my code:
Controller:
#POST
#Path("class/import")
#Consumes(MediaType.MULTIPART_FORM_DATA)
#Produces(MediaType.APPLICATION_JSON)
#RolesAllowed(Role.TRAINING_ADMIN)
public Response importClass(#FormParam("file") File file) {
InputStream is = new FileInputStream(file);
HSSFWorkbook workbook = new HSSFWorkbook(is);
if (checkTokenAndRole(new int[] {1, 11}).getStatus() != Response.Status.OK.getStatusCode()) {
return LoginError(checkToken().getStatus());
} else {
String token = request.getHeader(HttpHeaders.AUTHORIZATION);
String fileExtension = request.getHeader("FileExtension");
return ClassService.getInstance().importClass(file, fileExtension,
token);
}
}
HTML and Js file:
<form data-bind="submit: cancel">
<div class="modal-dialog dialog-class">
<div class="modal-content dialog-class">
<div class="modal-header layout-dialog-header">
<div class="layout-float-left dialog-close-icon">
<span class="glyphicon doc-icon-close-nav" data-bind="click: cancel"></span>
</div>
<div>
<h5 data-bind="text: title" data-i18n="modules.class.uploadSchedule"></h5>
</div>
</div>
<div class=" docs-margin-top-s">
<div>
<div class="form-group marginBot35">
<div class="class-browse">
<div class="col-md-12">
<div>
<label class="label-md search-class-header" for="">
<span class="search-class-header" data-i18n="modules.class.uploadClasslist" data-bind="text: listClass"></span>
</label>
</div>
<div id="" class="col-md-8 control-upload no-padding-left">
<input readonly="true" tabindex="3" class="col-md-12" id='uploadFile' type="text" name="" style="min-height: 40px" data-bind="value: name, attr: {'title': name()}"/>
</div>
<div clas="col-md-4">
<label for="input-file-upload" tabindex="3" class="pull-right btn btn-secondary-aia btn-cancel font-size20" data-dismiss="modal"
data-i18n="buttons.buttonBrowse" >Browse
</label>
</div>
</div>
<div class="class-center-align">
<label class="label-md search-class-header " for="">
<span class="search-class-header" data-i18n="modules.class.downloadThe">Download the</span>
<!-- <a class="class-highlight" tabindex="3" data-i18n="modules.class.trainingSchedule" data-bind="attr: {href: template}, text: textTemplate" download>Training Schedule Template</a> -->
<a class="class-highlight" tabindex="3" data-i18n="modules.class.trainingSchedule" data-bind="click: $root.download, text: textTemplate" >Training Schedule Template</a>
</label>
</div>
</div>
</div>
</div>
</div>
<div class="col-md-12 footer-class" style="padding-bottom:40px">
<button tabindex="3" type="button" class="btn btn-secondary-aia btn-cancel font-size20" data-dismiss="modal" data-i18n="buttons.buttonCancel" data-bind="click: cancel"></button>
<button tabindex="3" type="submit" class="btn btn-primary-aia btn-save font-size20 " style=" cursor: pointer; word-spacing: normal !important" data-bind="click: upload, disable: !readyUpload(),text: buttonUpload" data-dismiss="modal" data-i18n="buttons.buttonUploadSchedule"></button>
</div>
</div>
</div>
</form>
<form id="form-input-file-upload" action="" method="post" enctype="multipart/form-data" style="display:none">
<input id="input-file-upload" type="file" style="" name="file" size="45" accept=".xls,.xlsx" style="display:none" data-bind="attr: {accept: acceptedFiles},event: {change: addFile}" >
</form>
define([
'durandal/app',
'durandal/events',
'plugins/dialog',
'plugins/http',
'knockout',
'jquery',
'config',
'services/utils',
'i18next',
'services/document'
], function (app, Events, dialog, http, ko, $, Config, Utils, i18next, DocumentService) {
'use strict';
return function UploadBulkSchedule(mode) {
var self = this;
Events.includeIn(self);
if(mode === 1){
self.title = ko.observable( i18next.t("modules.bulkAttendee.title") ? i18next.t("modules.bulkAttendee.title") : "");
self.listClass = ko.observable( i18next.t("modules.bulkAttendee.listClass") ? i18next.t("modules.bulkAttendee.listClass") : "");
self.textTemplate = ko.observable( i18next.t("modules.bulkAttendee.template") ? i18next.t("modules.bulkAttendee.template") : "");
self.buttonUpload = ko.observable( i18next.t("modules.bulkAttendee.buttonUpload") ? i18next.t("modules.bulkAttendee.buttonUpload") : "");
}else{
self.title = ko.observable( i18next.t("modules.class.uploadSchedule") ? i18next.t("modules.class.uploadSchedule") : "");
self.listClass = ko.observable( i18next.t("modules.class.uploadClasslist") ? i18next.t("modules.class.uploadClasslist") : "");
self.textTemplate = ko.observable( i18next.t("modules.class.trainingSchedule") ? i18next.t("modules.class.trainingSchedule") : "");
self.buttonUpload = ko.observable( i18next.t("buttons.buttonUploadSchedule") ? i18next.t("buttons.buttonUploadSchedule") : "");
}
self.name = ko.observable();
var acceptedFileArr = [
'application/vnd.ms-excel',
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
'application/csv',
'.xls','.xlsx', '.csv'];
var acceptedExtension = ['xls', 'xlsx', 'csv'];
self.mode = mode;
self.acceptedFiles = ko.observable(acceptedFileArr.join(','));
self.readyUpload = ko.computed(function(){
return self.name() ? true : false;
});
var maxSize = 5242880;
self.template = (self.mode === 1) ? Config.getBackendBaseUrl('/temp/excel/AttendanceImportTemplate/AttendeeListTemplate.xls') :Config.getBackendBaseUrl('/temp/excel/ClassImportTemplate/ClassImportTemplate.zip');
self.templateCSV = Config.getBackendBaseUrl('/temp/excel/ClassImportTemplate/ClassImportTemplate.csv');
var filesArray = [];
self.cancel = function(){
dialog.close(self);
};
self.active = function(){
};
self.upload = function(data, e){
e.preventDefault();
app.showLoading();
var inputTag = $('#form-input-file-upload :input')[0];
var fileName = $(inputTag).val().replace(/^.*[\\\/]/, '');
var extension = fileName.split('.').pop();
var headers = {
FileExtension: extension,
FileName: encodeURIComponent(fileName),
'Authorization': app.user().get('token'),
'isCourseImage': 0
};
if (self.mode === 1) {
self.trigger('uploadSuccess', [ $('#form-input-file-upload :input')[0] ]);
} else {
Utils
.uploadFile(
'class/import',
new FormData(
$('#form-input-file-upload')[0]),
headers)
.then(
function() {
app.hideLoading();
},
function(response) {
var title = i18next
.t('modules.class.errorTitle');
var options = [{
text : i18next
.t('buttons.buttonOk'),
value: Config.Events.DialogMessage.OK
}];
if(response.status === 200){
app.hideLoading();
} else if(response.status === 500){
var errorMessage = Utils
.getErrorMessage(response);
var errorCode = '';
var developerMessage = '';
try{
errorCode = JSON
.parse(response.responseText).errorCode;
developerMessage = JSON
.parse(response.responseText).message;
} catch(e){
}
if (errorCode === 1007
&& developerMessage) {
var messageContent = '<br></br><b>'
+ i18next
.t(
'message.error.importClassSuccess')
.format(
developerMessage)
+ '</b><br></br>';
title = i18next
.t('message.error.importSuccess');
app
.showMessageConfirmTitle(
messageContent,
title,
options,
false,
{
class : 'success-class'
})
.then(
function() {
self
.trigger('uploadSuccess');
dialog
.close(self);
});
} else if(errorMessage){
app.showMessageError(
errorMessage,
title, options,
false, null);
}
} else if(response.status === 0) {
var errorMessage = i18next
.t('message.error.notSaveClassList');
app.showMessageError(
errorMessage, title,
options, false, null);
}
app.hideLoading();
});
}
};
self.browse = function(){
filesArray = [];
document.getElementById("uploadFile").click();
};
self.addFile = function(data, event){
var inputFile = document.getElementById("input-file-upload");
var path = inputFile.value.toString();
var uploadFile = event.currentTarget;
var file = uploadFile.files[0];
var fsize = file.size;
var name, extension;
name = path.replace(/^.*[\\\/]/, '');
extension = name.split('.').pop();
if( fsize > maxSize){
self.name('');
$('#input-file-upload').replaceWith($('#input-file-upload').clone(true));
showUploadMessageWithData(file);
$('#input-file-upload')[0].value = '';
} else if(acceptedExtension.indexOf(extension.toLowerCase()) < 0){
self.name('');
$('#input-file-upload').replaceWith($('#input-file-upload').clone(true));
var messageContent = '<br/><b>'+i18next.t('modules.class.wrongFileExtension')+' </b><br/>';
var options = [{
text: i18next.t('buttons.buttonClose'),
value: Config.Constants.MessageBox.DialogResult.BUTTON_INDEX_0
}];
var title = i18next.t('modules.class.errorTitle');
app.showMessageError(messageContent, title, options, false, null);
$('#input-file-upload')[0].value = '';
} else {
self.name(name);
}
};
function showUploadMessageWithData (file) {
var messageContent = '<p style="white-space: pre-wrap">'+i18next.t('modules.course.editPage.fileName')+': ' + file.name + '</p>';
messageContent += '</br><p><b>'+i18next.t('modules.course.editPage.warnUploadFile')+' </b></p>'; messageContent += '<p><b>'+i18next.t('modules.course.editPage.requireUploadFile')+ ' </b></p>';
var options = [{
text: i18next.t('buttons.buttonOk'),
value: Config.Constants.MessageBox.DialogResult.BUTTON_INDEX_0
}];
var title = i18next.t('modules.class.errorTitle');
return app.showMessageError(messageContent, title, options, false, {class: 'confirm-class'}).then(function () {
});
}
//download Material
self.download = function(fileDownload){
app.showLoading();
DocumentService.downloadTemplate(fileDownload.template).then(function (response) {
app.hideLoading();
var extension = fileDownload.template.split('.').pop();
var ctType = '';
switch(extension) {
case 'jpg':
case 'jpeg':
ctType = 'image/jpeg';
break;
case 'png':
ctType = 'image/png';
break;
case 'doc':
ctType = 'application/msword';
break;
case 'docx':
ctType = 'application/vnd.openxmlformats-officedocument.wordprocessingml.document';
break;
case 'xls':
ctType = 'application/vnd.ms-excel';
break;
case 'xlsx':
ctType = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet';
break;
case 'ppt':
ctType = 'application/vnd.ms-powerpoint';
break;
case 'pptx':
ctType = 'application/vnd.openxmlformats-officedocument.presentationml.presentation';
break;
case 'pdf':
ctType = 'application/pdf';
break;
default:
break;
}
var byteArray = new Uint8Array(response.data);
var a = window.document.createElement('a');
a.setAttribute("id", "tmpHref");
a.href = window.URL.createObjectURL(new Blob([byteArray], { type: ctType }));
a.download = fileDownload.template.split("/")[fileDownload.template.split("/").length - 1];
// Append anchor to body.
document.body.appendChild(a);
a.click();
// Remove anchor from body
document.body.removeChild(a);
}, function (response) {
app.hideLoading();
Utils.downloadMaterial(response);
});
};
};
});
Anyone can help me give a solution?
Thanks.
I had the solution. I change use IMultipartBody instead using #FormParam,changing ImultipartBody to byte array and use it instead a file.

Onclick function button inside a javascript

I want to direct the button to another page
function showInput() {
document.getElementById("demo").innerHTML = '<input type="submit"
onclick="location.href = "addnewcustomer.php";" id ="newcust"
class="btnRegister" value = "New Customer">';
}
I want when i click the New Customer button, it will redirect to addnewcustomer.php but when i run the code, nothing happened.
There are no errors. Just the button didn't function the way i want it to
You have to escape quotes in element. Try following code
function showInput() {
document.getElementById("demo").innerHTML = '<input type="submit" onclick="location.href = \'addnewcustomer.php\';" id ="newcust" class="btnRegister" value = "New Customer">';
}
<a onclick="showInput()" >Add New Buton</a>
<div id="demo"></div>
You can use following code to redirect page.
function showInput() {
document.getElementById("demo").innerHTML = '<input type="submit" id ="newcust" class="btnRegister" value = "New Customer" />';
}
document.getElementById("newcust").onclick = function () {
location.href = "addnewcustomer.php";
}
<div id="demo"></div>
<a onclick="showInput()" >Click To Get Button</a>
Try this
function showInput() {
document.getElementById("demo").innerHTML = '<input type="submit" onclick="location.href = \'https://www.youtube.com/\';" class="btnRegister" value = "New Customer">';
}
showInput()
<p id="demo">click</p>
It is because you didn’t close your input tag
Try this...
function showInput() {
document.getElementById("demo").innerHTML = '<input type="submit"
onclick="location.href = "addnewcustomer.php";" id ="newcust"
class="btnRegister" value = "New Customer"/>';
}
If you don’t close it the button will not work.
function showInput() {
document.getElementById("demo").innerHTML = '<input type="submit" onclick="location.href = "yourpage.php";" id ="newcust" class="btnRegister" value = "New Customer">';
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<a onclick="showInput()" >Click To Get Button</a>
<p id="demo"></p>
Right Click And inspect Button.
Try the code below, the inner html text is missing with escape string. Call window.onload to trigger your method and display your button. HTH.
<head>
<script type="text/javascript">
function showInput() {
document.getElementById("demo").innerHTML = '<input type="submit" onclick="location.href = \'addnewcustomer.php\';" id ="newcust" class="btnRegister" value = "New Customer">';
}
window.onload = showInput;
</script>
</head>
<body>
<p id="demo"></p>
</body>

How to post nested json using angular js in form

How to POST Item Object using angularjs?
My simple java class:
#Entity
public class ProductionOrder implements Serializable {
#Enumerated(EnumType.STRING)
public Status status;
#Id
#GeneratedValue
private Long id;
#ManyToOne
#JoinColumn(name = "ITEM_ID")
private Item item;
private int plannedQty;
private Date plannedDate;
private String description;
//getters setters enum
My angular controller:
'use strict';
App.controller('PoController', ['$scope', 'PoService', function($scope, PoService) {
var vm = this;
vm.order = {id: null, status: null, item:null , plannedQty: null, plannedDate: '', description:''};
vm.orders = [];
vm.fetchAllOrders = function () {
PoService.fetchAllOrders()
.then(
function (d) {
vm.orders = d;
},
function (errResp) {
console.error('Error while fetching production orders!');
}
);
};
vm.createOrder = function (item) {
PoService.createOrder(item)
.then(
vm.fetchAllOrders,
function (errResponse) {
console.error('Error while creating production order');
}
);
};
vm.fetchAllOrders();
vm.submit = function () {
if (vm.order.id === null) {
console.log('Saving new order', vm.order);
vm.createOrder(vm.order);
} else {
console.log('Sth wrong with adding new order');
}
vm.reset();
};
vm.reset = function () {
vm.order = {id: null, status:null, item: null, plannedQty: null, plannedDate: '', description:''};
$scope.myForm.$setPristine();
};
}]);
And this is my angular service:
'use strict';
App.factory('PoService', ['$http', '$q', function ($http, $q) {
return {
fetchAllOrders: function () {
return $http.get('http://localhost:8080/api/po/all')
.then(
function (response) {
return response.data;
},
function (errResponse) {
console.error('Error while fetching production orders');
return $q.reject(errResponse);
}
);
},
createOrder: function (item) {
return $http.post('http://localhost:8080/api/po/add', item)
.then(
function (res) {
return res.data;
},
function (errRes) {
console.error('Error while adding production order');
return $q.reject(errRes);
}
);
}
};
}]);
In html I have simple form:
<div class="ui main text container", ng-controller="PoController as ctrl">
<form class="ui form" ng-submit="ctrl.submit()" name="myForm">
<h4 class="ui dividing header">Production order information</h4>
<div class="field">
<label> </label>
<div class="two fields">
<div class="field">
<input type="text" ng-model="ctrl.order.id" placeholder="Production order id">
</div>
<div class="field">
<input type="text" ng-model="ctrl.order.item" placeholder="Item id">
</div>
</div>
</div>
<h4 class="ui dividing header">Status:</h4>
<select class="ui dropdown" ng-model="ctrl.order.status">
<option value="CREATED">CREATED</option>
<option value="PLANNED">PLANNED</option>
<option value="DONE">DONE</option>
</select>
<h4 class="ui dividing header">Planning information</h4>
<div class="field">
<label> </label>
<div class="two fields">
<div class="field">
<input type="text" ng-model="ctrl.order.plannedQty" placeholder="Quantity">
</div>
<div class="field">
<input type="text" ng-model="ctrl.order.plannedDate" placeholder="Enter date RRRR-MM-DD">
</div>
</div>
</div>
</br>
<div class="field">
<label>Description</label>
<textarea ng-model="ctrl.order.descritpion"></textarea>
</div>
<div class="asbutton" id="button">
<input type="submit" value="Save" class="ui primary button" ng-disabled="myForm.$invalid">
<button class="ui button" type="button" ng-click="ctrl.reset()" ng-disabled="myForm.$pristine">
Reset
</button>
</div>
</form>
</div>
And when i type for example: 1. It means I want to create realtion with item with 1 id. In Terminal I see error:
2016-06-12 16:06:13.906 WARN 10057 --- [nio-8080-exec-3] .w.s.m.s.DefaultHandlerExceptionResolver : Failed to read HTTP message: org.springframework.http.converter.HttpMessageNotReadableException: Could not read document: Can not instantiate value of type [simple type, class com.prod.domain.Item] from String value ('2'); no single-String constructor/factory method
at [Source: java.io.PushbackInputStream#2b8fb852; line: 1, column: 25] (through reference chain: com.prod.domain.ProductionOrder["item"]); nested exception is com.fasterxml.jackson.databind.JsonMappingException: Can not instantiate value of type [simple type, class com.prod.domain.Item] from String value ('2'); no single-String constructor/factory method
at [Source: java.io.PushbackInputStream#2b8fb852; line: 1, column: 25] (through reference chain: com.prod.domain.ProductionOrder["item"])
How could I POST nested json similar to this:
item: {id: 6}

POST not supported exception while invoking REST api via SpringBoot

I have a REST API defined in a SpringBoot application and I'm trying to access this via POST using a different application deployed on a Tomcat 8 server. Upon doing a POST from the other application, I get the following error in the SpringBoot logs:
Request method 'POST' not supported.
Here is my Rest Controller class:
#Controller
public class RestApiController {
#RequestMapping(value="/cancel", method=RequestMethod.GET)
public #ResponseBody String CancelJobEndPointInfo() {
return "A job can be cancelled by POSTing to this URL";
}
#RequestMapping(value="/cancel", method=RequestMethod.POST)
public #ResponseBody DataPost CancelJobEndPoint(#RequestParam("username") String name,
#RequestParam(name = "passPhrase", defaultValue = "null") String passPhrase,
#RequestParam("jobnumber") String jobNumber, #RequestParam("file") MultipartFile file){
UserDetails userObject = new UserDetails();
CancelJob job = new CancelJob();
DataPost dpc = new DataPost();
if (!file.isEmpty()) {
try {
/*
* Write private key
*/
byte[] ppkBytes = file.getBytes();
BufferedOutputStream ppkStream =
new BufferedOutputStream(new FileOutputStream(new File(file.getOriginalFilename())));
ppkStream.write(ppkBytes);
ppkStream.close();
userObject.setKeyPath(file.getOriginalFilename());
userObject.setUserName(name);
userObject.setPassphrase(passPhrase);
job.getCancelJob(userObject, jobNumber);
dpc.setMessage("Job:" + jobNumber + " Cancelled successfully");
return dpc;
} catch (IOException e) {
dpc.setMessage("Could not cancel the job:" + jobNumber + " ERROR => " + e.getMessage());
return dpc;
// return "Could not cancel the job:" + jobNumber + " ERROR => " + e.getMessage();
} catch (JSchException e){
// return "Could not cancel the job:" + jobNumber + " ERROR => " + e.getMessage();
dpc.setMessage("Could not cancel the job:" + jobNumber + " ERROR => " + e.getMessage());
return dpc;
}
} else {
dpc.setMessage("Private Key file for user: " + name + " is empty");
return dpc;
// return "Private Key file for user: " + name + " is empty";
}
}
I could see that a GET request is going through successfully, but I'm not sure what is wrong with the PUT request.
Also, I am able to invoke the API via POST by using html files within the application that has the REST methods.
I am facing this issue while trying to invoke it from a different application.
Following is the form that I am using:
<form action="http://localhost:8080/cancel" enctype="multipart/form-data"
method="post" accept-charset="utf-8" id="jobCancelForm"
name="job">
<h4 class="section-heading">User Details:</h4>
<fieldset class="form-group">
<label for="UserID">User Name</label> <input type="username"
class="form-control" id="canceluser"
placeholder="Enter SSH User ID" name="username">
</fieldset>
<fieldset class="form-group">
<label for="passPhrase">PassPhrase :</label> <input
type="password" class="form-control" id="cancelpass"
placeholder="Private Key PassPhrase" name="passPhrase">
</fieldset>
<fieldset class="form-group">
<label for="PrivateKeyFileInput">Private Key File</label> <input
type="file" class="form-control-file"
id="cancelPrivateKeyFileInput" name="cFile"> <small
class="text-muted">Select the pre-configured private
key file to be used for SSH authentication.</small>
</fieldset>
<a role="separator" class="divider"></a>
<hr>
<h4 class="section-heading">Job Details:</h4>
<fieldset class="form-group">
<label for="jobID">Job ID :</label> <input type="number"
class="form-control" id="canceljobID"
placeholder="Enter the job ID Ex: 1242254" name="jobNumber">
</fieldset>
<button type="submit" class="btn btn-primary"
id="jobMonitorButton">Cancel Job</button>
</form>
<a role="separator" class="divider"></a>
<!-- response div -->
<div style="word-wrap: break-word;" id="cancelResponse"></div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default"
data-dismiss="modal" id="jobCancelFormCloseButton">Close</button>
</div>
</div>
Any pointers please?
It seems to me the same issue for what the solution is provided here
Add #RequestMapping("YOUR-CONTEXT-VALUE") on the controller's class and remove value from #RestController annotation.

How delete the particler column through the jquery

Hi here i am using jquery to delete the records in the table but once I delete the record that record is coming back while updating. But if I do cancel with out doing updating that record is not coming.But the record is delete fine in the database.Can anyone plz solve my problem by seeing my code where I went wrong plz assist me.
Jquery code
$('button[id*="delid"]').click(function() {
var cnfrm = confirm("Do you really want to delete this");
if (cnfrm == true) {
var a = "trid" + $(this).val();
var tcopies = $("#abc").val();
// alert(a);
// var slno = $('#' + a).find('td:first').text();
// alert("alert" + $(this).val());
$.ajax({type: 'POST', url: 'deletebar.do?id=' + $(this).val(), success: function(result) {
if (result == 'success') {
$('#' + a).remove();
$("#abc").val(--tcopies);
$("#jkl").val(tcopies);
// $('#cancel').attr('disabled', true);
// $('#vehicletab tr').each(function() {
// var i = $(this).find('td:first').text();
// if (i > slno) {
// --i;
// }
// $(this).find('td:first').html(i);
// })
alert("Deleted Successfully", "Success");
} else {
alert("This vehicle is assigned to Route, You can't Delete it", "Error");
}
}
});
}
else {
return false;
}
});
Jsp Code
<c:forEach var="lib" items="${list}">
<table>
<tr id="trid${lib.slno}">
<td>
<label class="control-label" for="typeahead">Bar Code No&nbsp:&nbsp&nbsp</label>
<input type="text" name="barcode" value="${lib.getbarcode}" readonly="true"/>
</td>
<td>
<label class="control-label" for="typeahead">Accession No&nbsp:&nbsp&nbsp</label>
<input type="text" name="accessno" value="${lib.acession}"/>
</td>
<td>
<button type="button" id="delid${lib.slno}" value="${lib.slno}">Delete</button>
</td>
</tr>
</table>
</c:forEach>
</c:forEach>

Categories