Facelet自定义标签的参数化
我创建了 Facelet 模板:
left-right.xhtml
<ui:composition>
<ui:include name="left" />
<hr />
<ui:include name="right" />
</ui:composition>
之后,如果我将此模板与 ui:decorate 一起使用,它可以正常工作:
index.xhtml
<ui:decorate template="left-right.xhtml">
<ui:define name="left">FOO</ui:define>
<ui:define name="right">BAR</ui:define>
</ui:decorate>
但是,如果我使用此模板作为自定义 Facelet 标记,它不会作品。
custom-taglib.xml
<facelet-taglib>
<tag>
<tag-name>leftright</tag-name>
<source>left-right.xhtml</source>
</tag>
</facelet-taglib>
index.xhtml
<custom:leftright>
<ui:define name="left">FOO</ui:define>
<ui:define name="right">BAR</ui:define>
</custom:leftright>
ui:define 标签内的内容未包含在模板中:(
所以,问题是如果 Facelet 模板呈现为 Facelet 自定义标签,我如何参数化它?
I have created facelet template:
left-right.xhtml
<ui:composition>
<ui:include name="left" />
<hr />
<ui:include name="right" />
</ui:composition>
After, if I use this template with ui:decorate it works fine:
index.xhtml
<ui:decorate template="left-right.xhtml">
<ui:define name="left">FOO</ui:define>
<ui:define name="right">BAR</ui:define>
</ui:decorate>
BUT, if I use this template as custom facelet tag it does not works.
custom-taglib.xml
<facelet-taglib>
<tag>
<tag-name>leftright</tag-name>
<source>left-right.xhtml</source>
</tag>
</facelet-taglib>
index.xhtml
<custom:leftright>
<ui:define name="left">FOO</ui:define>
<ui:define name="right">BAR</ui:define>
</custom:leftright>
The content inside ui:define tags is not included into template :(
So, question is how can I parameterise facelet template if it renders as facelet custom tag?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
(请注意,您的
left-right.xhtml
中存在语法错误,您应该使用
而不是< ui:include>
,但我认为这只是粗心的过度简化)标签文件不能被视为模板客户端。您需要根据具体的功能需求以不同的方式处理它。如果您使用的是 JSF 2.x,那么 复合组件 将是您需要的最接近的组件。您可以将这些部分定义为
并在复合实现中通过
渲染它们。例如
/resources/custom/leftRight.xhtml
用法:
但是如果您仍然使用 JSF 1.x,则无法创建复合组件。您需要坚持
。另请参阅:
(note that you have a syntax error in your
left-right.xhtml
, you should be using<ui:insert>
instead of<ui:include>
, but I'll assume it to be just careless oversimplification)A tag file cannot be treated as a template client. You need to approach it differently depending on the concrete functional requirement. If you're on JSF 2.x, then a composite component would be the closest which you need. You could define the parts as
<f:facet>
and render them by<cc:renderFacet>
in the composite implementation.E.g.
/resources/custom/leftRight.xhtml
Usage:
But if you're still on JSF 1.x, you cannot create a composite component. You'd need to stick to
<ui:decorate>
.See also: