嗨,我试图在JSF中显示树结构
为了打算我想插入
<span class="intendWidth" />
Run Code Online (Sandbox Code Playgroud)
这是我的jsf代码
<ui:repeat value="#{myHandler.entityTree}" var="entityDepthHolder">
<p:commandLink action="#{myHandler.toggle(entityDepthHolder.entity)}">
<div>
<c:forEach begin="0" end="#{entityDepthHolder.depth}">
<span class="intendWidth" />
</c:forEach>
#{entityDepthHolder.depth} #{entityDepthHolder.entity.title}
</div>
</p:commandLink>
</ui:repeat>
Run Code Online (Sandbox Code Playgroud)
但由于某种原因,c:forEach总是运行一次,虽然只有一个entityDepthHolder.depth是1,其他所有都是0
任何想法如何在没有c:forEach的情况下插入标签n次?
的<c:forEach>期间视图编译时间运行(当XHTML变成JSF组件树那一刻),而<ui:repeat>图中运行渲染时间(当JSF组件树产生HTML输出力矩).
因此,当<c:forEach>运行时,#{entityDepthHolder}EL范围中无处可用null并且在此情况下进行求值并隐式强制执行0.由于begin也0和end包容,您可以有效地结束了1项.
在视图构建时间之后,JSF组件树最终会像这样:
<ui:repeat value="#{myHandler.entityTree}" var="entityDepthHolder">
<p:commandLink action="#{myHandler.toggle(entityDepthHolder.entity)}">
<div>
<span class="intendWidth" />
#{entityDepthHolder.depth} #{entityDepthHolder.entity.title}
</div>
</p:commandLink>
</ui:repeat>
Run Code Online (Sandbox Code Playgroud)
在视图渲染时,重复生成相同的HTML.
你有2个选项来解决这个问题:
使用<c:forEach>而不是<ui:repeat>外循环.警告是,这打破了早于2.1.18的Mojarra版本中的视图范围豆.
使用<ui:repeat>而不是<c:forEach>内循环.如果您碰巧使用JSF实用程序库OmniFaces,那么您可能会发现此#{of:createArray()}功能很有用.
<ui:repeat value="#{of:createArray(entityDepthHolder.depth)}">
Run Code Online (Sandbox Code Playgroud)| 归档时间: |
|
| 查看次数: |
279 次 |
| 最近记录: |