1Z0-900 · Question #10
Given the code fragment from a Facelet page: On Line 1, you ae asked to insert a search box that displays the text "Search Here" via a placeholder. Assume searchMB is a valid Managed Bean. Which two…
Options C and D are correct. D works because the pt: prefix is the JSF pass-through attributes namespace (xmlns:pt="http://xmlns.jcp.org/jsf/passthrough"), which explicitly tells JSF to render any prefixed attribute as a native HTML attribute on the output element - making…
Question
Given the code fragment from a Facelet page:
On Line 1, you ae asked to insert a search box that displays the text “Search Here” via a placeholder. Assume searchMB is a valid Managed Bean. Which two options enable you to create a search box with a placeholder attribute on Line 1? (Choose two.) A. <h:inputText value=“#(searchMB.query)”><f:param name=“placeholder” value=“Search Here”/></h:inputText>
Exhibit
Options
- B<h:inputText value="#(searchMB.query)" placeholder="Search here"/>
- C<input jsf:id="search" placeholder="Search here" jsf:value="# (searchMB.query)"></input>
- D<h:inputText pt:placeholder="Search Here" value="#(searchMB.query)"/>
- E<input id="search" jsf:placeholder="Search Here" value="$(searchMB.query)"></input>
Explanation
Options C and D are correct.
D works because the pt: prefix is the JSF pass-through attributes namespace (xmlns:pt="http://xmlns.jcp.org/jsf/passthrough"), which explicitly tells JSF to render any prefixed attribute as a native HTML attribute on the output element - making pt:placeholder appear as placeholder in the final HTML. C works because it uses a JSF pass-through element: a plain HTML <input> tag gains JSF component behavior via the jsf: namespace (e.g., jsf:id, jsf:value), while non-prefixed attributes like placeholder are rendered as-is, giving you full HTML5 attribute support.
A is wrong because <f:param> injects URL query parameters, not HTML element attributes. B is wrong because JSF component tags like <h:inputText> only recognize their own declared attributes; arbitrary HTML attributes like placeholder are silently ignored and not passed through to the rendered HTML. E is wrong for two reasons: jsf:placeholder is not valid (the jsf: namespace is for component bindings like jsf:value/jsf:id, not HTML attributes), and it uses the invalid $() EL syntax instead of #{}.
Memory tip: When you need to add HTML5 attributes to JSF components, remember "PT = Pass-Through" - either use pt:attribute on JSF tags, or write plain HTML tags with jsf: bindings and drop native HTML attributes directly.
Topics
Community Discussion
No community discussion yet for this question.
