复合组件文件夹结构 [英] Composite component folder structure

查看:95
本文介绍了复合组件文件夹结构的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

JSF spec 2.2(2013-03-20)在项目10.3.3.1(声明要在Facelet页面中使用的复合组件库)中表示:

如果在XHTML页面中声明了facelet标记库,且命名空间以字符串开头 " http://java.sun.com/jsf/composite/"(不带引号),其余的名称空间声明 用作资源库的名称[...]

如果" http://java.sun.com/jsf/composite/"包含一个"/"字符,或者对于库名称不合法的任何字符,必须采取以下措施.如果application.getProjectStage()是Development,则必须在页面中放置一条提示性错误消息并进行记录.否则,该消息必须仅记录.

所以这意味着具有以下文件夹结构是非法的:

resources
    components
        system
        something_specific
        something_even_more_specific

并引用库名称" http://java.sun.com/jsf /composite/components/something_specific "?这是正确的吗?

这似乎是一个怪异的限制.我希望我的资源结构化,而不是一团糟.

这种分层库实际上可以在Wildfly 8.0.0.CR1中使用,但是我不确定依靠这种行为是否明智.

欢迎使用最佳做法"这类的答案.

解决方案

我将总结我的发现.

来源: JSF规范问题740 另一个讨论. net/jira/browse/JAVASERVERFACES_SPEC_PUBLIC-1141"rel =" nofollow> JSF规范问题1141 , org.apache.myfaces. STRICT_JSF_2_ALLOW_SLASH_LIBRARY_NAME ( MyFaces问题3454 ).我希望使用此设置依赖于名称带有斜杠的资源库,可能会破坏某些功能,例如JSF资源版本控制(它怎么知道哪个部分是库名称,哪个部分属于资源名称?).

我认为,可以通过将标签库中的组件一一导入来实现复合组件库层次结构:

<tag>
    <tag-name>test</tag-name>
    <component>
      <resource-id>
          components/system/test.xhtml
      </resource-id>
    </component>
</tag>

因此,库名称有效地变成了组件",而资源名称变成了"system/test.xhtml".

JSF spec 2.2 (2013-03-20) says in item 10.3.3.1 (Declaring a composite component library for use in a Facelet page):

If a facelet taglibrary is declared in an XHTML page with a namespace starting with the string "http://java.sun.com/jsf/composite/" (without the quotes), the remainder of the namespace declaration is taken as the name of a resource library [...]

If the substring following "http://java.sun.com/jsf/composite/" contains a "/" character, or any characters not legal for a library name the following action must be taken. If application.getProjectStage() is Development an informative error message must be placed in the page and also logged. Otherwise the message must be logged only.

So that means it's illegal to have the following folder structure:

resources
    components
        system
        something_specific
        something_even_more_specific

and refer to the library name "http://java.sun.com/jsf/composite/components/something_specific"? Is this correct?

That seems like a weird restriction. I want my sources structured, not mushed together in an enormous lump.

Such hierarchical library actually works in Wildfly 8.0.0.CR1, but I'm not sure if it's wise to rely on this behavior.

A "best practices" kind of answers are welcome.

解决方案

I'll summarize my findings.

Sources: JSF spec issue 740, discussion preceding issue 740, another discussion, JSF spec issue 1141, discussion preceding issue 1141.

Slash in a library name is disallowed. Slash in a resource name is allowed.

In practice on Mojarra 2.2.5 composite component library just works both in a XHTML namespace declaration, and in taglib's <composite-library-name>components/system</composite-library-name>. I expect that could still break in future Mojarra and/or JSF spec versions. If you use this, you're at JSF spec/impl developers' mercy. Linked issues and discussions have shown them to be willing to preserve backwards compatibility even for unintended features.

In MyFaces there is a special setting, org.apache.myfaces.STRICT_JSF_2_ALLOW_SLASH_LIBRARY_NAME (MyFaces issue 3454). I expect that relying on a resource library with slashes in its name, using this setting, could break some functionality such as JSF resource versioning (how can it know what part is a library name and what part belongs to resource name?).

I think composite component library hierarchy may be implemented by importing components in a taglib one by one:

<tag>
    <tag-name>test</tag-name>
    <component>
      <resource-id>
          components/system/test.xhtml
      </resource-id>
    </component>
</tag>

Thus the library name effectively becomes "components" and the resource name becomes "system/test.xhtml".

这篇关于复合组件文件夹结构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆