我需要渲染一个可展开的列表,它最初显示大约6-8个项目列表,但在单击'Show all'时,它应该显示整个项目列表。
发布于 2011-06-11 00:43:17
没有PrimeFaces组件出现在我的脑海中,但是仅仅是这样呢?
<h:form>
<ul>
<ui:repeat value="#{bean.list}" var="item" varStatus="loop">
<ui:fragment rendered="#{loop.index lt 6 or bean.showAll}">
<li>#{item}</li>
</ui:fragment>
</ui:repeat>
</ul>
<h:commandButton value="Show all" action="#{bean.setShowAll(true)}" rendered="#{!bean.showAll}">
<f:ajax render="@form" />
</h:commandButton>
</h:form>使用
@ManagedBean
@ViewScoped
public class Bean implements Serializable {
private List<String> list = Arrays.asList("one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten");
private boolean showAll;
public List<String> getList() {
return list;
}
public boolean isShowAll() {
return showAll;
}
public void setShowAll(boolean showAll) {
this.showAll = showAll;
}
}如有必要,您可以将其包装在复合组件中。
https://stackoverflow.com/questions/6309229
复制相似问题