使用 JSF2 资源有哪些好处?
我应该使用 JSF2 资源而不是像 或
url(image.png)
这样的纯 html 吗?有什么好处?对我来说,当网页设计师使用 XHTML、CSS 和所有这些东西创建布局时,这有点烦人,我需要花时间将纯 HTML 路径和标签替换为 JSF 资源标签,例如 #{resource[...] }
。
还有其他办法吗?喜欢将所有 CSS/图像文件放在 Web 根目录中并使用普通链接吗?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你的选择。
主要好处是您可以在每个组件的基础上声明它们。如果您无论如何都需要将它们包含在每个页面上,那么好处就很小了。但是,如果您需要在例如在单个视图中多次重用的复合组件中包含特定于组件的 CSS/JS 代码,那么例如 复合组件中的内容最终会出现在它被包括在内仅一次,而不是像使用
时那样多次使用复合组件。这同样适用于
@ResourceDependency
真实UIComponent< 上的注释/代码>
类。请注意,您并不需要仅使用 JSF2 资源。只是普通的
![]()
、、
等也完全没问题。它甚至可以指向 JSF 资源文件夹。
Your choice.
The major benefit is that you can declare them on a per-component basis. If you need to include them on every single page anyway, then the benefit is little. But if you need to include component-specific CSS/JS code in for example a composite component which is reused more than once in a single view, then for example an
<h:outputScript>
in a composite component would end up in it being included only once instead of that many times as the composite component is been used as would happen with<script>
. The same applies to the@ResourceDependency
annotation on realUIComponent
classes.Please note that you are not required to use JSF2 resources only. Just plain vanilla
<img>
,<link>
,<script>
, etc is also perfectly fine. It can even point to the JSF resources folder.