我需要呈现一个可扩展的列表,它最初显示大约6-8个项目列表,但单击'Show all'
时应该会显示整个项目列表。
脑海中没有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;
}
}
如果有必要,你可以把它包在复合材料里。