|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object wicket.Component wicket.MarkupContainer wicket.markup.html.WebMarkupContainer wicket.markup.html.WebMarkupContainerWithAssociatedMarkup wicket.markup.html.panel.Panel wicket.extensions.rating.RatingPanel
public abstract class RatingPanel
Rating component that generates a number of stars where a user can click on
to rate something. Subclasses should implement
onRated(int, AjaxRequestTarget)
to provide the calculation of the
rating, and onIsStarActive(int)
to indicate whether to render an
active star or an 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 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.
newRatingLabel(String, IModel, IModel)
method and create another
label instead, based on the 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.
rating.simple=Rated {0,number,#.#} rating.complete=Rated {0,number,#.#} from {1,number,#} votes
getActiveStarUrl(int)
and getInactiveStarUrl(int)
methods. Using the iteration parameter
it is possible to use a different image for each star, creating a fade effect
or something similar.
Nested Class Summary |
---|
Nested classes/interfaces inherited from class wicket.markup.html.WebMarkupContainerWithAssociatedMarkup |
---|
wicket.markup.html.WebMarkupContainerWithAssociatedMarkup.HeaderPartContainer |
Nested classes/interfaces inherited from class wicket.Component |
---|
wicket.Component.ComponentModelChange, wicket.Component.EnabledChange, wicket.Component.IVisitor, wicket.Component.VisibilityChange |
Field Summary | |
---|---|
static wicket.ResourceReference |
STAR0
Star image for no selected star |
static wicket.ResourceReference |
STAR1
Star image for selected star |
Fields inherited from class wicket.Component |
---|
ENABLE, FLAG_RESERVED1, FLAG_RESERVED2, FLAG_RESERVED3, FLAG_RESERVED4, FLAG_RESERVED5, FLAG_RESERVED6, FLAG_RESERVED7, FLAG_RESERVED8, PATH_SEPARATOR, RENDER |
Constructor Summary | |
---|---|
RatingPanel(java.lang.String id)
Constructs a rating component with 5 stars, using a compound property model as its model to retrieve the rating. |
|
RatingPanel(java.lang.String id,
wicket.model.IModel rating)
Constructs a rating component with 5 stars, using the rating for retrieving the rating. |
|
RatingPanel(java.lang.String id,
wicket.model.IModel rating,
wicket.model.IModel nrOfStars,
wicket.model.IModel nrOfVotes,
wicket.model.IModel hasVoted,
boolean addDefaultCssStyle)
Constructs a rating panel with nrOfStars stars, where the rating model is used to retrieve the rating, the nrOfVotes model used to retrieve the number of votes cast and the hasVoted model to retrieve whether the user already had cast a vote. |
|
RatingPanel(java.lang.String id,
wicket.model.IModel rating,
int nrOfStars,
boolean addDefaultCssStyle)
Constructs a rating component with nrOfStars stars, using the rating for retrieving the rating. |
|
RatingPanel(java.lang.String id,
wicket.model.IModel rating,
int nrOfStars,
wicket.model.IModel nrOfVotes,
boolean addDefaultCssStyle)
Constructs a rating panel with nrOfStars stars, where the rating model is used to retrieve the rating, the nrOfVotes model to retrieve the number of casted votes. |
|
RatingPanel(java.lang.String id,
int nrOfStars)
Constructs a rating component with nrOfStars stars, using a compound property model as its model to retrieve the rating. |
Method Summary | |
---|---|
void |
addDefaultCssStyle()
Will let the rating panel contribute a CSS include to the page's header. |
protected java.lang.String |
getActiveStarUrl(int iteration)
Returns the url pointing to the image of active stars, is used to set the URL for the image of an active star. |
protected java.lang.String |
getInactiveStarUrl(int iteration)
Returns the url pointing to the image of inactive stars, is used to set the URL for the image of an inactive star. |
protected wicket.Component |
newRatingLabel(java.lang.String id,
wicket.model.IModel rating,
wicket.model.IModel nrOfVotes)
Creates a new rating label, showing a message like 'Rated 5.4 from 53 votes'. |
protected wicket.Component |
newRatingStarBar(java.lang.String id,
wicket.model.IModel nrOfStars)
Creates a new bar filled with stars to click on. |
protected abstract boolean |
onIsStarActive(int star)
Returns true when the star identified by its sequence
number should be shown as active. |
protected abstract void |
onRated(int rating,
wicket.ajax.AjaxRequestTarget target)
Notification of a click on a rating star. |
RatingPanel |
setRatingLabelVisible(boolean visible)
Sets the visibility of the rating label. |
Methods inherited from class wicket.markup.html.panel.Panel |
---|
onComponentTag, onComponentTagBody, renderHead |
Methods inherited from class wicket.markup.html.WebMarkupContainerWithAssociatedMarkup |
---|
newHeaderPartContainer, renderHeadFromAssociatedMarkupFile |
Methods inherited from class wicket.markup.html.WebMarkupContainer |
---|
getMarkupType, getWebPage |
Methods inherited from class wicket.MarkupContainer |
---|
add, autoAdd, contains, findMarkupStream, get, getAssociatedMarkupStream, getMarkupStream, internalAdd, internalAttach, internalDetach, isTransparentResolver, iterator, iterator, newMarkupResourceStream, onRender, remove, remove, removeAll, renderAll, renderAssociatedMarkup, renderComponentTagBody, replace, setMarkupStream, setModel, size, toString, toString, visitChildren, visitChildren |
Methods inherited from class wicket.Component |
---|
add, addStateChange, checkComponentTag, checkComponentTagAttribute, continueToOriginalDestination, debug, detachBehaviors, detachModel, detachModels, error, exceptionMessage, fatal, findPage, findParent, findParentWithAssociatedMarkup, getApplication, getApplicationPages, getApplicationSettings, getBehaviors, getBehaviors, getClassRelativePath, getConverter, getEscapeModelStrings, getFeedbackMessage, getFlag, getFlag, getId, getLocale, getLocalizer, getMarkupAttributes, getMarkupId, getMetaData, getModel, getModelComparator, getModelObject, getModelObjectAsString, getOutputMarkupId, getPage, getPageFactory, getPageRelativePath, getParent, getPath, getRenderBodyOnly, getRequest, getRequestCycle, getResponse, getSession, getSizeInBytes, getString, getString, getString, getStyle, getVariation, hasErrorMessage, hasFeedbackMessage, info, initModel, internalOnAttach, internalOnDetach, internalOnModelChanged, isActionAuthorized, isAncestorOf, isBehaviorAccepted, isEnableAllowed, isEnabled, isHeadRendered, isIgnoreAttributeModifier, isRenderAllowed, isVersioned, isVisible, isVisibleInHierarchy, modelChanged, modelChanging, newPage, newPage, onAfterRender, onAttach, onBeforeRender, onBeginRequest, onDetach, onEndRequest, onModelChanged, onModelChanging, onRender, redirectToInterceptPage, remove, render, render, renderComponent, renderComponent, renderComponentTag, rendered, renderedBehaviors, replaceComponentTagBody, replaceWith, resetHeadRendered, sameRootModel, sameRootModel, setAuto, setEnabled, setEscapeModelStrings, setFlag, setFlag, setIgnoreAttributeModifier, setMetaData, setModelObject, setOutputMarkupId, setRedirect, setRenderBodyOnly, setResponsePage, setResponsePage, setResponsePage, setVersioned, setVisible, urlFor, urlFor, urlFor, urlFor, urlFor, visitParents, warn |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public static final wicket.ResourceReference STAR0
public static final wicket.ResourceReference STAR1
Constructor Detail |
---|
public RatingPanel(java.lang.String id)
id
- the component id.public RatingPanel(java.lang.String id, wicket.model.IModel rating)
id
- the component idrating
- the model to get the ratingpublic RatingPanel(java.lang.String id, int nrOfStars)
id
- the component idnrOfStars
- the number of stars to displaypublic RatingPanel(java.lang.String id, wicket.model.IModel rating, int nrOfStars, boolean addDefaultCssStyle)
id
- the component idrating
- the model to get the ratingnrOfStars
- the number of stars to displayaddDefaultCssStyle
- should this component render its own default CSS style?public RatingPanel(java.lang.String id, wicket.model.IModel rating, int nrOfStars, wicket.model.IModel nrOfVotes, boolean addDefaultCssStyle)
id
- the component idrating
- the model to get the ratingnrOfStars
- the number of stars to displaynrOfVotes
- the number of cast votesaddDefaultCssStyle
- should this component render its own default CSS style?public RatingPanel(java.lang.String id, wicket.model.IModel rating, wicket.model.IModel nrOfStars, wicket.model.IModel nrOfVotes, wicket.model.IModel hasVoted, boolean addDefaultCssStyle)
id
- the component id.rating
- the (calculated) rating, i.e. 3.4nrOfStars
- the number of stars to displaynrOfVotes
- the number of cast voteshasVoted
- has the user already voted?addDefaultCssStyle
- should this component render its own default CSS style?Method Detail |
---|
public final void addDefaultCssStyle()
protected wicket.Component newRatingStarBar(java.lang.String id, wicket.model.IModel nrOfStars)
id
- the bar idnrOfStars
- the number of stars to generate
protected wicket.Component newRatingLabel(java.lang.String id, wicket.model.IModel rating, wicket.model.IModel nrOfVotes)
id
- the id of the labelrating
- the model containing the ratingnrOfVotes
- the model containing the number of votes (may be null)
protected java.lang.String getActiveStarUrl(int iteration)
iteration
- the sequence number of the star
protected java.lang.String getInactiveStarUrl(int iteration)
iteration
- the sequence number of the star
public RatingPanel setRatingLabelVisible(boolean visible)
visible
- true when the label should be visible
protected abstract boolean onIsStarActive(int star)
true
when the star identified by its sequence
number should be shown as active.
star
- the sequence number of the star (ranging from 0 to nrOfStars)
true
when the star should be rendered as activeprotected abstract void onRated(int rating, wicket.ajax.AjaxRequestTarget target)
rating
- the number of the star that is clicked, ranging from 1 to
nrOfStarstarget
- the request target, null if the request is a regular, non-AJAX
request.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |