Thursday, November 28, 2019

JavaScript: Define Multiple Instance in Module Pattern

In JavaScript: Module Pattern with Anonymous Closure article, I have shown you how to create a Module using Immediately-Invoked-Function-Expression (IIFE). With IIFE, you only can have a single instance of the object.

What if you need to have multiple instances? Example two armies carry different weapons.

Remove () in the ARMORY module in the previous Article.
var ARMORY = (function(){
  // Private
  var weaponList = [ * List of weapon object * ];
  var removeWeapon = function(...){};
  var replaceWeapon = function(...){};

  // Public
  return{
    makeArmorRequest: function(...){}
  }
});
Now you can create multiple instances:
var army1 = new ARMORY();
var army2 = new ARMORY();

Tuesday, October 29, 2019

If you are writing ES6 syntax in designer's script library, you will get an error - ""const is a reserve identified".









I think designer default to ES5 syntax checking.

To work around, you can write your javascript at "WebContent" folder using Package Explorer. For this example, I will put my javascript in "javascripts" folder.





















This is how you point the javascript:
  <script src"javascript/like_button.js"></script>

Reference:
https://hclpnpsupport.hcltech.com/csm?id=community_question&sys_id=3bc76f951bbc481877761fc58d4bcb5e

Thursday, October 24, 2019

Object Methods in Javascript

I have introduced "Merging Object via Object.assign()" in my previous article. In this article, I will go over other important build-in object methods.

Object.create()
Object.create() method is used to create a new object and link it to the prototype of an existing object.

Object.keys()
Object.keys() create an array containing the keys of an object.

Object.values()
Object.values() create an array containing the values of an object.

Object.entries()
Object.entries() creates a nested array of the key/value pairs of an object.

Object.assign() - I would like to mention again. :-)
Object.assign() is used to copy values from one object to another.

Object.freeze()
Object.freeze() prevents modification to properties and values of an object and prevents the property from being added or removed from an object.

Object.seal()
Object.seal() prevent new properties from being added to an object but allows the modification of existing properties.

Object.getPrototypeOf()
Object.getPrototypeOf() is used to get the internal hidden [[Prototype]] of an object, also accessible through the _proto_ property.

In this example, we can create an array and access to the Array prototype.
  const employees = ['Simon','Adam','John'];
  console.log(Object.getPrototypeOf(employees));
Output:












The output is showing the employee array has access to pop, find, and other array prototype methods.

This method can be useful to get information on the available prototype methods - String, Integer, and etc.

References: 
https://www.digitalocean.com/community/tutorials/how-to-use-object-methods-in-javascript

Monday, September 23, 2019

HCL Software Customer Support Site

HCL Software launched a new customer support site.

For HCL Customer, you can register at https://support.hcltechsw.com/csm?id=csm_registration

For others where you wish to take part in the community (Forum, Knowledge Base, Attend Community Event, etc.), you can register at https://support.hcltechsw.com/csm?id=community_external_user_registration

Wednesday, September 18, 2019

NodeJS - HelloWorld with ExpressJS

In this tutorial, you are going to learn how to create an express application using Express Generator and create a hello world page by creating a new route file in nodejs.

This tutorial tested on Nodejs v10.16.2 and Expressjs v4.16.1.

1. Install Express Generator. Create the application skeleton using application generator tool. Go to the project folder and type “npm install -g express-generator”

2. Create Express Project using EJS view engine. By default, Express is using PUG view engine. For this example, we are using EJS. Use this command “express --view="ejs" [folder name]” to create the express project. Example: “C:\Users\simon.siah\workspace>express --view="ejs" nodejs-expressjs-starter”.

















3. Install dependencies. Type below command to install dependencies. It will read the package.json and install the stuff.





4. Start the server Type below command to start the server.




5. Open a browser and type http://localhost:3000/.











6. Route files. - The route files store in folder routes. - This section in app.js define the http routes. - Example: /, is using routes/index.js and /users us using routes/user.js.

7. View files - The view files store in folder views.

8. Create a Hello World Page.
  • Copy the routes/index.js and paste into folder routes, rename the files to helloworld.js. 
  • Change the content below:
  • Create helloworld.ejs in views folder: 
  • Update app.js to include helloworld route:
     
  • Start the server and enter URL -> http://localhost:3000/helloworld 
Changing the EJS templates does not require a server restart, but whenever you change a JS file, such as app.js or the route files, you'll need to restart the see the changes.

I am using sublimetext as IDE to update the sources. It is free, and you can download here: http://www.sublimetext.com/ 

Here are some useful references: 

Node.js, Express.js, MongoDb Tutorial:  

Node.js: 

Express.js: 

Thursday, August 8, 2019

CRUD using Java Bean binding in XPages Part 2

The disadvantage of part 1 is overloaded getter/setter when there are many fields. In this part 2 example, I am going to introduce the model layer using data object. By using data object, you don't need to configure the getter/setter.

Also, part 2 has included doclock and data validation functionality.

Download the database here:
https://drive.google.com/open?id=1vWWvqNlVOtV-ftUpvKYK-XJMiVcmOb5y

Notesin9:
http://www.notesin9.com/2014/01/13/notesin9-133-using-java-in-xpages-part-2/

OpenNTF DocLock:
https://www.openntf.org/main.nsf/project.xsp?r=project/XPage%20Document%20Locker

Wednesday, July 31, 2019

CRUD using Java Bean binding (Getter / Setter) in XPages

It is build using Model-Control-View (MVC) architecture.
  • Model – Field binding, configure the getter/setter, and business logic.
  • Controller – Serving the request.
  • View – XPages for  UI and Form.

Download the database here:
https://drive.google.com/open?id=1ZTITEjvp_YNakEkUhFn05PCcRWd0olQF


Part 1 Includes:
  • Bootstrap 4 Theme
  • Create, Read, Update, Delete using Java Bean
  • Text Field
  • Date Field
  • Dropdown Field
  • Checkbox Field (Multiple Value)
  • Backend Computed Data

XPages and Managed Bean: a new way to process Notes documents:
http://blog.redturtle.it/2014/02/06/xpages-javabean-new-way-to-bind-notes-document

How to use Managed Beans in XPages:
https://docs.google.com/document/d/1XFXEmXH8KFcXEHcs2qvbWqOs_TqJWJ8Dbs9CMMKLszI/mobilebasic?pli=1

Notesin9:
http://www.notesin9.com/2013/12/17/notesin9-132-using-java-in-xpages-part-1/

Quick Java Course for XPages Developers:
https://docs.google.com/document/d/1jjZIvkGQWjwYfTJBGVaE_0CyOiskLeOJ_3vlOWUjVNk
https://docs.google.com/document/d/1IdhQvybM47EMUjC8WN8vOkeGyBrirjdOk_DYbeICHRU
https://docs.google.com/document/d/1gywwFtmAdgTtGJt-LxUbxaH0yJFtbQleJlLtWzZNZpI