This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Struts and the fly likes struts2 tag Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "struts2 tag" Watch "struts2 tag" New topic
Author

struts2 tag

gurneeraj singh
Ranch Hand

Joined: Mar 19, 2008
Posts: 80
What is the use of label="%{ example}" in defining struts2 tag when we can use this directly label="example" with the help of OGNL?


SCJP 5.0 93%<br /> <br />SCWCD 5.0 97 %
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9291
    
  17

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...


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

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

Joined: Aug 03, 2008
Posts: 9291
    
  17

David Newton wrote:Your example uses the wrong character


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

James Hollier
Greenhorn

Joined: Jul 27, 2009
Posts: 19
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

Joined: Sep 29, 2008
Posts: 12617

Please start new threads for new questions.

OGNL allows arbitrary method invocation with parameters.
 
 
subject: struts2 tag
 
Similar Threads
struts2
Struts2
Struts2 questions
Passing a bean:message as string to a custom tag?(Struts2)
Struts2 valuestack error