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.