| |||||||
FRAMES NO FRAMES |
Use the webuijsf:rating
tag to present a row of stars indicating a rating assigned to an item. When the user assigns a new rating to an item, an Ajax request transmits the rating to the server.
None.
When the rating component is rendered, a DOM object corresponding to the rating component is created. To manipulate the component on the client side, you can call functions on the DOM object. For example, with reference to the DOM ID, to deny the user from selecting a grade, invoke document.getElementById(id).setProps({"gradeReadOnly": true})
.
Function | Description |
domNode.getProps() |
Use this function to get widget properties. See setProps() function for a list of supported properties. |
domNode.refresh(execute) |
Use this function to asynchronously refresh the component.
|
domNode.setProps(props) |
Use this function to change any of the following supported properties:
|
domNode.submit(execute) |
Use this function to asynchronously submit the selected grade.
|
domNode.subscribe(topic, obj, func) |
Use this function to subscribe to an event topic.
|
When the component is manipulated on the client side, some functions might publish event topics for custom AJAX implementations to listen for. For example, you can listen for the submit event topic by using:
<webuijsf:script> var processEvents = { update: function(props) { // Do something... } } // Subscribe to submit event. var domNode = document.getElementById("form1:rating"); domNode.subscribe(domNode.event.submit.endTopic, processEvents, "update"); </webuijsf:script>
The following events are supported.
Event | Description |
<Node>.event.refresh.beginTopic | Event topic published before asynchronously refreshing the component. Supported properties include:
|
<Node>.event.refresh.endTopic | Event topic published after asynchronously refreshing the component. Supported properties include:
|
<Node>.event.submit.beginTopic | Event topic published before asynchronously submitting the selected grade. Supported properties include:
|
<Node>.event.submit.endTopic | Event topic published after asynchronously submitting the selected grade. Supported properties include:
|
<Node>.event.grade.selectedTopic | Event topic published after selecting a grade. Supported properties include:
|
<webuijsf:rating id="rating" autoSubmit="true" averageGrade="#{RatingBean.averageGrade}" clearHoverText="Clear Rating" grade="#{RatingBean.grade}" gradeHoverTexts="#{RatingBean.gradeHoverTexts}" notInterestedHoverText="Not Interested" maxGrade="5"> </webuijsf:rating>
The corresponding backing bean would be something like this:
import com.sun.webui.jsf.component.Rating; public class RatingBackingBean { private double averageGrade = 0.0; private int grade = Rating.CLEAR_GRADE; private String[] gradeHoverTexts = { "Hate It", "Below Average", "Average", "Above Average", "Love It" }; private int gradeSum = 0; private int numGrades = 0; private int numNotInterested = 0; public RatingBackingBean() { } public int getNumNotInterested() { return this.numNotInterested; } public void setNumNotInterested(int numNotInterested) { this.numNotInterested = numNotInterested; } public int getGrade() { return grade; } public void setGrade(int grade) { this.grade = grade; // Not interested grade does not factor into average grade if (this.grade == Rating.NOT_INTERESTED_GRADE) { this.numNotInterested++; return; } // Clear grade does not factor into average grade if (this.grade == Rating.CLEAR_GRADE) { return; } gradeSum += grade; numGrades++; } public double getAverageGrade() { if (numGrades == 0) return 0.0; // Compute average grade, rounded to neaest .001 averageGrade = (double)gradeSum / numGrades; averageGrade = Math.rint(averageGrade * 1000) / 1000; return averageGrade; } public void setAverageGrade(double averageGrade) { this.averageGrade = averageGrade; } public String[] getGradeHoverTexts() { return this.gradeHoverTexts; } public void setGradeHoverTexts(String[] gradeHoverTexts) { this.gradeHoverTexts = gradeHoverTexts; } }
<webuijsf:rating id="rating" autoSubmit="true" averageGrade="#{RatingBean.averageGrade}" clearHoverText="Clear Rating" clearAcknowledgedText="Rating cleared" grade="#{RatingBean.grade}" gradeAcknowledgedText="Thank you!" gradeHoverTexts="#{RatingBean.gradeHoverTexts}" includeModeToggle="false" notInterestedAcknowledgedText="Sorry to hear" notInterestedHoverText="Not Interested" maxGrade="5"> </webuijsf:rating> <webuijsf:rating id="ratingAvg" autoSubmit="false" includeNotInterested="false" includeText="false" includeClear="false" includeModeToggle="false" inAverageMode="true" gradeReadOnly="true" modeReadOnly="true" averageGrade="#{RatingBean.averageGrade}" grade="#{RatingBean.grade}" maxGrade="5"> </webuijsf:rating>
The corresponding backing bean would be similar to the one in Example 1.
The application's javascript to manage the submit might look like this:
<webuijsf:script type="text/javascript"> function RatingListener(id) { this.ratingID = id; } // Callback for after submit function OnSubmit(props) { if (props.id != this.ratingID) return; var ratingNode = document.getElementById(this.ratingID); if (ratingNode == null) return; var ratingAvgNode = document.getElementById(this.ratingID + "Avg"); if (ratingNode != null) ratingAvgNode.refresh(); } RatingListener.prototype.onSubmit = OnSubmit; function rating_init() { var domNode = document.getElementById("rating"); if (domNode == null || domNode.event == null) { return setTimeout('rating_init();', 10); } var listener = new RatingListener("rating"); // Subscribe to post-submit event domNode.subscribe(domNode.event.submit.endTopic, listener, listener.onSubmit); } </webuijsf:script> <webuijsf:body onLoad="rating_init();"> ...
Tag Information | |
Tag Class | com.sun.webui.jsf.component.RatingTag |
TagExtraInfo Class | None |
Body Content | JSP |
Display Name | None |
Attributes | ||||
Name | Required | Request-time | Type | Description |
binding | false | false | java.lang.String | A ValueExpression that resolves to the UIComponent that corresponds to this tag. This attribute allows the Java bean that contains the UIComponent to manipulate the UIComponent, its properties, and its children. |
notInterestedAcknowledgedText | false | false | java.lang.String | The acknowledged text for the "not interested" control. There is no default. |
averageGrade | false | false | java.lang.String | The average grade the general user population has assigned to the item. Must be between 0.0 and the maximum grade. This attribute should be set to a value binding expression that corresponds to a property of a managed bean so it will be updated whenever a grade is clicked and the grade property is updated asynchronously. |
modeToggleAcknowledgedTexts | false | false | java.lang.String | The acknowledged texts to be used for the mode toggle control.
The attribute's value must be a JavaServer Faces EL expression that
evaluates to an array of |
maxGrade | false | false | java.lang.String | The maximum grade (number of "stars") this rating instance allows. There is no default, and so must be set. |
clearHoverText | false | false | java.lang.String | The hover text for the clear control. There is no default. |
inAverageMode | false | false | java.lang.String | Indicates whether the component will be rendered displaying the average grade. The default is false, the component will be rendered showing the user's rating (normal mode). |
includeText | false | false | java.lang.String | Indicates whether an area for hover or post-click acknowledeged text should be rendered. The default is true. |
clearAcknowledgedText | false | false | java.lang.String | The acknowledged text for the clear control. There is no default. |
modeReadOnly | false | false | java.lang.String | Indicates whether the mode of this rating component can be changed by the user. The default is false - it is NOT read-only, and therefore can be changed by the user. |
grade | false | false | java.lang.String | The grade (number of "stars") the user has assigned the item.
This attribute should be set to a value binding expression that corresponds
to a property of a managed bean so it will be updated whenever a grade
is clicked. A managed bean can set the value to |
gradeReadOnly | false | false | java.lang.String | Indicates whether the grade of this rating component can be changed by the user. The default is false - it is NOT read-only, and therefore can be changed by the user. |
notInterestedHoverText | false | false | java.lang.String | The hover text for the "not interested" control. There is no default. |
autoSubmit | false | false | java.lang.String | Indicates whether the grade is automatically submitted to the server via an Ajax request immediately after the grade is selected. The default is false - it is NOT automatically submitted. |
styleClass | false | false | java.lang.String | CSS style class or classes to be applied to the outermost HTML element when this component is rendered. |
gradeAcknowledgedText | false | false | java.lang.String | The acknowledged text for the grade controls. There is no default. |
gradeHoverTexts | false | false | java.lang.String | The hover texts that will be used for the grade controls, ordered from
lowest to highest rating. The attribute's value must be a JavaServer Faces
EL expression that evaluates to an array of |
style | false | false | java.lang.String | CSS style or styles to be applied to the outermost HTML element when this component is rendered. |
visible | false | false | java.lang.String | Use to indicate whether the component should be viewable by the user in the rendered HTML page. If set to false, the HTML code for the component is present in the page, but the component is hidden with style attributes. By default, visible is set to false, so HTML for the component HTML is included and not visible to the user. If the component is not visible, it can still be processed on subsequent form submissions because the HTML is present. |
modeToggleHoverTexts | false | false | java.lang.String | The hover texts to be used for the mode toggle control. The
attribute's value must be a JavaServer Faces EL expression that
evaluates to an array of |
includeNotInterested | false | false | java.lang.String | Indicates whether a control to allow the user to assign a "not interested" rating should be rendered. The default is true. |
includeClear | false | false | java.lang.String | Indicates whether a control to clear the user's rating should be displayed. The default is true. |
tabIndex | false | false | java.lang.String | Position of this element in the tabbing order of the current document. Tabbing order determines the sequence in which elements receive focus when the tab key is pressed. The value must be an integer between 0 and 32767. |
includeModeToggle | false | false | java.lang.String | Indicates whether a control to toggle the mode (to show the average rating or the user's rating) should be rendered. The default is false. |
converter | false | false | java.lang.String | Specifies a method to translate native
property values to String and back for this component. The converter
attribute value must be one of the following:
|
required | false | false | java.lang.String | Flag indicating that an input value for this field is mandatory, and failure to provide one will trigger a validation error. |
immediate | false | false | java.lang.String | Flag indicating that event handling for this component should be handled immediately (in Apply Request Values phase) rather than waiting until Invoke Application phase. |
validatorExpression | false | false | java.lang.String | Used to specify a method in a backing bean to validate input
to the component. The value must be a JavaServer Faces
EL expression that resolves to a public method with
return type void. The method must take three parameters:
The backing bean where the method is defined must implement
The method is invoked during the Process Validations Phase. |
rendered | false | false | java.lang.String | Indicates whether the HTML code for the component should be included in the rendered HTML page. If set to false, the rendered HTML page does not include the HTML for the component. If the component is not rendered, it is also not processed on any subsequent form submission. |
valueChangeListenerExpression | false | false | java.lang.String | Specifies a method to handle a value-change event that is triggered
when the user enters data in the input component. The
attribute value must be a JavaServer Faces EL expression that
resolves to a backing bean method. The method must take a single
parameter of type javax.faces.event.ValueChangeEvent ,
and its return type must be void. The backing bean where the
method is defined must implement java.io.Serializable
or javax.faces.component.StateHolder .
|
id | false | true | java.lang.String | No Description |
Variables | No Variables Defined. |
| |||||||
FRAMES NO FRAMES |