<< HTTP Temporary redirect and Permantent redirect | Home | Eclipse | Java | Linux | SEO | Photos | Videos | Blog | Recipes | Links | My Profile | Sitemap URL Link >>

Struts 2 OGNL Syntax for Collections

Howto: Setting and getting values in a collection via OGNL in Struts 2

in geronimo, ,

For Lists

  • In Java code:
    List list = new ArrayList(3);
    list.add("one");
    list.add("two");
    list.add("three");
    
  • In OGNL, it is equivalent to:
    
    
    
  • To access it in JSP:
    roperty value="list[1]">roperty>
    
  • Will output in HTML:
    Value=two
    

For Maps

  • In Java code:
    Map map = new HashMap(3);
    map.put("one", "uno");
    map.put("two", "dos");
    map.put("three", "tres");
    
  • In OGNL, it is equivalent to:
    
    
    
  • To access it in JSP:
    Value=roperty value="map['one']">roperty>
    
  • Will output in HTML:
    Value=uno
    




Add a comment Send a TrackBack