Per help me getting a single XSP.partialRefreshGet to work. That is working fine for me noe. Thank you. Now I need to get multiple refreshes to work:
XSP.partialRefreshGet("#{txtRateType}", {
onComplete: function() {
XSP.partialRefreshGet("#{CurrentBalancesSection}", {
onComplete: function() {
XSP.partialRefreshGet("#{PricingSection}}", {});
}
});
}
});
I get a run time error. Any idea what I am doing wrong?
You are missing the id part again (and you had an extra curly brace), Bruce :-)
XSP.partialRefreshGet("#{id:txtRateType}", {
onComplete: function() {
XSP.partialRefreshGet("#{id:CurrentBalancesSection}", {
onComplete: function() {
XSP.partialRefreshGet("#{id:PricingSection}", {});
}
});
}
});
This is client side JS and the functions need client side ids. You use {id: to tell XPages to return the client side id of a server side component.
Related
First of all, this is one of my first projects in Node.js so I'm very new to it.
I have a project I want to make that is a SOAP (I know, SOAP... backwards compatibility, huh?) interface that connects to an Oracle database.
So I have a WSDL describing what these functions look like (validation for addresses and stuff) and I have a connection to the database.
Now when using the SOAP npm module, you need to create a server and listen using a service that allows you to respond to requests. I have a separate file that contains my SOAP service but this service should do queries on the database to get its results.
How would I go about sort of 'injecting' my database service into my SOAP service so that whenever a SOAP call is done, it orchestrates this to the correct method in my database service?
This is what my code looks like:
databaseconnection.js
var oracledb = require('oracledb');
var dbConfig = require('../../config/development');
var setup = exports.setup = (callback) => {
oracledb.createPool (
{
user : dbConfig.user,
password : dbConfig.password,
connectString : dbConfig.connectString
},
function(err, pool)
{
if (err) { console.error(err.message); return; }
pool.getConnection (
function(err, connection)
{
if (err) {
console.error(err.message);
return callback(null);
}
return callback(connection);
}
);
}
);
};
databaseservice.js
var DatabaseService = function (connection) {
this.database = connection;
};
function doSomething(callback) {
if (!this.database) { console.log('Database not available.'); return; }
this.database.execute('SELECT * FROM HELP', function(err, result) {
callback(result);
});
};
module.exports = {
DatabaseService: DatabaseService,
doSomething: doSomething
};
soapservice.js
var myService = {
CVService: {
CVServicePort: {
countryvalidation: function (args, cb, soapHeader) {
console.log('Validating Country');
cb({
name: args
});
}
}
}
};
server.js
app.use(bodyParser.raw({type: function(){return true;}, limit: '5mb'}));
app.listen(8001, function(){
databaseconnection.setup((callback) => {
var temp = databaseservice.DatabaseService(callback);
soapservice.Init(temp);
var server = soap.listen(app, '/soapapi/*', soapservice.myService, xml);
databaseservice.doSomething((result) => {
console.log(result.rows.length, ' results.');
});
});
console.log('Server started');
});
How would I go about adding the databaseservice.doSomething() to the countryvalidation soap method instead of 'name: args'?
Also: I feel like the structure of my code is very, very messy. I tried finding some good examples on how to structure the code online but as for services and database connections + combining them, I didn't find much. Any comments on this structure are very welcome. I'm here to learn, after all.
Thank you
Dieter
The first thing I see that looks a little off is the databaseconnection.js. It should be creating the pool, but that's it. Generally speaking, a connection should be obtained from the pool when a request comes in and release when you're done using it to service that request.
Have a look at this post: https://jsao.io/2015/02/real-time-data-with-node-js-socket-io-and-oracle-database/ There are some sample apps you could have a look at that might help. Between the two demos, the "employees-cqn-demo" app is better organized.
Keep in mind that the post is a little dated now, we've made enhancements to the driver that make it easier to use now. It's on my list to do a post on how to build a RESTful API with Node.js and Oracle Database but I haven't had a chance to do it yet.
I've picked up Node.js recently. Before I jump to Express.js and other web frameworks, I learned few things about them but I wanted to try some API programming. I downloaded this module: https://www.npmjs.com/package/steamwebapi
Since I'm new to Node.js, I made new javascript file, app.js and my code is:
var SteamWebAPI = require('steamwebapi').SteamWebAPI;
SteamWebAPI.setAPIKey('My key is here');
SteamWebAPI.getRecentlyPlayedGames('76561198190043289', 5, function(response) {
console.log(response);
});
SteamWebAPI.getRecentlyPlayedGames('76561198190043289', 5, function(response) {
console.log(response);
});
'76561198190043289' is my steam 64 id. When I type: node app.js in terminal, I get:
{ response: { total_count: 1, games: [ [Object] ] } }
{ response: { total_count: 1, games: [ [Object] ] } }
How do I display my results, what I'm doing wrong?
You are not doing anything wrong. console.log makes the output more compact for the sake of readability. It can get very lengthy at times so it's probably a good thing.
It means that "[ [Object] ]" is actually an array of one or more games. You can try using
console.dir( response );
instead, or you can be more specific with log:
console.log( response.response.games );.
There are other ways around this as well if you can bother to search around. Converting to a string seems to be popular:
console.log( JSON.stringify( response, null, 4) );
Off topic...
I would also like to mention something else (since you are new) the one thing everyone must relearn coming to node from js. Calling functions like you do:
function1(..., callback);
function2(..., callback);
Node moves on to the second function immediately without waiting for the first callback to finish. So you have no idea of which of those functions will finish first. To force the order you would have to do this:
SteamWebAPI.getRecentlyPlayedGames('76561198190043289', 5, function(response) {
console.log(response);
SteamWebAPI.getRecentlyPlayedGames('76561198190043289', 5, function(response) {
console.log(response);
});
});
Your code will turn into the infamous callback hell. There is no avoiding it. It will happen sooner or later! To prevent that, learn how to use promises. You'll be much better off going from there!
Edit: Connect to angular
You need to create a server-backend of some kind. This is how it could look like using express (since you mention express):
var express = require('express');
var server = express();
var SteamWebAPI = require('steamwebapi').SteamWebAPI;
SteamWebAPI.setAPIKey('My key is here');
// define endpoints
server.get('/games', function (req, res) {
SteamWebAPI.getRecentlyPlayedGames('76561198190043289', 5, function(response) {
res.json(response.response.games);
});
});
// Start the server
server.listen(3000, function () {
console.log('Example app listening on port 3000!');
});
Once it's running you can test that it works by browsing to http://example.com:3000/games
Then you call your endpoint from angular:
var app = angular.module("app", []);
app.controller("myCtrl", function($scope, $http){
$scope.games = [];
$http.get('http://example.com:3000/games').then(function(response){
// The response is seldom exactly what you expect. Check your browser console.
console.log(response);
$scope.games = response.data;
});
});
html
<body ng-app="app" ng-controller="myCtrl">
<div ng-repeat="game in games">{{ game }}</div>
</body>
All done.
Mind you, this is all shooting from the hip (no testing whatsoever) , so there are bound to be errors. But it should give you a starting point at least.
I have my Todo list set up. I can persist to parse.com with Backbone if I press "Add" button to add a new todo. Only problem is that if i refresh the page, all the todos i just added is gone. Which is correct, because I'm not actually using a backend right now.
When integrating with Node/express, how do I do a post request to parse.com and get back the todos I currently have?
I read in a tutorial to do something like this:
var Todos = Backbone.Collection.extend({
url: 'http://localhost:3000/api/todos'
});
and something like this:
var TodosView = Backbone.View.extend({
model: todos,
el: $('.todos-list'),
initialize: function() {
this.model.on('add', this.render, this);
this.model.on('remove', this.render, this);
//this thing-----------
this.model.fetch({
success: function(response){
_.each(response.toJSON(), function(item) {
console.log('Successfully GOT todo with _id: '+ item._id);
});
},
error: function() {
console.log('Failed to get blogs!');
}
})
},
//this thing end-----------
render: function() {
var self = this;
this.$el.html('');
_.each(this.model.toArray(), function(todo) {
self.$el.append((new TodoView({model: todo})).render().$el);
});
return this;
}
});
this.model.fetch is trying to fetch from the url: from up there, but that tutorial was using MongoDB. How do I use parse.com to do the same thing??
It would be awesome if you explained your answers, because I just tried to learn backbone/node/express/parse yesterday.
var Messages = Backbone.Collection.extend({
model:Message,
url:'https://api.parse.com/1/something/something',
getMessages:function() {
this.fetch({
data:{
order:'-createdAt'
}
});
},
parse:function(response, options) {
return response.results.reverse();
}
});
In your example you are fetching and posting to your own computer http://localhost:3000/api/todos which I'm guessing you learned from your tutorial. Setup and account with parse.com and checkout out the docks. You will change the url to match their API. Checkout out their REST api documentation for specifics https://www.parse.com/docs/rest/guide.
I'm trying to write tests for my npm module, which takes care of communicating with my backend api. this module will sit inside a cordova android app, and will take care of any api calls. the issue that i'm having seems to be an understanding of mocha, but i've had a good look around the internet and can't find a solution so i turn to the masses. As an example, i have a function like
test: function() {
request.get({
url: defaultHost,
headers: {
}
}, function(err, httpResponse, body) {
if(err) {
return err;
} else {
console.log(body);
return body;
}
});
}
this works will. i'm now trying to create the test for it in mocha. the problem that i'm getting is that i have no idea how to get the return function from the .get call into the mocha test. the api returns json, so i know that i'm going to have to be doing an is equal comparison, but at the moment i can't even get it to print the results. i think the problem with is that with my other mocha tests that i can get working, they all have an argument that you pass in where as this doesn't. my current code for the test looks like this.
describe('#test', function() {
it('tests api reachability;', function() {
var test = new test();
});
});
if someone can explain what is required afterwards or even just point me in the right direction on google, that would be awesome. i'm normally pretty good at the google, but failing to find direction on this one.
I think nock will solve this issue. Let's assume you sending get request to some resource (http://domain.com/resource.json) and the tests would be like this:
var nock = require('nock');
// ...
describe('#test', function() {
beforeEach(function () {
nock('http://domain.com')
.get('resource.json')
.reply(200, {
message: 'some message'
});
});
it('tests api reachability;', function() {
var test = new test();
});
});
I have a problem with a jQuery Ajax request that does not respond when my NodeJS server crushes.
function postRequest(url, query, onComplete) {
$.post(url, query)
.done(function (response) {
onComplete(false, response);
})
.fail(function (xhr) {
onComplete(true, xhr.status);
});
}
postRequest('/noderoute', {id: 4}, function (error, res) {
if (!error) {
$('#content').html(res);
}
else {
alert(res);
}
});
If the server responds, all is good and well but if it crushes nothing happens. How can I solve this? Thank you.
Edit: Solved
I have been running my tests on a production build instead of my development files. Everything working fine now.
You are passing an incorrect xhr argument to your fail call.
.fail(xhr, function () {
should be
.fail(function (xhr) {