我试图实现一个复合组件,它以纯文本形式显示用户的信息详细信息,或者通过可编辑的输入文本字段显示它们,如果所需的详细信息是当前连接用户的详细信息.
我知道,可以通过渲染属性渲染al UI组件,但是那些不是UI组件(例如div)的UI组件
<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>
解决方法
正确的JSF组件来表示HTML< div>元素是< h:panelGroup>将layout属性设置为block.所以,这应该做:
<h:panelGroup layout="block" ... rendered="#{someCondition}"> ... </h:panelGroup>
或者,将其包装在< ui:fragment> ;::::
<ui:fragment rendered="#{someCondition}"> <div> ... </div> </ui:fragment>
请注意,当您想要ajax更新有条件渲染的组件时,您应该ajax更新其父组件.
也可以看看:
> Alternative to ui:fragment in JSF
> Conditional rendering of non-JSF components (plain vanilla HTML and template text)
> Ajax update/render does not work on a component which has rendered attribute
> Why do I need to nest a component with rendered=”#{some}” in another component when I want to ajax-update it?