gpt4 book ai didi

jsf - #{resource} EL 在哪里指定?

转载 作者:行者123 更新时间:2023-12-04 14:08:16 25 4
gpt4 key购买 nike

在 JSF 页面中,我使用 EL 来定位放置在 /resource/images/ 文件夹中的图像。

<h:graphicImage value="#{resource['images:logo.gif']}"

EL如何定位图像?也许一个规范定义了规则,但我不知道是哪个规范。我试图在 JSR-000344 JavaServer Faces 2.2 中找到它,JSR-000342 Java Platform, Enterprise Edition 7 , JSR-000341 Expression Language 3.0 , 但未找到。

最佳答案

JSF 2.0 specification , 在 2.6.2 章节中首次提到:

2.6.2 Rendering Resources

Resources such as images, stylesheets and scripts use the resource handling mechanism as outlined in Section 2.6.1 “Packaging Resources”. So, for example:

<h:graphicImage name=”Planets.gif” library=”images”/>
<h:graphicImage value=”#{resource[‘images:Planets.gif’]}”/>

These entries render exactly the same markup. In addition to using the name and library attributes, stylesheet and script resources can be “relocated” to other parts of the view. For example, we could specify that a script resource be rendered within an HTML “head”, “body” or “form” element in the page.

然后在第 5.6.2.5 章中:

5.6.2.5 Resource ELResolver

This resolver is a means by which Resource instances are encoded into a faces request such that a subsequent faces resource request from the browser can be satisfied using the ResourceHandler as described in Section 2.6 “Resource Handling”.

ELResolver method implementation requirements

If base and property are not null, and base is an instance of ResourceHandler (as will be the case with an expression such as #{resource[‘ajax.js’]}, perform the following. (Note: This is possible due to the ImplicitObjectELResolver returning the ResourceHandler, see Section 5.6.2.1 “Implicit Object ELResolver for Facelets and Programmatic Access”)

  • If property does not contain a colon character ‘:’, treat property as the resourceName and pass property to ResourceHandler.createResource(resourceName).
  • If property contains a single colon character ‘:’, treat the content before the ‘:’ as the libraryName and the content after the ‘:’ as the resourceName and pass both to ResourceHandler.createResource(resourceName, libraryName)
  • If property contains more than one colon character ‘:’, throw a localized ELException, including property.

If one of the above steps results in the creation of a non-null Resource instance, call ELContext.setPropertyResolved(true) and return the result of calling the getRequestPath() method on the Resource instance.

它也在 JSF 2.1 和 2.2 规范的相同章节中提到。

与具体问题无关images 是资源库名称的一个非常糟糕的例子。不要从规范示例中接管它。

另见:

关于jsf - #{resource} EL 在哪里指定?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34446178/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com