Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jsf-2/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
复合和cc之间的JSF2差异_Jsf_Jsf 2_Composite Component - Fatal编程技术网

复合和cc之间的JSF2差异

复合和cc之间的JSF2差异,jsf,jsf-2,composite-component,Jsf,Jsf 2,Composite Component,我试图创建一个基于的复合组件。 我无法从支持组件获取属性或任何值。代码: <?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/

我试图创建一个基于的复合组件。 我无法从支持组件获取属性或任何值。代码:

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:c="http://java.sun.com/jsp/jstl/core"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:p="http://primefaces.org/ui"
    xmlns:composite="http://java.sun.com/jsf/composite">

<composite:interface componentType="test">
    <composite:attribute name="something" />
</composite:interface>

<composite:implementation>
    <h:outputText value="#{composite.attrs.something}" />
    <h:outputText value="#{composite.hello}" />
</composite:implementation>
</html>

我发现相同的代码可以工作,然后我使用“cc”名称空间而不是“composite”。代码:


问题是,为什么它不使用“复合”名称空间? 我找不到任何关于“composite”是JSF保留字之类的信息


谢谢。

您把XML名称空间和XML名称空间搞混了。
{cc}
中的
cc
没有引用当前正在使用的复合组件XML命名空间。它只是引用EL范围中的复合组件实例,是一个固定名称。这个构造在
composite
XML名称空间中同样有效

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:c="http://java.sun.com/jsp/jstl/core"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:p="http://primefaces.org/ui"
    xmlns:composite="http://java.sun.com/jsf/composite">

<composite:interface componentType="test">
    <composite:attribute name="something" />
</composite:interface>

<composite:implementation>
    <h:outputText value="#{cc.attrs.something}" />
    <h:outputText value="#{cc.hello}" />
</composite:implementation>
</html>

(注意:我宁愿使用
而不是
,就像你在那里链接的博客文章一样)


至于XML名称空间,
composite
太长了,不适合所有其他缩写的XML名称空间,如
h
f
c
,等等。这就是为什么许多开发人员选择使用
cc
而不是JSF本身使用的
composite
。请注意,复合标记文档本身也使用
{cc}
贯穿于
composite
XML名称空间的示例中。

哦,我明白了。谢谢你的解释。你是我们的JSF英雄;)。也谢谢你的留言。
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:c="http://java.sun.com/jsp/jstl/core"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:p="http://primefaces.org/ui"
    xmlns:composite="http://java.sun.com/jsf/composite">

<composite:interface componentType="test">
    <composite:attribute name="something" />
</composite:interface>

<composite:implementation>
    <h:outputText value="#{cc.attrs.something}" />
    <h:outputText value="#{cc.hello}" />
</composite:implementation>
</html>