开发者

how to render a datatable based on a list size in jsf using java EL?

how to ren开发者_如何转开发der a datatable based on the list size in jsf using java EL?


Three ways:

  1. Add an extra getter.

    public int getSearchListSize() {
        return searchList.size();
    }
    

    with

    <h:dataTable rendered="#{bean.searchListSize > 2}">
    
  2. Use JSTL fn:length() function. Install JSTL if not done yet (just drop jstl-1.2.jar in /WEB-INF/lib) and declare fn 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}">
    
  3. 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 in web.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}">
    
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜