This week's book giveaway is in the Design forum.
We're giving away four copies of Design for the Mind and have Victor S. Yocco on-line!
See this thread for details.
Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

struts2 tag

 
gurneeraj singh
Ranch Hand
Posts: 80
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is the use of label="%{ example}" in defining struts2 tag when we can use this directly label="example" with the help of OGNL?
 
Ankit Garg
Sheriff
Posts: 9510
22
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The %{} syntax is used for properties which accept string, but you want to dynamically assign the value of a field to that property. Let's say the name property of textfield, it takes a string. But suppose I want the name of the textfield to be decided upon the name of the category user is browsing (which is under an attribute cat), then I can do this



I hope this makes sense...
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your example uses the wrong character, and in fact won't work after ~S2.0.9ish when we started disallowing JSP EL in the S2 tags due to a potential security issue.

The "%{}" syntax is the OGNL escape sequence: for most attributes it forces evaluation of the contents as an OGNL expression.
 
Ankit Garg
Sheriff
Posts: 9510
22
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
David Newton wrote:Your example uses the wrong character


I typed that in a hurry. This would be the correct example

 
James Hollier
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is there an expression syntax to support invoking getCat("aaa") in this case...something like %{cat['aaa']}

Or is it NOT passible in OGNL to indicate parameters to pass?

Thanks,
J
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please start new threads for new questions.

OGNL allows arbitrary method invocation with parameters.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic