Facelet 自定义组件 - 阻止渲染
阅读这个答案后,我仍然难住了。我同意应该避免使用 JSTL,并了解它的评估是如何在错误的阶段发生的。但是,根据facelets上的文档开发网站上,
标签似乎只支持两个属性,id
和 binding
。因此,即使某些实现支持渲染,您似乎也会试图利用它。另一个建议是使用
,但是,它会在响应中插入
元素,这可能会导致不良的副作用(例如更改您的内容从内联到块)。有谁知道解决这个问题的方法吗?特别是,我正在尝试以下操作:<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns:ice="http://www.icesoft.com/icefaces/component"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets">
<ui:composition>
<ice:selectOneListbox binding="#{binding}" rendered="#{modeExisting}">
<f:selectItems
value="#{binding.allTagsSelectItems}" />
</ice:selectOneListbox>
<ice:inputText binding="#{binding.name}" />
<ice:inputText binding="#{binding.description}" />
</ui:composition>
</html>
这基本上是一个列表框,用于选择具有名称和描述的元素,选择该元素后将允许用户编辑它们。我可以在块周围放置一个
,并使用它的渲染属性,但同样,注入额外的 div 可能会产生副作用。有什么办法可以让这个工作吗?
另外,可能值得一提的是,我正在使用上面的自定义组件与这个facelet-taglib配对:
<?xml version="1.0"?>
<!DOCTYPE facelet-taglib PUBLIC
"-//Sun Microsystems, Inc.//DTD Facelet Taglib 1.0//EN"
"http://java.sun.com/dtd/facelet-taglib_1_0.dtd">
<facelet-taglib>
<namespace>http://www.mitre.org/asias/jsf</namespace>
<tag>
<tag-name>configurationTagEditor</tag-name>
<source>../component/configurationTagEditor.xhtml</source>
</tag>
<tag>
<tag-name>configurationTagSelector</tag-name>
<source>../component/configurationTagSelector.xhtml</source>
</tag>
<tag>
<tag-name>configurationTagRegexTable</tag-name>
<source>../component/configurationTagRegexTable.xhtml</source>
</tag>
</facelet-taglib>
为了允许我在我的jsf xhtml中使用它:
...
<ice:panelTab label="Existing" styleClass="configurationTagsExisting">
<m:configurationTagEditor tag="#{configuration.existingTag}" />
</ice:panelTab>
...
After reading this answer, I am still stumped. I agree that JSTL should be avoided and understand how its evaluation occurs in the wrong phase. However, per the documentation on the facelets development site, it appears that <ui:fragment>
tags only supports two attributes, id
and binding
. So, even if some implementation support rendered
, it seems like you would be tempting fate to make use of it. The other suggestion was to use <h:panelGroup>
, however, that inserts a <div>
element in the response which could cause undesirable side effects (like changing your content from inline to block). Does anyone know a way around this? In particular, I am attempting the following:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns:ice="http://www.icesoft.com/icefaces/component"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets">
<ui:composition>
<ice:selectOneListbox binding="#{binding}" rendered="#{modeExisting}">
<f:selectItems
value="#{binding.allTagsSelectItems}" />
</ice:selectOneListbox>
<ice:inputText binding="#{binding.name}" />
<ice:inputText binding="#{binding.description}" />
</ui:composition>
</html>
Which is basically a listbox used to select an element with a name and description which when selected will allow the user to edit them. I could put an <ice:panelGroup>
around the block, and use the rendered attribute of it, but again, there could be side effects of injecting that additional div. Is there any way to make this work?
Also, it may be worth mentioning that I am using the above custom component paired with this facelet-taglib:
<?xml version="1.0"?>
<!DOCTYPE facelet-taglib PUBLIC
"-//Sun Microsystems, Inc.//DTD Facelet Taglib 1.0//EN"
"http://java.sun.com/dtd/facelet-taglib_1_0.dtd">
<facelet-taglib>
<namespace>http://www.mitre.org/asias/jsf</namespace>
<tag>
<tag-name>configurationTagEditor</tag-name>
<source>../component/configurationTagEditor.xhtml</source>
</tag>
<tag>
<tag-name>configurationTagSelector</tag-name>
<source>../component/configurationTagSelector.xhtml</source>
</tag>
<tag>
<tag-name>configurationTagRegexTable</tag-name>
<source>../component/configurationTagRegexTable.xhtml</source>
</tag>
</facelet-taglib>
To allow me to use this in my jsf xhtml:
...
<ice:panelTab label="Existing" styleClass="configurationTagsExisting">
<m:configurationTagEditor tag="#{configuration.existingTag}" />
</ice:panelTab>
...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
>默认情况下不渲染
。仅当您添加
layout="block"
时才会呈现。对于所有其他 HTML 属性(例如id
、styleClass
等),它仅呈现。如果没有
layout
属性存在并且所有其他 HTML 属性都不存在,则它不会呈现任何内容。The
<h:panelGroup>
doesn't render a<div>
by default. It only renders that if you addlayout="block"
. For all other HTML attributes (likeid
,styleClass
, etc), it only renders a<span>
. If nolayout
attribute is present and all other HTML attributes are absent, it renders nothing.