6.72.  < rich:progressBar >

6.72.1. Description

The <rich:progressBar> component is designed for displaying a progress bar which shows the current status of the process.

<rich:progressBar> component

Figure 6.194.  <rich:progressBar> component


6.72.2. Key Features

  • Ajax or Client modes

  • Option to control rerendering frequency

  • Customizable status information label

  • Highly customizable look and feel

Table 6.390. rich : progressBar attributes

Attribute NameDescription
actionListenerMethodBinding pointing at method accepting an ActionEvent with return type void
ajaxSingleif "true", submits ONLY one field/link, instead of all form controls
bindingThe attribute takes a value-binding expression for a component property of a backing bean
bypassUpdatesIf "true", after process validations phase it skips updates of model beans on a force render response. It can be used for validating components input
completeClassCSS class that defines style for progress line rendering
dataSerialized (on default with JSON) data passed on the client by a developer on AJAX request. It's accessible via "data.foo" syntax
enabledEnables/disables polling. Default value is "true".
eventsQueueName of requests queue to avoid send next request before complete other from same event. Can be used to reduce number of requests of frequently events (key press, mouse move etc.)
finishClassCSS class that defines style for complete state of the component
focusid of element to set focus after request completed on client side
idEvery component may have a unique id that is automatically created if omitted
ignoreDupResponsesAttribute allows to ignore an Ajax Response produced by a request if the newest 'similar' request is in a queue already. ignoreDupResponses="true" does not cancel the request while it is processed on the server, but just allows to avoid unnecessary updates on the client side if the response isn't actual now
immediateTrue means, that the default ActionListener should be executed immediately (i.e. during Apply Request Values phase of the request processing lifecycle), rather than waiting until the Invoke Application phase
initialClassCSS class that defines style for initial state of the component
intervalInterval (in ms) for call poll requests. Default value 1000 ms (1 sec)
labelAttribute defines a simple label instead of rendering children component
limitToListIf "true", updates on client side ONLY elements from this 'reRender' property. If "false" (default) updates all rendered by ajax region components
maxValueMax value, after which complete state should be rendered. Default value is "100".
minValueMin value when initial state should be rendered. Default value is "0".
modeAttributes defines AJAX or CLIENT modes for component. Possible values are "ajax", "client". Default value is "client".
onbeforedomupdateJavaScript code for call before DOM has been updated on client side
onclickHTML: a script expression; a pointer button is clicked
oncompleteJavaScript code for call after request completed on client side
ondblclickHTML: a script expression; a pointer button is double-clicked
onkeydownHTML: a script expression; a key is pressed down
onkeypressHTML: a script expression; a key is pressed and released
onkeyupHTML: a script expression; a key is released
onmousedownHTML: script expression; a pointer button is pressed down
onmousemoveHTML: a script expression; a pointer is moved within
onmouseoutHTML: a script expression; a pointer is moved away
onmouseoverHTML: a script expression; a pointer is moved onto
onmouseupHTML: script expression; a pointer button is released
onsubmitJavaScript code for call before submission of ajax event
parametersParameters for macrosubstitution in the label
processId['s] (in format of call UIComponent.findComponent()) of components, processed at the phases 2-5 in case of AjaxRequest caused by this component. Can be single id, comma-separated list of Id's, or EL Expression with array or Collection
progressVarProvides access to value of the component on the client
remainClassCSS class that defines style for remained part of progress bar
renderedIf "false", this component is not rendered
reRenderId['s] (in format of call UIComponent.findComponent()) of components, rendered in case of AjaxRequest caused by this component. Can be single id, comma-separated list of Id's, or EL Expression with array or Collection
reRenderAfterCompleteSet of componets to rerender after completion
statusID (in format of call UIComponent.findComponent()) of Request status component
styleCSS style(s) is/are to be applied when this component is rendered
styleClassCSS class that defines style for progress bar
timeoutResponse waiting time on a particular request. If a response is not received during this time, the request is aborted
titleAdvisory title information about markup elements generated for this component
valueSets the current value of the progress

Table 6.391. Component identification parameters

NameValue
component-typeorg.richfaces.ProgressBar
component-classorg.richfaces.component.html.HtmlProgressBar
component-familyorg.richfaces.ProgressBar
renderer-typeorg.richfaces.renderkit.ProgressBarRenderer
tag-classorg.richfaces.taglib.ProgressBarTag

6.72.3. Creating the Component with a Page Tag

Here is a simple example of how the component can be used on a page:

Example:


...
<rich:progressBar value="#{bean.incValue1}"/>
...

6.72.4. Creating the Component Dynamically Using Java

Example:


import org.richfaces.component.html.progressBar;
... 
HtmlProgressBar myProgressBar = new progressBar();
...

6.72.5. Details of Usage

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

Progress bar

Figure 6.195. Progress bar


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 "progressVar" attribute 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> .

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:

Macrosubstitution

Figure 6.196. Macrosubstitution


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

Usage of parameters

Figure 6.197. Usage of parameters


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 here.

6.72.6. JavaScript API

Table 6.392. JavaScript API

FunctionDescription
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

6.72.7. Look-and-Feel Customization

For skinnability implementation, the components use a style class redefinition method. Default style classes are mapped on skin parameters.

There are two ways to redefine the appearance of all <rich:progressBar> components at once:

  • Redefine the corresponding skin parameters

  • Add to your style sheets style classes used by a <rich:progressBar> component

6.72.8. Skin Parameters Redefinition

Table 6.393. Skin parameters redefinition for the progressBar without a label

Skin parametersCSS properties
controlBackgroundColorbackground-color
panelBorderColorborder-color

Table 6.394. Skin parameters redefinition for the completed progress area of the progressBar without a label

Skin parametersCSS properties
selectControlColorbackground-color

Table 6.395. Skin parameters redefinition for the progressBar with a label

Skin parametersCSS properties
panelBorderColorborder-color
generalFamilyFontfont-family
generalSizeFontfont-size
controlTextColorcolor

Table 6.396. Skin parameters redefinition for the label of the progressBar

Skin parametersCSS properties
panelBorderColorborder-color

Table 6.397. Skin parameters redefinition for the completed progress area of the progressBar with a label

Skin parametersCSS properties
selectControlColorbackground-color
controlBackgroundColorcolor

Table 6.398. Skin parameters redefinition for the remained progress area of the progressBar with a label

Skin parametersCSS properties
controlBackgroundColorbackground-color
controlTextColorcolor

6.72.9. Definition of Custom Style Classes

On the screenshot there are classes names that define styles for component elements.

Classes names

Figure 6.198. Classes names


Table 6.399. Classes names for the progressBar without a label

Class nameDescription
rich-progress-bar-shellDefines styles for a wrapper <div> element of a progressBar
rich-progress-bar-uploadedDefines styles for the completed progress area
rich-progress-bar-heightDefines height for a progressBar
rich-progress-bar-widthDefines width for a progressBar

Table 6.400. Classes names for the progressBar with a label

Class nameDescription
rich-progress-bar-shell-digDefines styles for a wrapper <div> element of a progressBar
rich-progress-bar-uploaded-digDefines styles for the label
rich-progress-bar-remainedDefines styles for the remained progress area
rich-progress-bar-completedDefines styles for the completed progress area
rich-progress-bar-height-digDefines height for a progressBar
rich-progress-bar-widthDefines width for a progressBar

Note:

It's necessary to define width of the component in pixels only.

In order to redefine styles for all <rich:progressBar> components on a page using CSS, it's enough to create classes with the same names (possible classes could be found in the tables above) and define necessary properties in them.

Example:


...
.rich-progress-bar-remained{                                    
    
background-color: #ebf3fd;                         
}  
...

This is the result:

Redefinition styles with predefined classes

Figure 6.199. Redefinition styles with predefined classes


In the example above background color of the remained part of progress area was changed.

It's aslo possible to change styles of a particular <rich:progressBar> component. In this case you should create own style classes and use them in corresponding <rich:progressBar> styleClass attributes. An example is placed below:

Example:


...
.myClass{  
background-color: #ebf3fd;
}
...

The "remainClass" attribute for <rich:progressBar> is defined as it’s shown in the example below:

Example:


<rich:progressBar value="#{bean.incValue1}" styleClass="remainClass"/>

This is the result:

Modificaton of a look and feel with own classes and styleClass attributes

Figure 6.200. Modificaton of a look and feel with own classes and styleClass attributes


As it could be seen on the picture above, background color of the remained part of progress area was changed.

6.72.10. Relevant Resources Links

Here you can see the example of <rich:progressBar> usage and sources for the given example.