how to ren开发者_如何转开发der a datatable based on the list size in jsf using java EL?
Three ways:
Add an extra getter.
public int getSearchListSize() { return searchList.size(); }
with
<h:dataTable rendered="#{bean.searchListSize > 2}">
Use JSTL
fn:length()
function. Install JSTL if not done yet (just drop jstl-1.2.jar in/WEB-INF/lib
) and declarefn
taglib in top of JSP as follows:<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
and use it as follows:
<h:dataTable rendered="#{fn:length(bean.searchList) > 2}">
Use JBoss EL ("enhanced EL") as JSF EL implementation instead. It's backwards compatible with standard JSF EL implementation. Drop jboss-el.jar in
/WEB-INF/lib
and declare the following inweb.xml
, assuming you're using Mojarra JSF implementation:<context-param> <param-name>com.sun.faces.expressionFactory</param-name> <param-value>org.jboss.el.ExpressionFactoryImpl</param-value> </context-param>
This way you can access non-getter methods directly:
<h:dataTable rendered="#{bean.searchList.size() > 2}">
精彩评论