| `listprovider' tags
A list provider has a body which is evaluated repeatedly, it is mainly just an iterator tag.
When the list is acting as a contextwriter (if the 'id' parameter is specified), then the body
is still evaluated but within the body of the tag the variable refers to the current element. Then
after evaluation of the tag, the entire list of elements is available in the context with the
type 'java.util.List'.
The attributes to tags of this type (comparator, retain, etc.) all have more or less the same
behaviour as the methods of the java.util.Collection interface.
|
| attributes |
-
comparator
(since: MMBase-1.7)
Give the class name of a class that implements the java.util.Comparator interface. Give
either a fully qualified name, or a single name. When it is a single name the
class must be defined as a static inner class in the jsp (see example)
The Comparator may have a method init(PageContext), which will be called first if it has (since 1.8.1).
| SHUFFLE |
For shuffling you don't need to implement a comparator (which is principally
possible). This will use Collections.shuffle in stead.
|
| REVERSE |
This pseudo-comparator simply reverses the order of the list (using Collections.reverse).
|
| NATURAL |
Sorts the objects by their natural ordering.
|
| CASE_INSENSITIVE |
Sorts Strings case-insensitively.
|
| MyCollator |
If you use a value like this, then it will be supposed that this Comparator is implemented
in this jsp. E.g.:
<%!
/**
* Comparator to order mmbase nodes on their field named "title".
*/
static private final Collator DUTCH_COLLATOR = Collator.getInstance(new Locale("nl", "NL"));
static {
// PRIMARY strength ignores differences between é and e, and between e and E
DUTCH_COLLATOR.setStrength(Collator.PRIMARY);
}
static public class DutchCaseInsensitiveCollator implements Comparator {
public int compare(Object o1, Object o2) {
String title1 = ((org.mmbase.bridge.Node) o1).getStringValue("title");
String title2 = ((org.mmbase.bridge.Node) o2).getStringValue("title");
return DUTCH_COLLATOR.compare(title1, title2);
}
}
%>;
<mm:listnodescontainer>
<!-- make sure the list is not gigantic, when sorting with
comparator it happens in memory, not by database! -->
<mm:ageconstraint maxage="7" />
<mm:listnodes comparator="DutchCaseInsensitiveCollator">
...
</mm:listnodes>
</mm:listnodescontainer>
|
| nl.myorg.OurComparator |
You can also use a fully qualified class name.
|
-
add
(since: MMBase-1.8)
Adds to this list all elements represented by the value of this attribute. The value refers
to some taglib variable, like the id of another list, or the id of a node (which is only one
element then).
This method is similar to the behavior of the 'add()' and 'addAll()' methods from the java.util.Collection interface.
It is also possible to postfix the referid with '?', in which case no error will occur if the variable with this id does not exist.
-
retain
(since: MMBase-1.8)
Removes all the elements from the list, except the ones that are also present in the
list which is specified by this attribute.
This method is similar to the behavior of the 'retainAll()' method from the java.util.Collection interface.
It is also possible to postfix the referid with '?', in which case no error will occur if the variable with this id does not exist.
-
remove
(since: MMBase-1.8)
Removes all the elements from the list which are present in the
object referred by this attribute.
This method is similar to the behavior of the 'removeAll()' method from the java.util.Collection interface.
It is also possible to postfix the referid with '?', in which case no error will occur if the variable with this id does not exist.
-
varStatus
(since: MMBase-1.9)
Like varStatus of c:forEach.
|
|
example 1 |
<mm:import id="list1" vartype="list">a,b,c,d,e</mm:import>
<mm:import id="list2" vartype="list">c,d,e,f</mm:import>
<mm:stringlist id="list3" referid="list1" add="list2" />
<mm:stringlist id="list4" referid="list1" retain="list2" />
<mm:stringlist id="list5" referid="list1" remove="list2" />
<mm:write referid="list3" /> / <mm:write referid="list4" /> / <mm:write referid="list5" />
This will print the following:
a,b,c,d,e,c,d,e,f / c,d,e / a,b
|