Questions tagged [ognl]

OGNL stands for Object-Graph Navigation Language. It is an expression language for getting and setting properties of Java objects.

OGNL stands for Object-Graph Navigation Language (pronounced oganal); it is an expression language for getting and setting properties of Java objects, plus other extras such as list projection and selection and lambda expressions. You use the same expression for both getting and setting the value of a property.

The official site, gives the following uses to which OGNL has been applied:

  1. A binding language between GUI elements (textfield, combobox, etc.) to model objects. Transformations are made easier by OGNL's TypeConverter mechanism to convert values from one type to another (String to numeric types, for example)
  2. A data source language to map between table columns and a Swing TableModel;
  3. A binding language between web components and the underlying model objects;
  4. A more expressive replacement for the property-getting language used by the Apache Commons BeanUtils package or JSTL's EL (which only allow simple property navigation and rudimentary indexed properties).

It is used as an expression language in various projects:

  1. Apache Click
  2. Spring Web Flow
  3. Tapestry
  4. Struts 2.

Useful resources:

  1. Official Site
  2. Developer Guide
  3. Language Guide
622 questions
79
votes
3 answers

What's the difference between # , % and $ signs in Struts tags?

I'm working with Struts 2 and when I'm accessing ValueStack variables I don't know whether to use % or # or $. I try all of them until I find the correct one. Can anybody explain what is the difference between them?
Khashayar
  • 2,014
  • 3
  • 22
  • 31
19
votes
4 answers

OGNL Hello World in Java

I need to use OGNL for reading some properties from Java object. OGNL is completely new thing to me. The documentation available for OGNL is OGNL's website is really confusing to me. So anyone can provide a simple HelloWorld example for using OGNL…
Veera
  • 32,532
  • 36
  • 98
  • 137
16
votes
6 answers

Format number in Struts 2 tag

I would like to format number displayed by tag in Struts 2. There is a double value. How can I do that? Should I use OGNL? Or maybe I must use tag and define my format in resuource file?
prostynick
  • 6,129
  • 4
  • 37
  • 61
11
votes
1 answer

Two different Class instances giving same hashCode

I'm encountering a bizarre issue on a JBoss server where two classes are producing the same hashCode(). Class cl1 = Class.forName("fqn.Class1"); Class cl2 =…
Glenn Lane
  • 3,892
  • 17
  • 31
11
votes
1 answer

Struts2 accessing enum from JSP

I have the following class package com.test; public class SomeClass { public enum COLOR {RED,BLUE} } I want to access values of COLOR enum in my JSP. I've tried the following code but it doesn't work.
Dev Blanked
  • 8,555
  • 3
  • 26
  • 32
10
votes
2 answers

Benefits to using Spring EL over OGNL?

I was wondering what exactly moved Spring to use Spring EL over OGNL in its web flow product: http://static.springsource.org/spring-webflow/docs/2.2.x/reference/htmlsingle/spring-webflow-reference.html#el-language-choices With OGNL, I can…
MetroidFan2002
  • 29,217
  • 16
  • 62
  • 80
10
votes
2 answers

Struts 2 dynamic variables

I'm trying to create a dynamic variable in Struts2 using set tag numConst will return a dynamic value that retrieved from database. For…
9
votes
1 answer

Struts 2 "%" sign and '#" sign in OGNL

Anybody can tell me how to use "%" and "#" sign in STRUTS2 OGNL? I google around, but can't find any valuable info about this.Or give me a link of documentation of this. thanks
acoolme
  • 91
  • 1
  • 3
9
votes
4 answers

Accessing static variable using OGNL in Struts2

Good day! I am reading Manning's struts2 book and one of the topic is accessing the static variable using OGNL using the syntax @[fullClassName]@[property or methodCall] so I tried it on my program and my code is as follows: BEAN: public class…
newbie
  • 14,582
  • 31
  • 104
  • 146
9
votes
3 answers

Object tree navigation language in Java

In the system which I'm currently developing I often have to navigate an object tree and based on its state and values take actions. In normal Java this results in tedious for loops, if statements etc... Are there alternative ways to achieve tree…
paweloque
  • 18,466
  • 26
  • 80
  • 136
9
votes
4 answers

Struts 2 nesting iterators

I can't believe how something this simple can seem so hard to do in Struts 2. This is approximately what I would like to do as it would be done in Java. for (Parent parent : parents){ for (Child child: parent.getChildren()){ …
Bloodboiler
  • 93
  • 1
  • 1
  • 3
9
votes
4 answers

test expression evaluation for boolean value doesn't work as expected

I want to check value of variable bool_val using Struts 2 tag but it's not working. <%@ taglib prefix="s" uri="/struts-tags" %> <%boolean bool_val=true;%> real value : <%=bool_val%>
expression evaluated value :
Akash Jain
  • 93
  • 1
  • 1
  • 5
8
votes
3 answers

Mybatis If statements using include properties

I'm trying to create a generic SQL include in Mybatis that will apply a comparator given a particular value. The idea is to reuse this sql code snippet across several mappers. The issue I'm having is when using string substitution in the if…
jamesnuge
  • 81
  • 1
  • 1
  • 6
8
votes
2 answers

struts2: enum in IF

How does the following Java condition translate into s:if test="..." in struts2? if(company.getAffiliateId().asInt() != com.foo.bar.Affiliates.XYZ.asInt()){ // do something } company.getAffiliateId() returns BigDecimal com.foo.bar.Affiliates is an…
kosmičák
  • 1,043
  • 1
  • 17
  • 41
7
votes
1 answer

Accessing Map attribute with dynamic key in Struts 2 OGNL

I have a list of Strings that are attribute names and a Map. I'm trying to access a model(ex.project) in the map using attribute name in string list. Here is what I have now.
Daniel Kim
  • 446
  • 2
  • 8
  • 17
1
2 3
41 42