Posts

OGNL with Field and Method

Calling Method/Field using OGNL Java code utilityObj.makeRandomNumber() utilityObj.getRandomNumberValue() OGNL code makeRandomNumber() getRandomNumberValue() randomNumberValue Here we are assuming that the utilityObj is available in the ValueStack. Static Field @fullClassName@(property or methodName) Static Method @com.data.constants.UtilityClass@getDayName() but here if we assume some object in the valuestack available and we want to access its static properties then @vs@USERNAME @vs@getTodaysDate() here 'vs' is the symbol for the valuestack.

Operators of the OGNL

Operators of the OGNL sum (+) : 2 + 4 , 'hello' + 'world' minus (-) : 5 – 3 multiplication(*) : 9*9 division(/) : 99/3 modulo (%) :  99% 3 increment (++) : ++pre , post++ decrement (--) : post-- , --pre equality (==)  : hello == world greater than (>) :  19 > 10 less than  (<) :  10 < 20

Literal of the OGNL

Literal of the OGNL Literal : Example Char : 'a' String : 'hello' or  "hello"  Boolean : True , False int : 178 double : 199.5 BigDecimal : 777b BigInteger : 777h

Filter and Projection on Collections using OGNL

Filter and Projection on Collections using OGNL Filter Syntax for the filter collectionObjectName.{? expression} Filtering filter the objects from the collection based on the expression provided. For example students.{?#this.percentage>70} Here it will return  new students collection having percentage greater than 70. Filtering always gives less than or equal to the number of elements available in the collection based on the provided expression. Projection Syntax for projection Projecting always gives exactly the same number elements available in the original main collection. students.{name}; Here this projection will gives you a new collection contains only the name of all the students elements available in the original collection. students.{name+''+percentage}; Here this projection will gives you a new collection contains  the name + percentage combination of all the students elements available in the original collection. students.{?#this.percentage...

Create Map dynamically using OGNL

Create Map dynamically using OGNL Java Code Map<Integer,String> myMap =  new HashMap<Integer,String>(); myMap.put(1,"one"); myMap.put(2,"two"); myMap.put(3,"three"); myMap.put(4,"four"); myMap.isEmpty() : myMap.isEmpty OGNL Expression #{1:"one", 2:"two", 3:"three", 4:"four"} Example: 1) <s:iterator value="#{1:'one', 2:'two', 3:'three', 4: 'four'}" status="counter"> <s:property value="#counter.index"></s:property> <s:property value="key"></s:property> <s:property value="value"></s:property> </s:iterator> Here we are creating the map dynamically in the value attribute. In this case # sign is used to creat the map object. 2) <s:iterator value="#request.studentsMap" status="counter"> <s:property value="#cou...

Explore Maps using OGNL

Explore Maps using OGNL Java Code : OGNL Expression myMap.get("id") : myMap.id myMap.get("id") : myMap['id'] myMap.size : myMap.size User user = (User)myMap.get("user") : myMap.user.name user.getName() (configuration of the OGNL type conversion required : see here for more in

Explore List and Array using OGNL

Explore List and Array using OGNL Java Code : OGNL Expression dataList.get(0) : dataList[0] dataArray[0] : dataArray[0] ((Student)dataList.get(0)).getName() : dataList[0].name dataArray.length: dataArray.length dataList.size() : dataList.size dataList.isEmpty() : dataList.isEmpty