How to Use the Rating Component
The Rating JSF component that was created by Matthew Bohm allows
users to rate items and have the model updated through an AJAX
call. The component uses a managed bean to configure the advanced
properties as well as the resultant user rating selection. The
tag library for
the Rating component can be accessed using the
declaration:
<%@taglib prefix="ui" uri="http://java.sun.com/blueprints/ui/14"%>
An example of the JSF Rating component's use is as follows:
<ui:rating id="rating" maxGrade="5" includeNotInterested="true" includeClear="true"
hoverTexts="#{RatingBean.ratingText}" notInterestedHoverText="Not Interested"
clearHoverText="Clear Rating" grade="#{RatingBean.grade}"/>
JSP
Tag Attributes
The Rating component supports
the following attributes.
- includeClear - Whether a control to clear the user's rating
should be rendered.
- includeModeToggle - Whether a control to toggle the mode (to
show the average rating or the user's rating) should be rendered.
- includeNotInterested - Whether a "not interested" control should
be rendered.
- includeText - Whether an area for text should be rendered.
- style - The style to be applied to the outermost rendered
element.
- styleClass - The style class to be applied to the outermost
rendered element.
- averageGrade - The average grade the general user population has
assigned to the item. Must be between 0.0 and maxGrade. This property
must be bound to work dynamically at runtime.
- averageModeHoverText - A custom hover text that will be used for
the mode toggle control, offering the user to switch to average mode.
- averageModeText - Text that appears when the mouse is not
hovering
and the component is in average mode. If bound, this property is sent
to the client via AJAX.
- clearHoverText - A custom hover text that will be used for the
"clear" control.
- grade - The grade (number of "stars") the user has assigned the
item. Use RatingComponent.NOT_INTERESTED_GRADE for "not interested" and
RatingComponent.CLEAR_GRADE for a "clear" grade. This property must be
bound to work dynamically at runtime.
- hoverTexts - An array of custom hover texts that will be used
for
the "star" controls. Null can be specified as a member of the array.
- inAverageMode - Whether the component will be initially rendered
displaying the average grade. If False, then the component will be
initially rendered displaying the user's grade (normal mode).
- maxGrade - The maximum grade (number of "stars") this rating
instance allows.
- normalModeHoverText - A custom hover text that will be used for
the
mode toggle control, offering the user to switch to normal mode.
- normalModeText - Text that appears when the mouse is not
hovering
and the component is in normal mode. If bound, this property is sent to
the client via AJAX.
- notInterestedHoverText - A custom hover text that will be used
for the "not interested" control.
- averageModeAcknowledgedText - Text that appears when the user
clicks the modeToggle control to switch to average mode.
- gradeAcknowledgedText - Text that appears when the user assigns
a
grade to the item (i.e., when the user clicks a control other than the
mode toggle).
- gradeReadOnly - Whether the grade of this rating instance can be
changed by the user.
- modeReadOnly -Whether the mode of this rating instance can be
changed by the user via the mode toggle control.
- normalModeAcknowledgedText - Text that appears when the user
clicks the mode toggle control to switch to normal mode.
- onGrade - A scripting function that will be called when the user
assigns a grade (including "not interested" or "clear").
- onModeToggle - A scripting function that will be called when the
user toggles the mode.
- rendered - Whether the component will be rendered.
© Sun Microsystems 2006. All of the material in The
Java BluePrints Solutions Catalog is copyright-protected
and may not be published in other works without express
written permission from Sun Microsystems.