]
Lukáš Fryč updated RF-12231:
----------------------------
Priority: Critical (was: Major)
[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
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: