6. Building a view: tags Flashcards

1
Q

What data objects are available to be targeted with OGNL? Think what’s in an ActionContext.

A

ValueStack, parameters, application, session, attr, request

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What’s the default data object OGNL will resolve against?

A

ValueStack

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

How do you have OGNL resolve against a different object?

A

Use the #object[‘property’] syntax.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What are the 4 categories of Struts 2 tags?

A
  1. Data Tags
  2. Control-Flow Tags
  3. UI Tags
  4. Miscellaneous Tags
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What function do Data Tags perform?

A

Extracting data from the ValueStack and/or setting values in the ValueStack.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What functions do Control-flow tags perform?

A

Allows you to test values on the ValueStack to conditionally alter the flow of the rendering process.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What’s the syntax for including Struts 2 tags into a JSP page?

A

taglib prefix=”s” uri=”/struts-tags”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is the property tag used for? What’s the syntax for it?

A

For using OGNL to display value from ValueStack on the page.

s:property value=”OGNL Expression” default=”If null, show instead” escape=”True”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Assume image is true, value isn’t on ValueStack. What happens?

A

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 well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

How could you modify this code so that the default attribute pulls ‘myDefaultString’ from the ValueStack INSTEAD of using the string literal?

A

Important note is the %{expression} syntax.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is the set tags prupose? What are the attributes available?

A

Assigning a property to another name. You could use this to basically alias to a deeper, tougher to type out OGNL expression.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is the push tags prupose? What are the attributes available?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is the bean tags purpose? What are the attributes available?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

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

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What is the action tags purpose? What are the attributes available?

A

Allows us to invoke another action from our view layer.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What is the iterator tags purpose? What are the attributes available?

A

Allows you to loop over collections or objects easily!

17
Q

What methods are available on the IteratorStatus object?

A
18
Q

What is the if/else tags purpose? What are the attributes available?

A

Controls flow of tags. You can use if/elseif/else.

19
Q

What is the include tags purpose? What are the attributes available?

A

You can use it to include the output of another web resource in the currently rendering page. IMPORTANT: Can include ANY servlet resource.

20
Q

What is the url tags purpose? What are the most important attributes?

A

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)

21
Q

What’s the OGNL expression for filtering a list of users whos age is greater than 30?

A

users.{?#this.age > 30}

Notice the {? } is the filter expression. #this is reference THIS user object being evaluated.

22
Q

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

A

users.{username}