我正在尝试实现一个复合组件,它或者以纯文本显示用户的信息详细信息,或者如果所需的详细信息是当前连接的用户的详细信息,则通过可编辑的输入文本字段显示它们。
我知道所有的UI组件都可以通过rendered属性来呈现,但是那些不是UI组件的组件(例如div)呢?
<div class = "userDetails" rendered = "#{cc.attrs.value.id != sessionController.authUser.id}">
Name: #{cc.attrs.value.name}
Details: #{cc.attrs.value.details}
</div>
<div class = "userDetails" rendered = "#{cc.attrs.value.id == sessionController.authUser.id}">
<h:form>
...
</h:form>
</div>
我知道div没有呈现属性,可能我根本没有采取正确的方法。我可以很容易地使用JSTL标记,但我想避免这种情况。
发布于 2016-04-02 10:47:21
从JSF 2.2开始,这就变得很简单。通过使用传递元素,任何HTML元素都可以转换为具有呈现属性的JSF组件。
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:jsf="http://xmlns.jcp.org/jsf">
<div class="userDetails" jsf:rendered="#{cc.attrs.value.id != sessionController.authUser.id}">
Name: #{cc.attrs.value.name}
Details: #{cc.attrs.value.details}
</div>
</html>
有关更多信息,请访问https://jsflive.wordpress.com/2013/08/08/jsf22-html5/#elements
发布于 2012-01-11 17:21:23
我只想用<h:panelGroup>
包装你的超文本标记语言
<h:panelGroup rendered = "#{cc.attrs.value.id != sessionController.authUser.id}">
<div class = "userDetails">
Name: #{cc.attrs.value.name}
Details: #{cc.attrs.value.details}
</div>
</h:panelGroup>
<h:panelGroup rendered = "#{cc.attrs.value.id == sessionController.authUser.id}">
<div class = "userDetails">
<h:form>
...
</h:form>
</div>
</h:panelGroup>
另一个选择是使用Seam (<s:div>
)或Tomahawk (<t:htmlTag>
)库中的组件,如果您的项目中已经有这些组件的话。
请参阅:http://www.jsftoolbox.com/documentation/seam/09-TagReference/seam-div.html
<s:div styleClass = "userDetails" rendered = "#{cc.attrs.value.id != sessionController.authUser.id}">
Name: #{cc.attrs.value.name}
Details: #{cc.attrs.value.details}
</s:div>
<s:div styleClass = "userDetails" rendered = "#{cc.attrs.value.id == sessionController.authUser.id}">
<h:form>
...
</h:form>
</s:div>
或者:http://myfaces.apache.org/tomahawk-project/tomahawk12/tagdoc/t_htmlTag.html
<t:htmlTag value="div" styleClass = "userDetails" rendered = "#{cc.attrs.value.id != sessionController.authUser.id}">
Name: #{cc.attrs.value.name}
Details: #{cc.attrs.value.details}
</t:htmlTag>
<t:htmlTag value="div" styleClass = "userDetails" rendered = "#{cc.attrs.value.id == sessionController.authUser.id}">
<h:form>
...
</h:form>
</t:htmlTag>
发布于 2015-06-16 07:41:53
您可以使用另一个复合组件。没有div或其他额外的标记,正是您需要的。请参阅此示例:
<table>
<tr>...</tr>
<my:cc rendered="false">
<tr>...</tr>
</my:cc>
<my:cc rendered="true">
<tr>...</tr>
</my:cc>
</table>
和my:cc组件:
<?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:cc="http://xmlns.jcp.org/jsf/composite">
<cc:interface>
</cc:interface>
<cc:implementation>
<cc:insertChildren />
</cc:implementation>
</html>
生成下面的HTML,根本不需要额外的标签,使用ajax。
<table><tr>...</tr><tr>...</tr></table>
https://stackoverflow.com/questions/8816212
复制相似问题