[英]How to create Facelets subpage
Say I have a file index.xhtml
, how can I dynamically create subpages for it like index.xhtml?id=1
. 假设我有一个文件
index.xhtml
,如何为它动态创建子页面,如index.xhtml?id=1
。 And is there any way to grab this id=1
with some actions in this page? 还有什么办法可以通过此页面中的某些操作来获取此
id=1
?
That's why <f:viewParam>
tag exists in JSF. 这就是
<f:viewParam>
标记存在于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 (ie showing user with a certain id).
它不是用来创建“许多(子)页面”的,而是用来将信息传递给视图的 ,因此视图可以是动态的,这意味着渲染的信息将基于这些视图参数(即显示具有特定id的用户)得出。 It also thus allows to create bookmarkable URLs.
因此,它还允许创建可添加书签的URL。
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. 这将使用传递给视图的参数作为查询参数来预置bean的给定属性。
You can find more information in answer to What can <f:metadata>
and <f:viewParam>
be used for? 您可以在
<f:metadata>
和<f:viewParam>
做什么用的答案中找到更多信息。 . 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.