Java Doc for RatingPanel.java in  » J2EE » wicket » wicket » extensions » rating » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » J2EE » wicket » wicket.extensions.rating 
Source Cross Reference  Class Diagram Java Document (Java Doc) 


wicket.markup.html.panel.Panel
   wicket.extensions.rating.RatingPanel

RatingPanel
abstract public class RatingPanel extends Panel (Code)
Rating component that generates a number of stars where a user can click on to rate something. Subclasses should implement RatingPanel.onRated(int,AjaxRequestTarget) to provide the calculation of the rating, and RatingPanel.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 RatingPanel.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 RatingPanel.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.

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 RatingPanel.getActiveStarUrl(int) and RatingPanel.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.
author:
   Martijn Dashorst


Field Summary
final public static  ResourceReferenceSTAR0
    
final public static  ResourceReferenceSTAR1
    

Constructor Summary
public  RatingPanel(String id)
     Constructs a rating component with 5 stars, using a compound property model as its model to retrieve the rating.
public  RatingPanel(String id, IModel rating)
     Constructs a rating component with 5 stars, using the rating for retrieving the rating.
public  RatingPanel(String id, int nrOfStars)
     Constructs a rating component with nrOfStars stars, using a compound property model as its model to retrieve the rating.
public  RatingPanel(String id, IModel rating, int nrOfStars, boolean addDefaultCssStyle)
     Constructs a rating component with nrOfStars stars, using the rating for retrieving the rating.
public  RatingPanel(String id, IModel rating, int nrOfStars, 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.
public  RatingPanel(String id, IModel rating, IModel nrOfStars, IModel nrOfVotes, 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.
Parameters:
  id - the component id.
Parameters:
  rating - the (calculated) rating, i.e.

Method Summary
final public  voidaddDefaultCssStyle()
     Will let the rating panel contribute a CSS include to the page's header. It will add RatingPanel.css from this package.
protected  StringgetActiveStarUrl(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  StringgetInactiveStarUrl(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  ComponentnewRatingLabel(String id, IModel rating, IModel nrOfVotes)
     Creates a new rating label, showing a message like 'Rated 5.4 from 53 votes'.
protected  ComponentnewRatingStarBar(String id, IModel nrOfStars)
     Creates a new bar filled with stars to click on.
abstract protected  booleanonIsStarActive(int star)
     Returns true when the star identified by its sequence number should be shown as active.
abstract protected  voidonRated(int rating, AjaxRequestTarget target)
     Notification of a click on a rating star.
public  RatingPanelsetRatingLabelVisible(boolean visible)
     Sets the visibility of the rating label.

Field Detail
STAR0
final public static ResourceReference STAR0(Code)
Star image for no selected star



STAR1
final public static ResourceReference STAR1(Code)
Star image for selected star




Constructor Detail
RatingPanel
public RatingPanel(String id)(Code)
Constructs a rating component with 5 stars, using a compound property model as its model to retrieve the rating.
Parameters:
  id - the component id.



RatingPanel
public RatingPanel(String id, IModel rating)(Code)
Constructs a rating component with 5 stars, using the rating for retrieving the rating.
Parameters:
  id - the component id
Parameters:
  rating - the model to get the rating



RatingPanel
public RatingPanel(String id, int nrOfStars)(Code)
Constructs a rating component with nrOfStars stars, using a compound property model as its model to retrieve the rating.
Parameters:
  id - the component id
Parameters:
  nrOfStars - the number of stars to display



RatingPanel
public RatingPanel(String id, IModel rating, int nrOfStars, boolean addDefaultCssStyle)(Code)
Constructs a rating component with nrOfStars stars, using the rating for retrieving the rating.
Parameters:
  id - the component id
Parameters:
  rating - the model to get the rating
Parameters:
  nrOfStars - the number of stars to display
Parameters:
  addDefaultCssStyle - should this component render its own default CSS style?



RatingPanel
public RatingPanel(String id, IModel rating, int nrOfStars, IModel nrOfVotes, boolean addDefaultCssStyle)(Code)
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. This panel doens't keep track of whether the user has already voted.
Parameters:
  id - the component id
Parameters:
  rating - the model to get the rating
Parameters:
  nrOfStars - the number of stars to display
Parameters:
  nrOfVotes - the number of cast votes
Parameters:
  addDefaultCssStyle - should this component render its own default CSS style?



RatingPanel
public RatingPanel(String id, IModel rating, IModel nrOfStars, IModel nrOfVotes, IModel hasVoted, boolean addDefaultCssStyle)(Code)
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.
Parameters:
  id - the component id.
Parameters:
  rating - the (calculated) rating, i.e. 3.4
Parameters:
  nrOfStars - the number of stars to display
Parameters:
  nrOfVotes - the number of cast votes
Parameters:
  hasVoted - has the user already voted?
Parameters:
  addDefaultCssStyle - should this component render its own default CSS style?




Method Detail
addDefaultCssStyle
final public void addDefaultCssStyle()(Code)
Will let the rating panel contribute a CSS include to the page's header. It will add RatingPanel.css from this package. This method is typically called by the class that creates the rating panel.



getActiveStarUrl
protected String getActiveStarUrl(int iteration)(Code)
Returns the url pointing to the image of active stars, is used to set the URL for the image of an active star. Override this method to provide your own images.
Parameters:
  iteration - the sequence number of the star the url pointing to the image for active stars.



getInactiveStarUrl
protected String getInactiveStarUrl(int iteration)(Code)
Returns the url pointing to the image of inactive stars, is used to set the URL for the image of an inactive star. Override this method to provide your own images.
Parameters:
  iteration - the sequence number of the star the url pointing to the image for inactive stars.



newRatingLabel
protected Component newRatingLabel(String id, IModel rating, IModel nrOfVotes)(Code)
Creates a new rating label, showing a message like 'Rated 5.4 from 53 votes'.
Parameters:
  id - the id of the label
Parameters:
  rating - the model containing the rating
Parameters:
  nrOfVotes - the model containing the number of votes (may be null) the label component showing the message.



newRatingStarBar
protected Component newRatingStarBar(String id, IModel nrOfStars)(Code)
Creates a new bar filled with stars to click on.
Parameters:
  id - the bar id
Parameters:
  nrOfStars - the number of stars to generate the bar with rating stars



onIsStarActive
abstract protected boolean onIsStarActive(int star)(Code)
Returns true when the star identified by its sequence number should be shown as active.
Parameters:
  star - the sequence number of the star (ranging from 0 to nrOfStars) true when the star should be rendered as active



onRated
abstract protected void onRated(int rating, AjaxRequestTarget target)(Code)
Notification of a click on a rating star. Add your own components to the request target when you want to have them updated in the Ajax request. NB the target may be null when the click isn't handled using AJAX, but using a fallback scenario.
Parameters:
  rating - the number of the star that is clicked, ranging from 1 tonrOfStars
Parameters:
  target - the request target, null if the request is a regular, non-AJAXrequest.



setRatingLabelVisible
public RatingPanel setRatingLabelVisible(boolean visible)(Code)
Sets the visibility of the rating label.
Parameters:
  visible - true when the label should be visible this for chaining.



Methods inherited from wicket.markup.html.panel.Panel
protected void onComponentTag(ComponentTag tag)(Code)(Java Doc)
protected void onComponentTagBody(MarkupStream markupStream, ComponentTag openTag)(Code)(Java Doc)
public void renderHead(HtmlHeaderContainer container)(Code)(Java Doc)

www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.