Say I have a file index.xhtml
, how can I dynamically create subpages for it like index.xhtml?id=1
. And is there any way to grab this id=1
with some actions in this page?
-
1@JeffNoel a suggestion that can't be applied isn't a suggestion. – Luiggi Mendoza Jul 24 '13 at 20:09
1 Answers
That's why <f:viewParam>
tag exists in JSF. It allows you to get the query parameter(s): those after ?
and separated with &
, and use it in your view directly, or set it as a model property, convert/validate it, etc.
But you're getting its meaning the wrong way. It is not used to create 'many (sub)pages', but to pass information to the view, so that view could be dynamic, meaning that rendered information will be derived basing on those view parameters (i.e. showing user with a certain id). It also thus allows to create bookmarkable URLs.
Its usage is basically as follows:
<f:metadata>
<f:viewParam name="id" value="#{yourBean.userId}" />
</f:metadata>
This will preset the given property of your bean with the parameter passed to the view as query parameter.
You can find more information in answer to What can <f:metadata>
and <f:viewParam>
be used for?.