Etc

A way to call the JSON service

nexacro platform provides various communication  ways.
This explains about a way to call JSON type data.

json1

Main Source Code

Form Code

this.Button01_onclick = function(obj:Button,  e:nexacro.ClickEventInfo)
{
  var strInDS = "";
  var strOutDS = "Dataset00=dsDetailMain";
  var strParams = "";
  var strCallback = "fn_init_callback";
  this.transaction("load", "Svc::json.jsp", strInDS, strOutDS, strParams, strCallback);
}
  
this.fn_init_callback = function (sid, errcd, errmsg)
{   
  if (errcd == 0) {
    this.Grid00.createFormat();
  }            
}

Main Source Code for JSON data format handling

_pTransactionItem._deserializeData = function (strRecvData, bPending) 
{     
 if (!strRecvData)
  return [-1, "Stream Data is null!"]; 
 strRecvData = strRecvData.trim();
 var fstr = strRecvData.substring(0, 3);
 
 if (fstr == "SSV") // SSV Type (HEX:53,53,56)
 { 
  return this.__deserializeSSV(strRecvData);
  
 }
 else if (fstr == "CSV") // CSV Type (HEX:43,53,56)
 { 
  return this.__deserializeCSV(strRecvData);
 }
 else if (fstr == "PPX") // PPX Type : Runtime only
 { 
  return this.__deserializeJSON(strRecvData);
 } 
 // Additional code for JSON handling
 else if (fstr == "JSN") {
 }
 //<< Additional code for JSON handling
 else // XML Type (HEX:3C,3F)
 {   
  //return this.__deserializeXML(strRecvData);
  return this.__deserializeJSON(strRecvData);
 }
}
// When receive data under transaction, JSON handling 
_pTransactionItem.__deserializeJSON = function(strRecvData) 
{
 var code = 0;
 var message = "SUCCESS";
 
 var outDatasets = this.outputDatasets;
 if (outDatasets && outDatasets.length)
 {
  var revcJsonObj = JSON.parse(strRecvData);
  if (!revcJsonObj) 
  {
   code = -1;
   message = "Fail JSON.parse";
  }
  var outDataCnt = outDatasets.length;
  for (var i = 0; i < outDataCnt; i++)
  {
   // this.context: access form object
   var ds = this.context._getDatasetObject(outDatasets[i].lval);
   if (ds) {
    ds.clear();
    this.context.createDatasetColInfo(ds);
    this.context.addData(ds, revcJsonObj);
   }
  }
 }
 return [code, message];
}   
// dataset initialization
this.createDatasetColInfo = function(ds) 
{
 var nIndex = ds.addColumn( "name", "string" );
 nIndex = ds.addColumn( "surname", "string", 120 );
}
// data processing
this.addData = function(ds, jsonObj) 
{
 for (var j = 0 ; j < jsonObj.length ; j++) 
 {
  jObj = jsonObj[j];
  var rIdx = ds.addRow();
  ds.setColumn(rIdx, "name", jObj.name);
  ds.setColumn(rIdx, "surname", jObj.surname);
 }
}

You need to change column name into column name of DataSet.

Example ) name, surname

JSP

<%@page contentType="text/html; charset=UTF-8"%>
<%@page import="org.json.simple.JSONObject"%>
<%@page import="org.json.simple.JSONArray"%>
<%
  JSONArray users = new JSONArray();
  JSONObject obj=new JSONObject();
  obj.put("name","Ambarish");
  obj.put("surname","Aura"); 
  users.add(obj);
  obj=new JSONObject();
  obj.put("name","bmbarish");
  obj.put("surname","Bura"); 
  obj=new JSONObject();
  obj.put("name","Cmbarish");
  obj.put("surname","Cura"); 
  users.add(obj);
  response.getWriter().print(users);
%>

JSP Result

[{"surname":"Aura","name":"Ambarish"},{"surname":"Cura","name":"Cmbarish"}]

Source Location

Sample\ListBox\np_Transaction_JSON.xfdl

DomParser

To use XML type data, You  have to parse XML type documents before using.
This explains about a way to access to  XML document using DomParser.

domparser1

Main Source Code

Node List

var domDoc;
var domPar = new DomParser;
domDoc = domPar.parseFromString(this.TextArea00.value);

var domElement1, domElement2;  
var i, j;
var msg="";
for( i = 0 ; i < domDoc.childNodes.length ; i++ )
{
  domElement1 = domDoc.childNodes[i];
  msg += "Node1["+i+"] = " + domElement1.nodeName + "\n";
  for( j = 0 ; j < domElement1.childNodes.length ; j++ )
  {
    domElement2 = domElement1.childNodes[j];
    msg += "    Node2["+j+"] = " + domElement2.nodeName + "\n";   
  }
 }  
 this.TextArea01.set_value(msg);

Node Value

// Parsing
 var domDoc;
 var domPar = new DomParser;
 domDoc = domPar.parseFromString(this.TextArea00.value);
 // Checking Node value
 var domElement;  
 var msg="";
 
 domElement = domDoc.getElementsByTagName("Dataset");
 msg += "Dataset TAG의 id값 = " + domElement[0].getAttribute("id") + "\n";
 
 domElement = domDoc.getElementsByTagName("Column");
 msg += "ID value of first Column TAG = " + domElement[0].getAttribute("id") + "\n";
 msg += "ID value of second Column TAG = " + domElement[1].getAttribute("id");
     
 this.TextArea01.set_value(msg);

Source Location

Sample\Etc\np_DomParser.xfdl

Most browsers parse XML string using DOMParser object.

IE browser parses XML string using ActiveXObject object.

How to use jQuery

Preparation

Copying related jQuery module

To use jQuery copy the jquery lib file to engine folder of  nexacro platform.
1) Copy the ExtApi.json file to nexacro component directory
For example) C:\Program Files (x86)\nexacro\14\nexacro14lib\component\ExtAPI.json
2) Create the ExtAPI directory in the component directory
For example) C:\Program Files (x86)\nexacro\14\nexacro14lib\component\ExtAPI .
3) Copy the jquery-1.10.2.js file to ExtAPI folder in the component directory
For example) C:\Program Files (x86)\nexacro\14\nexacro14lib\component\ExtAPI\jquery-1.10.2.js

Reference) This ExtAPI and file are below

Sample\Etc\jQuery

jQuery_0

Window explorer form is expressed differently by country and OS.

You should do the same work as above in the WAS.

jQuery_1

Registering ExtAPI.jsp module in TypeDefinition in nexacro studio

jQuery_2

jQuery_3

jQuery_4

Click the OK button after registeration like above.

Implementing animation Using JQuery

jQuery_animation_0

We implemented moving effect using animation function of jQuery.

Source location

Sample\Etc\np_jQuery_animate.xfdl

A way to use Local DB

Basic

This explains about how to configure Local DB.
  1. How to create Lite DB

  2. Data Definition (DDL)

  3. Data Manipulation Language (DML)

How to create Lite DB

localdb_new1

Adjust datasource location to your development environment.

localdb_new31

localdb_new1

localdb_new1

Data Definition (DDL)

localdb_new1

localdb_new1

After completing table creation or modification, please check whether it is accomplished clicking on [Execute SQL] button. [ctrl + s] button does not save changed information of Table.

localdb_new1

localdb_new1

You can do table work using SQLite Manager of Firefox additional function.

See a way to use SQLite Manager for detailed information , We don't explain about the Utility .

localdb_new11

localdb_new11

You can verify Table information created by naxacro using SQL Manager.

localdb_new11

You can manage Table management using SQL Manager. So this is useful.

We recommend you to use SQL Manager.

Data Manipulation Language (DML)

Preparation to implement insert, update, delete and select statement

Insert

This is setting for insert
Ex)
insert into department values('100','CS Team','Gangnam-Gu, Seoul, Korea','135-873','1588-7895')

localdb_new11

this.Button00_onclick = function(obj:Button,  e:nexacro.ClickEventInfo)
{
    this.LiteDBConnection00.open();
    this.LiteDBStatement00.executeUpdate();
}

localdb_new17

localdb_new11

Select

This explains about a way to select data from Table.

localdb_new17

localdb_new31

this.Button03_onclick = function(obj:Button,  e:nexacro.ClickEventInfo)
{
    this.LiteDBConnection00.open();
    this.SelectStatement.executeQuery();
}
Ex)
select code, name, address, zipcode, telno from department

localdb_new31

this.SelectStatement_onsuccess = function(obj:LiteDBStatement,  e:nexacro.LiteDBEventInfo)
{
    if(e.reason == 7) // Select
   {
        this.dsDepartment.copyData(e.returnvalue);
   }
}

localdb_new31

Update

This explains about a way to update existing data.
Create update button and LiteDBStatement and then write update statement in query in Properties.

localdb_new35

this.Button01_onclick = function(obj:Button,  e:nexacro.ClickEventInfo)
{
    this.LiteDBConnection00.open();
    this.UpdateStatement.executeUpdate();
}
Ex)
update department set name = 'Support Team' where code = '100'

localdb_new35

Delete

This explains about a way to delete existing data.

localdb_new35

this.Button02_onclick = function(obj:Button,  e:nexacro.ClickEventInfo)
{
    this.LiteDBConnection00.open();
    this.DeleteStatement.executeUpdate();
}
Ex)
delete from department where code = '100'

Etc

  1. LocalDB does not work when LocalDB is located in server. Please use localDB after putting LocalDB in local.

  2. LocalDB sample provides interlocking with open source SQLite. We do not provide technical support about SQL query statements or ways to use query statements..

  3. You can modify column of DB file using SQLite edit program.

Local DB sample with DataSet

After understanding about Local DB content, please try to apply Local DB to your project referring to sample with grid and dataset.

localdb_new38

Preparation

  1. Down load a zip file from link below and unzip in your pc directory.

  2. Copy localDB.s3db file from DB folder into Documents folder.

  3. Run nexacro studio and open sample project in LocalDB folder.

Related content is already explained, so we do not explain about source more.

Related Source

Local DB Sample Source

http://www.xplatform.co.kr:8080/Next_JSP/Docs/LocalDB.zip