Rating component that generates a number of stars where a user can click on to rate something. Subclasses should implement {@link #onRated(int,org.apache.wicket.ajax.AjaxRequestTarget)} to provide the calculationof the rating, and {@link #onIsStarActive(int)} to indicate whether to render an active star oran inactive star.
Active stars are the stars that show the rating, inactive stars are the left overs. E.G. a rating of 3.4 on a scale of 5 stars will render 3 active stars, and 2 inactive stars (provided that the {@link #onIsStarActive(int)} returns true
for each of the first three stars).
Use this component in the following way:
add(new RatingPanel("rating", new PropertyModel(rating, "rating"), 5) { protected boolean onIsStarActive(int star) { return rating.isActive(star); } protected void onRated(int rating, AjaxRequestTarget target) { rating1.addRating(rating); } });
The user of this component is responsible for creating a model that supplies a Double (or Float) value for the rating message, however the rating panel doesn't necessarily have to contain a float or number rating value.
Though not obligatory, you could also supply a value for the number of votes cast, which allows the component to render a more complete message in the rating label.
Customizing the rating value and label
To customize the rating value, one should override the {@link #newRatingLabel(String,IModel,IModel)} method and create another label instead, based onthe provided models. If you do so, and use another system of rating than returning a Float or Double, then you should also customize the rating resource bundle to reflect your message. The default resource bundle assumes a numeric value for the rating.
Resource bundle
This component uses two types of messages: rating.simple and rating.complete. The first message is used when no model is given for the number of cast votes. The complete message shows the text 'Rating xx.yy from zz votes'.
rating.simple=Rated {0,number,#.#} rating.complete=Rated {0,number,#.#} from {1,number,#} votes
Customizing the star images
To customize the images shown, override the {@link #getActiveStarUrl(int)} and{@link #getInactiveStarUrl(int)} methods. Using the iteration parameter it is possible to use adifferent image for each star, creating a fade effect or something similar.
@author Martijn Dashorst