Skip to main content

Posts

Showing posts from March, 2012

Spring - Array configuration using xml bean configuration file

In this example I am going to give example for array configuration in spring application using XML bean configuration file. This is my bean, here I have created the setter and getter method for array variable ("countryArray").    public class ArrayConfig {       private String[] countryArray ;       public String[] getCountryArray() {             return countryArray ;       }       public void setCountryArray(String[] countryArray) {             this . countryArray = countryArray;       }       } This is my beans.xml file. The <array> tag is used for configuring array.    <? xml version = "1.0" encoding = "UTF-8" ?> < beans xmlns = "http://w...

Spring - ArrayList configuration using xml bean configuration file

In this example I am going to give example for array list configuration in spring application using XML bean configuration file. This is my bean, here I have created the setter and getter method for array list variable ("countryList").    import java.util.ArrayList;   public class ArrayListConfig {       private ArrayList<String> countryList ;       public ArrayList<String> getCountryList() {             return countryList ;       }       public void setCountryList(ArrayList<String> countryList ) {             this . countryList = countryList ;       }        } This is my beans.xml file. The <list> tag is used for configuring list. ...

Getting key/value pair from JSON object and getting variable name and value from JavaScript object.

 Hi, I had faced one issue like this. I have an JSON object but I don't know any key name but I need to get the all the key and corresponding value from JSON object using client side JavaScript. Suddenly I wondered whether it's possible or not, after that I had done lot of workaround and finally got this solution. See the below example.    function getKeyValueFromJSON() {     var jsonObj =  {a:10,b:20,c:30,d:50} ;     for ( var key in jsonObj) {       alert( "Key: " + key + " value: " + jsonObj[key]);     }  }  In this example I have created the one json array as string, and converted this string into JSON object using eval() function. Using for-each loop I got all the key value from jsonObj, and finally using that key I got the corresponding value.  Finally I got the alert like this,    Key: a value:10    Key: b value:20    Key...

Spring bean wiring (Dependency Injection)

In spring application, you have two ways for injecting beans. These are,  1. Setter based injection.  2. Constructor based injection. You can able to use primitive type as well as reference type for injecting. Example for setter based injection. In this example I am going to inject the room object into home using setter method. 1.  Create a new Room bean like this.      package com.setterinject;      public class Room {         private String roomName ;          public String getRoomName() {             return roomName ;        }          public void setRoomName(String roomName) {             this . roomName = roomName;        }      } 2 .Create a new Home bean POJO ...