JBoss.orgCommunity Documentation
The <rich:progressBar> component is designed for displaying a progress bar which shows the current status of the process.
Ajax or Client modes
Option to control rerendering frequency
Customizable status information label
Highly customizable look and feel
As it was mentioned above, the <rich:progressBar> component displays the status of the ongoing process.
The
<rich:progressBar>
component can run in two modes: Ajax
(default) and Client
.
Ajax
- In this mode the component works the same way as
<a4j:poll/>
which gets the current progress value from the sever, repeating after a set time interval.
Client
- The current progress value in Client mode is set using JavaScript API
In order to define the mode you need to use "mode" attribute.
One of the key attributes of the component is "interval" which defines the frequency of status polling and rerenders the component when the value is updated.
Polling is active while the "enabled" attribute is "true".
Example:
...
<rich:progressBar value="#{bean.incValue}" id="progrs" interval="900" enabled="true"/>
...
With the help of "timeout" attribute you can define the waiting time on a particular request. If a response is not received during this time the request is aborted.
Status of the process is calculated basing on values of the following attributes:
"value" is a value binding to the current progress value
"minValue" (default value is "0") sets minimal progress value
"maxValue" (default value is "100") sets maximum progress value
Example:
...
<rich:progressBar value="#{bean.incValue}" minValue="50" maxValue="400"/>
...
This is the result
There are two ways to display information on a progress bar:
Using "label" attribute
Example:
...
<rich:progressBar value="#{bean.incValue}" id="progrs" label="#{bean.incValue}"/>
...
Using any child(nested) components. One of the components that can be used is <h:outputText />
Example:
...
<rich:progressBar value="#{bean.incValue}">
<h:outputText value="#{bean.incValue} %"/>
</rich:progressBar>
...
The <rich:progressBar> component provides 3 predefined macrosubstitution parameters:
{value}
contains the current value
{minValue}
contains min value
{maxValue}
contains max value
You can use them as follows:
Example:
...
<rich:progressBar value="#{bean.incValue1}" minValue="400" maxValue="900">
<h:outputText value="Min value is {minValue}, current value is {value}, max value is {maxValue}"/>
</rich:progressBar>
...
This is the result:
The
"parameters"
is also a special attribute which defines parameters that can be to get additional data from server (e.g. additional info about process status).
All you need is to define the value of your own parameter
(e.g parameters="param:'#{bean.incValue1}'"
)
and you can use it to pass the data.
Example:
...
<rich:progressBar value="#{bean.incValue}" parameters="param:'#{bean.dwnlSpeed}'">
<h:outputText value="download speed {param} KB/s"/>
</rich:progressBar>
...
This is the result:
The "progressVar" attribute (deprecated) defines request scoped variable that could be used for substitution purpose. This variable contains the data taken from "value" attribute. Please, study carefully the following example.
Example:
...
<rich:progressBar value="#{bean.incValue1}" enabled="#{bean.enabled1}" id="progrs1" progressVar="progress">
<h:outputText value="{progress}%"/>
</rich:progressBar>
...
In the shown example "progressVar" attribute defines a variable "progress" with the value taken from "value" attribute of the <rich:progressBar> component. The "progress" variable performs substitution passing the current progress value to the "value" attribute of the <h:outputText> . This is how the current value of a progress appears on the label of <rich:progressBar> .
As the
"progressVar"
attribute is deprecated, it's better to use
the predefined macrosubstitution parameter {value}
instead. See how you can rewrite the above example with the help of {value}
.
Example:
...
<rich:progressBar value="#{bean.incValue1}" enabled="#{bean.enabled1}" id="progrs1">
<h:outputText value="{value}%"/>
</rich:progressBar>
...
The component can also employ "initial" and "complete" facets to display the states of the process: "initial" facet is displayed when the progress value is less or equal to "minValue" , and the "complete" facet is shown when the value is greater or equal to "maxValue" . Please see an example below.
Example:
...
<rich:progressBar value="#{bean.incValue1}">
<f:facet name="initial">
<h:outputText value="Process not started"/>
</f:facet>
<f:facet name="complete">
<h:outputText value="Process completed"/>
</f:facet>
</rich:progressBar>
...
Information about the "process" attribute usage you can find " Decide what to process " guide section.
Table of <rich:progressBar> attributes.
Table 6.131. Component Identification Parameters
Name | Value |
---|---|
component-type | org.richfaces.ProgressBar |
component-class | org.richfaces.component.html.HtmlProgressBar |
component-family | org.richfaces.ProgressBar |
renderer-type | org.richfaces.renderkit.ProgressBarRenderer |
tag-class | org.richfaces.taglib.ProgressBarTag |
Table 6.132. JavaScript API
Function | Description |
---|---|
enable() | Begins polling for Ajax mode |
disable() | Stops polling for Ajax mode |
setValue(value) | Updates the progress of the process |
setLabel(label) | Update the label for the process |
Table 6.133. Facets
Facet name | Description |
---|---|
initial | Defines the information content about the state of the process if the progress value is less or equal to "minValue" |
complete | Defines the information content about the state of the process if the value is greater or equal to "maxValue" |
Table 6.134. Classes names for the progressBar without a label
Class name | Description |
---|---|
rich-progress-bar-shell | Defines styles for a wrapper <div> element of a progressBar |
rich-progress-bar-uploaded | Defines styles for the completed progress area |
rich-progress-bar-height | Defines height for a progressBar |
rich-progress-bar-width | Defines width for a progressBar |
Table 6.135. Classes names for the progressBar with a label
Class name | Description |
---|---|
rich-progress-bar-shell-dig | Defines styles for a wrapper <div> element of a progressBar |
rich-progress-bar-uploaded-dig | Defines styles for the label |
rich-progress-bar-remained | Defines styles for the remained progress area |
rich-progress-bar-completed | Defines styles for the completed progress area |
rich-progress-bar-height-dig | Defines height for a progressBar |
rich-progress-bar-width | Defines width for a progressBar |
It's necessary to define width of the component in pixels only.
On the component Live Demo page you can see the example of <rich:progressBar> usage and sources for the given example.
Read "Simple Ping Application with <rich:progressBar>" article to find out how to show the progress of server ping process.