[richfaces-issues] [JBoss JIRA] (RF-12231) [CDK] EL empty method doesn't work for Collection

Lukáš Fryč (JIRA) jira-events at lists.jboss.org
Mon May 28 10:17:18 EDT 2012


     [ https://issues.jboss.org/browse/RF-12231?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Lukáš Fryč resolved RF-12231.
-----------------------------

      Assignee: Lukáš Fryč
    Resolution: Done

    
> [CDK] EL empty method doesn't work for Collection
> -------------------------------------------------
>
>                 Key: RF-12231
>                 URL: https://issues.jboss.org/browse/RF-12231
>             Project: RichFaces
>          Issue Type: Bug
>      Security Level: Public(Everyone can see) 
>          Components: cdk
>    Affects Versions: 4.2.1.Final
>         Environment: All
>            Reporter: Paul Dijou
>            Assignee: Lukáš Fryč
>            Priority: Critical
>              Labels: cdk, richfaces
>             Fix For: 4.3.0.Milestone1
>
>
> Let's say I want to test if a component doesn't have any children. I write thise code :
> {code:xml}
> <c:if test="#{empty(component.getChildren())}">No children!</c:if>
> {code}
> Seems logic, right? If the List is empty, then it means there is no children. The generated Java code is the following :
> {code:java}
> if (isEmpty(component.getChildren())) {
>     responseWriter.writeText("No children!",null);
> }
> {code}
> And the "isEmpty" method :
> {code:java}
> private static boolean isEmpty(Object object) 
> {
>     return object == null || object.toString().length() == 0;
> }
> {code}
> This method will *always* returns {{false}}, even if the list is empty. Why? Because the list will not be null and an empty list toString() renders "{{[]}}", so "{{object.toString().length()}}" will be eval to "2", which is different from "0". So based on these test, the component will *always* have children.
> The "isEmpty" method should adapt its test depending on the type of object. It's an instance of Collection, calling "isEmpty()" is probably better.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.jboss.org/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

       



More information about the richfaces-issues mailing list