XHR Listener

12:15 AM Hendry 0 Comments


// Add jquery here
(function() {
   var proxied = window.XMLHttpRequest.prototype.send;
   window.XMLHttpRequest.prototype.send = function() {
       //Here is where you can add any code to process the request. 
       //If you want to pass the Ajax request object, pass the 'pointer' below
       var pointer = this
       var intervalId = window.setInterval(function(){
        //0: request not initialized 
        //1: server connection established
        //2: request received 
        //3: processing request 
        //4: request finished and response is ready
               if(pointer.readyState != 4){
                   return;
               }else if(pointer.readyState == 4){
                   //code here
                   
               }
               // will be raised whenever an AJAX request co

               //Here is where you can add any code to process the response.
               //If you want to pass the Ajax request object, pass the 'pointer' below
               clearInterval(intervalId);

       }, 1);//I found a delay of 1 to be sufficient, modify it as you need.
       return proxied.apply(this, [].slice.call(arguments));
   };


})();

0 comments:

Check Concurrent Job Status Running

2:41 AM Hendry 0 Comments

SELECT DISTINCT fcp.user_concurrent_program_name,
                fcp.concurrent_program_name,
                fcr.request_id,
                fcr.request_date,
                flv.meaning status,
                fcr.status_code,
                fcr.completion_text,
                fcr.logfile_name,
                fcr.outfile_name,
                fcr.argument_text
  FROM apps.fnd_concurrent_programs_vl fcp,
       apps.fnd_concurrent_requests    fcr,
       apps.fnd_lookup_values          flv
 WHERE fcr.concurrent_program_id = fcp.concurrent_program_id
   AND trunc(fcr.last_update_date) = trunc(SYSDATE)
   AND flv.lookup_code = fcr.status_code
   AND flv.lookup_type = 'CP_STATUS_CODE'
   AND REQUEST_DATE like'%06-NOV-%' 
 ORDER BY fcr.request_date,
          fcr.request_id DESC;

How to create Android APK file in Android Studio

9:32 PM Hendry 0 Comments

How to create Androdi APK file in Android Studio?

1. Click drop down button at the top toolbar
2. Select Edit configuration



3. Edit configuration popped up

4. Select gradle 



5.  Gradle Project  > select your module name
6. Tasks > type "assemble"
7. Click OK
8. Your APK file will be in ProjectName\app\build\outputs\apk



0 comments:

Asynchronous call with AngularJs and Spring

2:22 AM Hendry 0 Comments

UI first, content later!

This tutorial is intended to demonstrate an asynchronous call using AngularJs and Spring MVC project.

In order to perform an asynchronous service call, we will use AngularJs ajax http.Post method to call backends (such as SOAP/REST services or Database), and it will also map the data returned from controller to each field on the View.

Include AngularJS in Spring MVC Project
1. Download AngularJS https://angularjs.org/
2. Include AngularJS javascript files under your resources folder and jsp. How to include resource files in Spring project


Asynchronous Call
Spring MVC consists of Model, View, and Controller, however AngularJs covers the View only.



View and Controller

According to the picture above, it describes as the following

1. Spring View handles the page redirection using http.Get from the View. For example when the webpage url is called ndry93.blogspot.com/webpage1

2. Spring Controller returns the requested view name, and thus web page will render.

 @RequestMapping(value = "/webpage1", method = RequestMethod.GET) 
public String index() {               
     return "webpage1"; 
}

3. Asynchronously, AngularJs Ajax http.Post will be executed when the page is rendering its content. See AngularJS tutorial and documentation ( https://docs.angularjs.org/guide )  and http://www.w3schools.com/angular/angular_http.asp

For example,
<script type="text/javascript" src"<c:url value="/resources/js/angular.min.js" />"></script>
<script type="text/javascript">
var app = angular.module('myApp', []);
app.controller('customersCtrl'function($scope, $http) {
  $http.post("getSRDetails.htm", { ticketNumber : "1004406487" })
  .success(
          function (response) {
                $scope.srdetails = response;
          });
});
</script>

8. In the Controller, we should have code as the following to capture request from the View. Assume we get the values from backend service, then we need to convert the list of values into JSON format before we send it back to the view.


@RequestMapping(value = "/getSRDetails.htm", method = RequestMethod.POST)
public @ResponseBody
String GetSRDetails(@RequestBody Map requestthrows JsonGenerationException, JsonMappingException, IOException {

       List<SRConversationDetail> sRConversationDetails = 
                 serviceRequestFacade.retrieveSRDetails(request.get("ticketNumber").toString());
       logger.info("Service Request details size "sRConversationDetails.size());
       ObjectMapper converter = new ObjectMapper();
       logger.info("Service Request details converted: "sRConversationDetails);
       return converter.writeValueAsString(sRConversationDetails);


}

*@RequestBody since request param data sent through request body http POST method. *Use Map data type because the request param is in JSON format


In result, browser will render webpage1.jsp and display contents from Ajax http.Post method by calling /getSRDetails.htm. 


for more detail on the entire design see the next post

AngularJS Documentation

Spring MVC highlevel design for better performance and user experience

7:32 AM Hendry 0 Comments

This post is intended to discuss on enhancing Spring MVC so that it has better performance, and better user experience.
How to maximize performance and user experience? There are few things that could affect your web app performance and user experience. In my opinion for a better user experience, we should have "Let UI display first, content later". Asynchronously displaying content is the key to boost user experience. Suggestion is to use AngularJS to perform an asynchronous call


Here is my high-level design on my Spring MVC project

View represents your jsp files (html, css, javascript, jquery, and angular js ajax http.post)

Controller represents java files with @Controller and @RequestMapping and if required @RequestParam to accept input parameter from view

Model represents java files for your business object

Service represents java files for your business logic, and have direct access to Helper classes. This is where you set for example wsdl request parameters, and map response from WSDL java object to your POJO Model 

Helper represents java files that have direct access to WSDL to perform service call




AngularJs and Spring Integration

8:37 AM Hendry 0 Comments


The purpose of this tutorial is to perform an integration between AngularJs and Spring MVC and to demonstrate how easy to use AngularJs with Spring is.

Include AngularJS in Spring MVC Project


1. Download AngularJS https://angularjs.org/
2. Include AngularJS javascript files under your resources folder and jsp. See previous post


Try AngularJs!


Copy below codes on your jsp

<script src="<c:url value="/resources/libs/angularjs/1.3.14/angular.min.js" />"></script>
<body>

<div ng-app="">
  <p>Name : <input type="text" ng-model="name"></p>
  <h1>Hello {{name}}</h1>
</div>

</body>

http://www.w3schools.com/angular/tryit.asp?filename=try_ng_default

AngularJS Documentation


How to include resources files in JSP Spring MVC

4:24 AM Hendry 0 Comments



Configure the root resource folder in your dispatcher class (default servlet-context.xml)

  
  <resources mapping="/resources/**" location="/resources/" />

Add your resources file under "resources" folder



In your jsp file

1.      Add below code on the most top .jsp file
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>

2.      Javascript
<script type="text/javascript" src="<c:url value="/resources/jquery/jquery-1.11.1.min.js" />"></script>

3.      CSS
<link href="<c:url value="/resources/form.css" />" rel="stylesheet"  type="text/css" />

How to Run Spring MVC in Weblogic server

9:07 PM Hendry 0 Comments

What you need to have


1. Eclipse IDE with Spring Tool Suite Installed
2. Spring MVC Project
3. weblogic.xml
4. Running Weblogic server

Create weblogic.xml


1. Right click on "WEB-INF" folder and select "New" > "Other"



2. Create "XML" file and name it as "weblogic.xml"



3. "weblogic.xml" is now created under "WEB-INF" folder


4. Copy below codes and paste into your weblogic.xml
<?xml version="1.0" encoding="UTF-8"?>
<weblogic-web-app xmlns="http://xmlns.oracle.com/weblogic/weblogic-web-app">
<context-root>CreateSpringMVC</context-root>
<container-descriptor>
<prefer-web-inf-classes>true</prefer-web-inf-classes>
</container-descriptor>
</weblogic-web-app>

5. Export project as WAR file, and install on your weblogic server 

How to create Spring MVC Project in Eclipse

11:37 PM Hendry 0 Comments



What you need to have
1. Eclipse IDE JEE
2. Spring Tool Suite
3. Apache Tomcat


Apache Tomcat Installation

1. Download Apache Tomcat download here


2. Extract zip file to your local directory
Eclipse Installation


1. Download Eclipse IDE Java EE download here

2. Extract zip file to local directory
3. Run eclipse.exe, and create your workspace for eclipse project repository
4. You should see eclipse welcome page


Spring Tool Suite Installation


    1. Navigate to Help > Eclipse Market Place


    2. Eclipse Marketplace window opened, then search "STS"

    3. Click "Install" Spring Tool Suite (4.4) 3.6.4 RELEASE
    4. Click "Confirm" 

    5. Select "Accept" and click "Finish"




    You are now installing Spring Tool Suite


    1. Restart spring

    2. Confirm that Spring is installed successfuly. Navigate to Help > About Eclipse
    3. About Eclipse window opened, click "Spring IDE Developers"

    4. Spring Tool Suite was installed successfully 



    Create Spring MVC Project

    1. Navigate to File > New > Others

    2. Select "Spring Project" 


    3. Select "Spring MVC Project",  Name your project, and click "Next"


    4. Name your project package, and click "Finish"


    5. You should now see your project on "Project Explorer" tab


    Run your Spring MVC Hello World on Local Apache Tomcat


    1. Right click on your project > Run As > Run on server 



    2. Select "Tomcat v8.0", and click "Next"



    3. Browse to your apache tomcat directory, and click "Finish"



    4. You may encounter a problem when starting tomcat because port 8080 is in use. Just click "OK"


    5. Open "Servers" tab at the bottom, and double click



    6. Tomcat overview window is now open, change HTTP/1.1 port from 8080 to for example 8082 then press "Enter". Close the window and save changes.



    7. Run your project ( Right click on your project , select "Run as" > "Run on server" > "Finish"


    8. Done!