My Quotes


When U were born , you cried and the world rejoiced
Live U'r life in such a way that when you go
THE WORLD SHOULD CRY






Friday, April 15, 2016

Different Ways of Injecting Dependency in an AngularJS Application


In AngularJS, dependencies can be passed in three possible ways. They are as follows:

  1. Passing a dependency as Function Arguments
    1. Passing dependencies as function arguments works perfectly fine until we deploy the application in the production with a minified version of the application.
    2. Usually to improve the performance, we minify the application in production, but passing the dependency as a function argument breaks when we minify the application.
    3. This is because the parameter name will change to a shorter alias name.
    app.controller("ProductController", function ($scope) {
         $scope.message = "Hey I am passed as function argument"
       });
           
  2. Passing a dependency as Array Arguments
    1. Most popular way of passing a dependency in an AngularJS application is passing them as Array Arguments.
    2. When we pass a dependency as an Array Argument, the application does not break in production when we minify the application.
    3. We can do this in two possible ways.
      1. Using the Named function
        var app = angular.module('app', []);
          function ProductController($scope) {
              $scope.greet = "Infragistics";
          };
          app.controller('ProductController', ['$scope', ProductController]);
                      
        1. We are passing a dependency $scope object in the array along with the name of the controller function.
        2. More than one dependency can be passed, separated by a comma.
        3. For example, we can pass both $http service and the $scope object as dependencies
        var app = angular.module('app', []);
                function ProductController($scope,$http) {
              $scope.greet = $http.get("api.com");
            };
            app.controller('ProductController', ['$scope','$http', ProductController]);
                       
      2. Using the Inline Anonymous function
        1. You can pass dependencies as array arguments exactly the same way you pass them in named controller functions.
        2. We can pass dependencies in an inline function as array arguments
        3. Keep in mind that dependencies injected as Array arguments work even if we minify the application.
        var app = angular.module('app', []);
          app.controller('ProductController', ['$scope', '$http', function ($scope,$http) {
              $scope.greet = "Foo is Great!"
          }]);
         
  3. Passing a dependency using the $inject service
by using the $inject service. In doing so, we manually inject the dependencies. We can inject $scope object dependencies using the $inject service 
 function ProductController($scope){
     $scope.greet = "Foo is Not Great!5";
 }
 ProductController.$inject = ['$scope'];
 app.controller('ProductController', ProductController);
Using the $inject service also does not break the application when we minify the application for production. Most often we will find $inject services being used to inject dependencies in unit testing of the controller 
  1. Create a Calculator service
    app.factory("Calculator", function () {
    return {
    add: function (a, b) {
    return a + b;
    }
    }
    });
    
  2. Use a Calculator service inside CalController
    app.controller('CalController', CalController);
    function CalController($scope, Calculator) {
    $scope.result = 0;
    $scope.add = function () {
    alert("hi22");
    $scope.result= Calculator.add($scope.num1, $scope.num2);
    }
    };
    
  3. At this point, the application should work because dependencies are passed as function arguments.
  4. However, the application will break when we minify it.
  5. So, let's go ahead and inject the dependencies using the $inject
    CalController.$inject = ['$scope', 'Calculator'];
    
  6. On the view, the controller can be used as shown below:
    {{result}}

Tuesday, December 8, 2015

Maven Project Version in application




Getting Project Version to be displayed in the pages without much hassles..


pom.xml file changes 
   
    maven-war-plugin
    2.4
         
     WebContent
     false
    
   

${project.version} in your html file

Repeated columns in JPA


I wanted to define repeated columns in JPA. But when I do, I got the message the second column should be defined as insert="false" , update="false"


 Approach 1: Here is an easy way to do it. In the entity bean define the second property as follows 

        @Column(name="UPLOAD_DATE")
        private Date uploadDate;
        @AttributeOverride(name="uploadDateAsTime", column = @Column
                        (name = "UPLOAD_DATE"))
        private Timestamp uploadDateAsTime;
        @Column(name="UPLOAD_STATUS")
 

 Approach 2: Here is the alternatie way to do it via XML file.. 


it would take care of giving unique names for enbeddable field columns in target entity class.

                
                
                 ddl, callback 
                

Friday, December 4, 2015

Spring Custom Context Loader


Use Spring Custom Context Loader.


import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.annotation.WebListener;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.context.support.SpringBeanAutowiringSupport;

import com.fra.exception.ApplicationException;
import com.fra.exception.SystemException;
import com.fra.fv.service.IModuleConfigService;

@WebListener
public class CustomContextListener implements ServletContextListener {
 @Autowired
 @Qualifier(value = "mdlConfigService")
 IModuleConfigService mdlConfigService;
 final static Logger logger = Logger.getLogger(CustomContextListener.class);

 public CustomContextListener() {
  super();
 }

 @Override
 public void contextInitialized(ServletContextEvent event) {
  SpringBeanAutowiringSupport.processInjectionBasedOnCurrentContext(this);
  try {
   mdlConfigService.loadModuleConfigs();
  } catch (ApplicationException e) {
   logger.error(ExceptionUtil.getFullExceptionAsString(e, 50));
  } catch (SystemException e) {
   logger.error(ExceptionUtil.getFullExceptionAsString(e, 50));
  }
 }

 @Override
 public void contextDestroyed(ServletContextEvent event) {
 }
}

Wednesday, August 5, 2015

Clear OUTLOOK CACHE


Solution 1:   Manually Delete    (For ALL Versions of Outlook)

1. Open Outlook.
2. Type the e-mail address you wish to clear from the cache.
3. Press the Down-Arrow button (on the keyboard) to select the e-mail address.
4. Press the Delete button (on the keyboard).
5. That e-mail entry is now removed from the Outlook Auto-complete cache.

Solution 2:  Empty Auto-Complete List Button    (ONLY for Outlook Versions 2010 & 2013)

1. Open Outlook.
2. Click File | Options.
3. Click on the Mail tab on the right.
4. Scroll down to Send messages and click the Empty Auto-Complete List button.

Solution 3:  Recreate the .nk2 File    (ONLY for Outlook Versions 2003 & 2007)

1. Close Outlook.
2. Open Windows Explorer or Internet Explorer.
3. Paste the following into the Address Bar:  %APPDATA%\Microsoft\Outlook
4. Delete the following file from this folder:   Outlook.nk2

Important Note:  This will delete ALL of your cached e-mail addresses.  It should ONLY be used if you want to wipe clean your cache or if there is corruption issues in your .nk2 file.  The first time you open Outlook after deleting this file, Outlook will create a NEW .nk2 cache file automatically & start caching the e-mail addresses you use from here on out.