6. Building a view: tags Flashcards
What data objects are available to be targeted with OGNL? Think what’s in an ActionContext.
ValueStack, parameters, application, session, attr, request

What’s the default data object OGNL will resolve against?
ValueStack
How do you have OGNL resolve against a different object?
Use the #object[‘property’] syntax.

What are the 4 categories of Struts 2 tags?
- Data Tags
- Control-Flow Tags
- UI Tags
- Miscellaneous Tags
What function do Data Tags perform?
Extracting data from the ValueStack and/or setting values in the ValueStack.
What functions do Control-flow tags perform?
Allows you to test values on the ValueStack to conditionally alter the flow of the rendering process.
What’s the syntax for including Struts 2 tags into a JSP page?
taglib prefix=”s” uri=”/struts-tags”

What is the property tag used for? What’s the syntax for it?
For using OGNL to display value from ValueStack on the page.

s:property value=”OGNL Expression” default=”If null, show instead” escape=”True”
Assume image is true, value isn’t on ValueStack. What happens?

Prints out:
nonExistingProperty on the ValueStack =
nonExisting Property on the ValueStack = doesNotExist
Important to note that the first one checks ValueStack, doesn’t find the value so NULL is returned. When NULL turned into a string it becomes empty string “”
How could you modify this code so that the default attribute pulls ‘myDefaultString’ from the ValueStack INSTEAD of using the string literal?

Important note is the %{expression} syntax.

What is the set tags prupose? What are the attributes available?
Assigning a property to another name. You could use this to basically alias to a deeper, tougher to type out OGNL expression.

What is the push tags prupose? What are the attributes available?
Allows you to push properties onto the ValueStack, useful for when you do a lot of work revolving around a single object, push the object and refer to the properties.

What is the bean tags purpose? What are the attributes available?
Hybrid of set/push tags except you don’t need to work with an existing object.
Object must conform to JavaBeans standards (zero-arg constructor, properties for fields you intend to intialize with param tags.

What syntax would you need to create a bean, pass a parameter to the bean, then invoke a function that outputs a message?

What is the action tags purpose? What are the attributes available?
Allows us to invoke another action from our view layer.

What is the iterator tags purpose? What are the attributes available?
Allows you to loop over collections or objects easily!

What methods are available on the IteratorStatus object?

What is the if/else tags purpose? What are the attributes available?
Controls flow of tags. You can use if/elseif/else.

What is the include tags purpose? What are the attributes available?
You can use it to include the output of another web resource in the currently rendering page. IMPORTANT: Can include ANY servlet resource.

What is the url tags purpose? What are the most important attributes?
Creating URLs, mapping to external or even Actions. Can even pass parameters as part of the URL generation.
–Attributes–
value – Base URL
action – Name of the action to target (no ‘.action’ extension)
What’s the OGNL expression for filtering a list of users whos age is greater than 30?
users.{?#this.age > 30}
Notice the {? } is the filter expression. #this is reference THIS user object being evaluated.

What’s the OGNL expression for projecting usernames from a collection of users objects?
users.{username}
