This documentation is for an old version of fiftyfive-wicket (2.0.9).


fiftyfive.wicket.css
Class IterationCssBehavior

java.lang.Object
  extended by org.apache.wicket.behavior.AbstractBehavior
      extended by fiftyfive.wicket.css.CssClassModifier
          extended by fiftyfive.wicket.css.IterationCssBehavior
All Implemented Interfaces:
Serializable, IBehavior, IComponentConfigurationBehavior, IClusterable, IHeaderContributor

public class IterationCssBehavior
extends CssClassModifier

Emits odd, even, first and last CSS classes (or any combination thereof) for repeating components. Supports ListView, Loop and subclasses of RepeatingView (e.g. DataView).

To use, attach this behavior to the item being populated. Upon constructing the behavior you can specify exactly which classes you would like the behavior to manage. In this example, we ask for first and last to be emitted to each item in a list:

 Example.html
 
 <ul>
   <li wicket:id="items"></li>
 </ul>
 Example.java
 
 add(new ListView("items", listOfThreeThings) {
     @Override
     protected void populateItem(ListItem it)
     {
         it.add(new IterationCssBehavior("first", "last"));
     }
 });
 Output
 
 <ul>
   <li class="first"></li>
   <li></li>
   <li class="last"></li>
 </ul>

Since:
2.0.4
See Also:
Serialized Form

Nested Class Summary
static class IterationCssBehavior.CssClass
          Valid CSS classes that this behavior can be configured to emit during the rendering of repeating components.
 
Constructor Summary
IterationCssBehavior(IterationCssBehavior.CssClass... classes)
          Construct a behavior that will output the specified css classes.
IterationCssBehavior(String... classes)
          Construct a behavior that will output the specified css classes.
 
Method Summary
protected  int getIndex(Component component)
          Assume that the component is a ListItem, LoopItem, or Item and get its index.
protected  int getSize(Component component)
          Assume that the component has an immediate parent of ListView, Loop, or RepeatingView and use what we know about those implementations to infer the size of the list that is being iterated.
protected  void modifyClasses(Component component, Set<String> values)
          For each of the IterationCssBehavior.CssClass values provided in the constructor, inspect the component to which this behavior is bound and determine if the css class is applicable.
 
Methods inherited from class fiftyfive.wicket.css.CssClassModifier
onComponentTag
 
Methods inherited from class org.apache.wicket.behavior.AbstractBehavior
afterRender, beforeRender, bind, cleanup, detach, detachModel, exception, getStatelessHint, isEnabled, isTemporary, onConfigure, onException, onRendered, rendered, renderHead
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

IterationCssBehavior

public IterationCssBehavior(String... classes)
Construct a behavior that will output the specified css classes. The behavior must be added to a repeating item like an Item or ListItem. This is a convenience constructor that, while not typesafe, is much more concise.
 // These are equivalent:
 new IterationCssBehavior("odd", "even");
 new IterationCssBehavior(IterationCssBehavior.CssClass.ODD, IterationCssBehavior.CssClass.EVEN);

Parameters:
classes - One or more of the 5 classes declared in the IterationCssBehavior.CssClass enum.
Throws:
IllegalArgumentException - if one or more of the specified strings does not exactly match a IterationCssBehavior.CssClass value (case-insensitive)

IterationCssBehavior

public IterationCssBehavior(IterationCssBehavior.CssClass... classes)
Construct a behavior that will output the specified css classes. The behavior must be added to a repeating item like an Item or ListItem.

Parameters:
classes - One or more of the 5 classes declared in the IterationCssBehavior.CssClass enum.
Method Detail

modifyClasses

protected void modifyClasses(Component component,
                             Set<String> values)
For each of the IterationCssBehavior.CssClass values provided in the constructor, inspect the component to which this behavior is bound and determine if the css class is applicable. If so, add that class to the Set of classes that will be emitted in the markup. For example, if the class is "odd", determine if the component is odd-numbered within its repeating view; if so, add "odd" to the classes that will be emitted.

Specified by:
modifyClasses in class CssClassModifier
Parameters:
component - The component whose HTML element is being rendered.
values - A set containing all the CSS classes that were declared in the markup for this component, if any. If values are added to this set, they will be emitted in the class attribute of the element when the component renders, with a space separating each value. Values may also be removed in order to prevent them from being emitted.

getIndex

protected int getIndex(Component component)
Assume that the component is a ListItem, LoopItem, or Item and get its index. Note that the index begins from zero.

Throws:
UnsupportedOperationException - if the component is not one of the three supported types

getSize

protected int getSize(Component component)
Assume that the component has an immediate parent of ListView, Loop, or RepeatingView and use what we know about those implementations to infer the size of the list that is being iterated. Note that in the case of pagination, this is the size of the visible items (i.e the current page), not the total size that includes other pages.

Throws:
UnsupportedOperationException - if the parent component is not one of the three supported types


Copyright © 2011 55 Minutes. All Rights Reserved.