5. Data transfer: OGNL and type conversion Flashcards
What does OGNL stand for?
Object Graph Navigation Language
What’s the OGNL escape sequence?
%{expression}
What’s the difference between these fields when OGNL converts them to Java?
![](https://s3.amazonaws.com/brainscape-prod/system/cm/343/275/462/q_image_thumb.png?1618863263)
- ages – Sets the whole array.
- names – Sets individual index with value (calls get, then sets value). SO array MUST be initialized!
![](https://s3.amazonaws.com/brainscape-prod/system/cm/343/275/462/a_image_thumb.png?1618863291)
How do we tell OGNL what types to convert values to?
Create a ClassName-conversion.properties file next to the Java Class.
![](https://s3.amazonaws.com/brainscape-prod/system/cm/343/276/245/a_image_thumb.png?1618863790)
Regarding OGNL convertions properties file, how would you convert values named ‘weights’ from a generic list to a list of Doubles?
Add a line:
Element-weights=java.lang.Double
Note: Prefix of ‘Element-‘ and the full path to the Type.
![](https://s3.amazonaws.com/brainscape-prod/system/cm/343/276/346/a_image_thumb.png?1618863925)
What’s the syntax for using OGNL to populate a map from HTML?
Two ways you can do it:
map.key
or
map[‘key’]
![](https://s3.amazonaws.com/brainscape-prod/system/cm/343/277/132/a_image_thumb.png?1618864418)
Regarding HTML -> Java OGNL is the -conversion.properties NEEDED when dealing with List/Set/Map?
If you’re not using a typed generic, yet. But you should be using generics in which case it will work wihtout the properties file!
Ex: Map
What interface must be implemented to give OGNL ability to convert types? What 2 methods need to be implemented?
–Interface–
StrutsTypeConverter
–Methods–
convertFromString(Map context, String[] values, Class toClass)
String convertToString(Map context, Object o)
What is the OGNL properties file that’s used globally? Where should it be located?
xwork-conversion.properties
Place it in the root of the classpath.