Java Spring Multiple Choice Questions & Answers (MCQs) on “Custom Layouts,Tags and Templates”.
1. A Grails view can contain:-
a) HTML Tags
b) GSP or JSTL Tags
c) Groovy or Java code
d) All of the mentioned
Answer: d
Clarification: A Grails view can contain display elements (e.g., HTML tags), business logic elements (e.g., GSP or JSTL tags) or straightforward Groovy or Java code to achieve its display objectives.
2. A view can require a unique combination of display elements and business logic.
a) True
b) False
Answer: a
Clarification: To simplify the inclusion of such a combination and facilitate its reuse in multiple views a custom tag can be used.
3. To create custom tags.
a) grails create tag
b) grails create-tag-lib tag-lib-name
c) all of the mentioned
d) none of the mentioned
Answer: b
Clarification: To create custom tags, you can use the grails create-tag-lib tag-lib-name command.
4. grails create-tag-lib tag-lib-name command creates a custom tag library under:-
a) /grails-app/tag/
b) /grails-app/
c) /grails-app/tag-lib/
d) none of the mentioned
Answer: c
Clarification: This command creates a skeleton class for a custom tag library under an application’s /grails-app/tag-lib/ directory.
5. In order for this custom tag to function properly in JSP, it’s necessary to add it to the corresponding Tag Library Definition (TLD) grails.tld.
a) True
b) False
Answer: a
Clarification: TLDs are located in an application’s /web-app/WEB-INF/tld/ directory.
6. Custom tags can also rely on input parameters.
a) True
b) False
Answer: a
Clarification: Custom tags can also rely on input parameters passed in as tag attributes to perform a backing class’s logic.
7. By default, Grails assigns custom tags to:-
a) g: namespace
b) f: namespace
c) j: namespace
d) all of the mentioned
Answer: a
Clarification: Finally, a word about the namespace used in Grails custom tags—by default, Grails assigns custom tags to the g: namespace.
8. By default, Grails applies a global layout to display an application’s content.
a) True
b) False
Answer: a
Clarification: This allows views to have a minimal set of display elements (e.g., HTML, CSS, and JavaScript) and inherit their layout behavior from a separate location.
9. Grails doesn’t supports the concept of templates.
a) True
b) False
Answer: b
Clarification: Grails also supports the concept of templates, which serve the same purpose as layouts, except applied at a more granular level. In addition, it’s also possible to use templates for rendering a controller’s output, instead of a view as in most controllers.
10. Where is subdirectory called layouts located, containing the layouts available to an application?
a) /grails-app/view/
b) /grails-app/
c) /grails-app/view/WEB-INF
d) none of the mentioned
Answer: a
Clarification: Inside the /grails-app/view/ directory of an application, you can find a subdirectory called layouts, containing the layouts available to an application.
11. Tag is used to define the contents of a layout’s title section.
a) g:layoutTitle
b) g:layoutHead
c) g:layoutBody
d) g:layoutMeta
Answer: a
Clarification: The g:layoutTitle tag is used to define the contents of a layout’s title section.
12. Tag is used to define the contents of a layout’s head section.
a) g:layoutTitle
b) g:layoutHead
c) g:layoutBody
d) g:layoutMeta
Answer: b
Clarification: Any values declared in the head of a view head inheriting this layout are placed in this location upon rendering.
13. Tag allows any view inheriting this layout automatic access to JavaScript libraries.
a) g:javascript library=”application”
b) g:layoutHead
c) g:layoutBody
d) g:layoutMeta
Answer: a
Clarification: Upon rendering, this element is transformed into the following: script type=”text/javascript” src=”/court/js/application.js” /script.
14. A view’s body content is inside the:-
a) g:javascript library=”application”
b) g:layoutHead
c) g:layoutBody
d) g:layoutMeta
Answer: c
Clarification: Grails automatically sorts out the substitution process by placing a view’s title content inside the g:layoutTitle tag, a view’s body content inside the g:layoutBody / tag, and so on.
15. GORM dynamic finder comparators:-
a) InList
b) LessThan
c) LessThanEquals
d) All of the mentioned
Answer: d
Clarification: GORM comparator Query
InList If value is present in a given list of values
LessThan For lesser object(s) than the given value
LessThanEquals For lesser or equal object(s) than the given value
GreaterThan For greater object(s) than the given value
GreaterThanEquals For greater or equal object(s) than the given value
Like For object(s) like the given value
Ilike For object(s) like the given value in a case insensitive manner
NotEqual For object(s) not equal to the given value
Between For object(s) between to the two given values
IsNotNull For not null object(s); uses no arguments
IsNull For null object(s); uses no arguments