[richfaces-issues] [JBoss JIRA] (RF-12231) [CDK] EL empty method doesn't work for Collection
Lukáš Fryč (JIRA)
jira-events at lists.jboss.org
Wed May 16 10:29:21 EDT 2012
[ https://issues.jboss.org/browse/RF-12231?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12693320#comment-12693320 ]
Lukáš Fryč commented on RF-12231:
---------------------------------
Add support for java.util.Collection and arrays and java.util.Map.
> [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
> 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