Richfaces Usersguide
Richfaces Usersguide
Richfaces Usersguide
RichFaces framework
with a huge library of
rich components and
skinnability support
1. Introduction ................................................................................................................. 1
2. Technical Requirements .............................................................................................. 3
2.1. Supported Java Versions .................................................................................... 3
2.2. Supported JavaServer Faces Implementations and Frameworks ............................ 3
2.3. Supported Servers .............................................................................................. 3
2.4. Supported Browsers ............................................................................................ 4
3. Getting Started with RichFaces ................................................................................... 5
3.1. Downloading RichFaces 3.2.1 ............................................................................. 5
3.2. Installation .......................................................................................................... 5
3.3. Simple Ajax Echo Project ................................................................................... 6
3.3.1. JSP Page ................................................................................................ 6
3.3.2. Data Bean ............................................................................................... 7
3.3.3. faces-config.xml ....................................................................................... 7
3.3.4. Web.xml .................................................................................................. 8
3.3.5. Deployment ............................................................................................. 9
4. Settings for different environments ........................................................................... 11
4.1. Web Application Descriptor Parameters .............................................................. 11
4.2. Sun JSF RI ...................................................................................................... 14
4.3. Apache MyFaces .............................................................................................. 15
4.4. Facelets Support ............................................................................................... 15
4.5. JBoss Seam Support ........................................................................................ 16
4.6. Portlet Support .................................................................................................. 19
4.7. Sybase EAServer .............................................................................................. 19
4.8. Oracle AS/OC4J ............................................................................................... 20
5. Basic concepts of the RichFaces Framework ............................................................ 21
5.1. Introduction ....................................................................................................... 21
5.2. RichFaces Architecture Overview ....................................................................... 22
5.3. Limitations and Rules ........................................................................................ 25
5.4. Ajax Request Optimization ................................................................................ 26
5.4.1. Re-Rendering ......................................................................................... 26
5.4.2. Queue and Traffic Flood Protection ......................................................... 28
5.4.3. Data Processing Options ........................................................................ 29
5.4.4. Action and Navigation ............................................................................ 30
5.4.5. JavaScript Interactions ............................................................................ 31
5.4.6. Iteration components Ajax attributes ........................................................ 32
5.4.7. Other useful attributes ............................................................................ 33
5.5. How To... ......................................................................................................... 34
5.5.1. Send an Ajax request ............................................................................. 34
5.5.2. Decide What to Send ............................................................................. 34
5.5.3. Decide What to Change ......................................................................... 34
5.5.4. Decide what to process .......................................................................... 35
5.6. Filter Configuration ............................................................................................ 36
5.7. Scripts and Styles Load Strategy ....................................................................... 38
5.8. Request Errors and Session Expiration Handling ................................................ 39
iii
RichFaces Developer Guide
iv
6.6. < a4j:form > .................................................................................................... 89
6.6.1. Description ............................................................................................. 89
6.6.2. Creating on a page ................................................................................ 92
6.6.3. Creating the Component Dynamically Using Java ..................................... 92
6.6.4. Key attributes and ways of usage ........................................................... 92
6.6.5. Relevant resources links ......................................................................... 93
6.7. < a4j:htmlCommandLink > ................................................................................ 93
6.7.1. Description ............................................................................................. 93
6.7.2. Creating the Component with a Page Tag ............................................... 97
6.7.3. Creating the Component Dynamically Using Java ..................................... 97
6.7.4. Key attributes and ways of usage ........................................................... 97
6.7.5. Relevant resources links ......................................................................... 98
6.8. < a4j:jsFunction > ............................................................................................ 98
6.8.1. Description ............................................................................................. 98
6.8.2. Creating on a page .............................................................................. 100
6.8.3. Creating the Component Dynamically Using Java ................................... 101
6.8.4. Key attributes and ways of usage .......................................................... 101
6.8.5. Relevant resources links ....................................................................... 102
6.9. < a4j:include > ............................................................................................... 102
6.9.1. Description ........................................................................................... 102
6.9.2. Creating on a page .............................................................................. 103
6.9.3. Creating the Component Dynamically Using Java ................................... 104
6.9.4. Relevant resources links ....................................................................... 105
6.10. < a4j:loadBundle > ....................................................................................... 105
6.10.1. Description ......................................................................................... 105
6.10.2. Creating on a page ............................................................................. 105
6.10.3. Creating the Component Dynamically Using Java ................................. 106
6.10.4. Key attributes and ways of usage ........................................................ 106
6.10.5. Relevant resources links ..................................................................... 106
6.11. < a4j:loadScript > ......................................................................................... 106
6.11.1. Description ......................................................................................... 106
6.11.2. Creating on a page ............................................................................. 107
6.11.3. Creating the Component Dynamically Using Java ................................. 107
6.11.4. Key attributes and ways of usage ........................................................ 107
6.11.5. Relevant resources links ..................................................................... 108
6.12. < a4j:loadStyle > .......................................................................................... 108
6.12.1. Description ......................................................................................... 108
6.12.2. Creating on a page ............................................................................. 108
6.12.3. Creating the Component Dynamically Using Java ................................. 109
6.12.4. Key attributes and ways of usage ........................................................ 109
6.12.5. Relevant resources links ..................................................................... 109
6.13. < a4j:log > ................................................................................................... 109
6.13.1. Description ......................................................................................... 109
6.13.2. Creating the Component with a Page Tag ............................................ 111
v
RichFaces Developer Guide
vi
6.20.5. Relevant resources links ..................................................................... 141
6.21. < a4j:repeat > .............................................................................................. 141
6.21.1. Description ......................................................................................... 141
6.21.2. Creating on a page ............................................................................. 142
6.21.3. Creating the Component Dynamically Using Java ................................. 142
6.21.4. Key attributes and ways of usage ........................................................ 142
6.21.5. Relevant resources links ..................................................................... 143
6.22. < a4j:status > .............................................................................................. 144
6.22.1. Description ......................................................................................... 144
6.22.2. Creating on a page ............................................................................. 145
6.22.3. Creating the Component Dynamically Using Java ................................. 146
6.22.4. Key attributes and ways of usage ........................................................ 146
6.22.5. Relevant resources links ..................................................................... 147
6.23. < a4j:support > ............................................................................................ 148
6.23.1. Description ......................................................................................... 148
6.23.2. Creating on a page ............................................................................. 150
6.23.3. Creating the Component Dynamically Using Java ................................. 150
6.23.4. Key attributes and ways of usage ........................................................ 151
6.23.5. Relevant resources links ..................................................................... 154
6.24. < rich:ajaxValidator > ................................................................................... 154
6.24.1. Description ......................................................................................... 154
6.24.2. Key Features ...................................................................................... 154
6.24.3. Creating the Component with a Page Tag ............................................ 156
6.24.4. Creating the Component Dynamically Using Java ................................. 156
6.24.5. Details of Usage ................................................................................. 157
6.24.6. Relevant Resources Links ................................................................... 159
6.25. < rich:graphValidator > ................................................................................. 159
6.25.1. Description ......................................................................................... 159
6.25.2. Key Features ...................................................................................... 159
6.25.3. Creating the Component with a Page Tag ............................................ 160
6.25.4. Creating the Component Dynamically Using Java ................................. 160
6.25.5. Relevant Resources Links ................................................................... 162
6.26. < rich:beanValidator > .................................................................................. 162
6.26.1. Description ......................................................................................... 162
6.26.2. Key Features ...................................................................................... 163
6.26.3. Creating the Component with a Page Tag ............................................ 163
6.26.4. Creating the Component Dynamically Using Java ................................. 163
6.26.5. Details of Usage ................................................................................. 164
6.26.6. Relevant Resources Links ................................................................... 166
6.27. < rich:calendar > .......................................................................................... 166
6.27.1. Description ......................................................................................... 166
6.27.2. Key Features ...................................................................................... 166
6.27.3. Creating the Component with a Page Tag ............................................ 173
6.27.4. Creating the Component Dynamically Using Java ................................. 173
vii
RichFaces Developer Guide
viii
6.32. < rich:datascroller > ..................................................................................... 231
6.32.1. Description ......................................................................................... 231
6.32.2. Key Features ...................................................................................... 231
6.32.3. Creating the Component with a Page Tag ............................................ 236
6.32.4. Creating the Component Dynamically Using Java ................................. 236
6.32.5. Details of Usage ................................................................................. 236
6.32.6. Look-and-Feel Customization .............................................................. 240
6.32.7. Skin Parameters Redefinition .............................................................. 241
6.32.8. Definition of Custom Style Classes ...................................................... 241
6.32.9. Relevant Resources Links ................................................................... 243
6.33. < rich:columns > .......................................................................................... 244
6.33.1. Description ......................................................................................... 244
6.33.2. Key Features ...................................................................................... 244
6.33.3. Creating the Component with a Page Tag ............................................ 246
6.33.4. Creating the Component Dynamically Using Java ................................. 247
6.33.5. Details of Usage ................................................................................. 247
6.33.6. Look-and-Feel Customization .............................................................. 251
6.33.7. Skin Parameters Redefinition .............................................................. 251
6.33.8. Definition of Custom Style Classes ...................................................... 251
6.33.9. Relevant Resources Links ................................................................... 253
6.34. < rich:columnGroup > ................................................................................... 253
6.34.1. Description ......................................................................................... 253
6.34.2. Key Features ...................................................................................... 254
6.34.3. Creating the Component with a Page Tag ............................................ 255
6.34.4. Creating the Component Dynamically Using Java ................................. 256
6.34.5. Details of Usage ................................................................................. 256
6.34.6. Look-and-Feel Customization .............................................................. 259
6.34.7. Skin Parameters Redefinition .............................................................. 259
6.34.8. Definition of Custom Style Classes ...................................................... 259
6.34.9. Relevant Resources Links ................................................................... 261
6.35. < rich:column > ............................................................................................ 261
6.35.1. Description ......................................................................................... 261
6.35.2. Key Features ...................................................................................... 262
6.35.3. Creating the Component with a Page Tag ............................................ 264
6.35.4. Creating the Component Dynamically Using Java ................................. 264
6.35.5. Details of Usage ................................................................................. 265
6.35.6. Sorting and Filtering ........................................................................... 268
6.35.7. Look-and-Feel Customization .............................................................. 274
6.35.8. Skin Parameters Redefinition .............................................................. 274
6.35.9. Definition of Custom Style Classes ...................................................... 275
6.35.10. Relevant Resources Links ................................................................. 276
6.36. < rich:dataGrid > .......................................................................................... 276
6.36.1. Description ......................................................................................... 276
6.36.2. Key Features ...................................................................................... 277
ix
RichFaces Developer Guide
x
6.41. < rich:subTable > ......................................................................................... 320
6.41.1. Description ......................................................................................... 320
6.41.2. Key Features ...................................................................................... 320
6.41.3. Creating the Component with a Page Tag ............................................ 324
6.41.4. Creating the Component Dynamically Using Java ................................. 324
6.41.5. Details of Usage ................................................................................. 324
6.41.6. Look-and-Feel Customization .............................................................. 325
6.41.7. Skin Parameters Redefinition .............................................................. 325
6.41.8. Definition of Custom Style Classes ...................................................... 325
6.42. < rich:dndParam > ....................................................................................... 329
6.42.1. Description ......................................................................................... 329
6.42.2. Creating the Component with a Page Tag ............................................ 330
6.42.3. Creating the Component Dynamically Using Java ................................. 330
6.42.4. Details of Usage ................................................................................. 330
6.42.5. Look-and-Feel Customization .............................................................. 332
6.42.6. Relevan Resources Links .................................................................... 332
6.43. < rich:dragIndicator > ................................................................................... 332
6.43.1. Description ......................................................................................... 332
6.43.2. Key Features ...................................................................................... 332
6.43.3. Creating the Component with a Page Tag ............................................ 333
6.43.4. Creating the Component Dynamically Using Java ................................. 333
6.43.5. Details of Usage ................................................................................. 334
6.43.6. Look-and-Feel Customization .............................................................. 336
6.43.7. Relevant Resources Links ................................................................... 336
6.44. < rich:dragSupport > .................................................................................... 336
6.44.1. Description ......................................................................................... 336
6.44.2. Key Features ...................................................................................... 337
6.44.3. Creating the Component with a Page Tag ............................................ 340
6.44.4. Creating the Component Dynamically Using Java ................................. 340
6.44.5. Details of Usage ................................................................................. 341
6.44.6. Look-and-Feel Customization .............................................................. 343
6.44.7. Relevant Resources Links ................................................................... 343
6.45. < rich:dropSupport > .................................................................................... 343
6.45.1. Description ......................................................................................... 343
6.45.2. Key Features ...................................................................................... 343
6.45.3. Creating the Component with a Page Tag ............................................ 347
6.45.4. Creating the Component Dynamically Using Java ................................. 347
6.45.5. Details of Usage ................................................................................. 347
6.45.6. Look-and-Feel Customization .............................................................. 350
6.45.7. Relevant Resources Links ................................................................... 350
6.46. < rich:dragListener > .................................................................................... 350
6.46.1. Description ......................................................................................... 350
6.46.2. Key Features ...................................................................................... 350
6.46.3. Creating the Component with a Page Tag ............................................ 351
xi
RichFaces Developer Guide
xii
6.51.5. Details of Usage ................................................................................. 388
6.51.6. Look-and-Feel Customization .............................................................. 390
6.51.7. Skin Parameters Redefinition .............................................................. 390
6.51.8. Definition of Custom Style Classes ..................................................... 391
6.51.9. Relevant Resources Links ................................................................... 393
6.52. < rich:menuSeparator > ................................................................................ 393
6.52.1. Description ......................................................................................... 393
6.52.2. Creating the Component with a Page Tag ............................................ 394
6.52.3. Creating the Component Dynamically Using Java ................................. 394
6.52.4. Look-and-Feel Customization .............................................................. 394
6.52.5. Skin Parameters Redefinition .............................................................. 395
6.52.6. Definition of Custom Style Classes ...................................................... 395
6.52.7. Relevant Resources Links ................................................................... 396
6.53. < rich:effect > .............................................................................................. 396
6.53.1. Description ......................................................................................... 396
6.53.2. Key Features ...................................................................................... 396
6.53.3. Creating the Component with a Page Tag ............................................ 397
6.53.4. Creating the Component Dynamically Using Java ................................. 397
6.53.5. Details of Usage ................................................................................. 398
6.53.6. Look-and-Feel Customization .............................................................. 400
6.53.7. Relevant Resources Links ................................................................... 400
6.54. < rich:fileUpload > ........................................................................................ 400
6.54.1. Description ......................................................................................... 400
6.54.2. Key Features ...................................................................................... 400
6.54.3. Creating the Component with a Page Tag ............................................ 405
6.54.4. Creating the Component Dynamically Using Java ................................. 405
6.54.5. Details of Usage ................................................................................. 405
6.54.6. JavaScript API .................................................................................... 413
6.54.7. Look-and-Feel Customization .............................................................. 416
6.54.8. Skin Parameters Redefinition .............................................................. 416
6.54.9. Definition of Custom Style Classes ...................................................... 417
6.54.10. Relevant Resources Links ................................................................. 421
6.55. < rich:gmap > .............................................................................................. 421
6.55.1. Description ......................................................................................... 421
6.55.2. Key Features ...................................................................................... 421
6.55.3. Creating the Component with a Page Tag ............................................ 424
6.55.4. Creating the Component Dynamically Using Java ................................. 424
6.55.5. Details of Usage ................................................................................. 424
6.55.6. Look-and-Feel Customization .............................................................. 427
6.55.7. Definition of Custom Style Classes ...................................................... 427
6.55.8. Relevant Resources Links ................................................................... 429
6.56. < rich:virtualEarth > ...................................................................................... 430
6.56.1. Description ......................................................................................... 430
6.56.2. Key Features ...................................................................................... 430
xiii
RichFaces Developer Guide
xiv
6.60.7. Skin Parameters Redefinition .............................................................. 472
6.60.8. Definition of Custom Style Classes ...................................................... 472
6.60.9. Relevant Resources Links ................................................................... 474
6.61. < rich:inputNumberSpinner > ........................................................................ 474
6.61.1. Description ......................................................................................... 474
6.61.2. Key Features ...................................................................................... 475
6.61.3. Creating the Component with a Page Tag ............................................ 478
6.61.4. Creating the Component Dynamically Using Java ................................. 479
6.61.5. Details of Usage ................................................................................. 479
6.61.6. Look-and-Feel Customization .............................................................. 480
6.61.7. Skin Parameters Redefinition .............................................................. 480
6.61.8. Definition of Custom Style Classes ...................................................... 481
6.61.9. Relevant Resources Links ................................................................... 482
6.62. < rich:insert > .............................................................................................. 483
6.62.1. Description ......................................................................................... 483
6.62.2. Key Features ...................................................................................... 483
6.62.3. Creating the Component with a Page Tag ............................................ 484
6.62.4. Creating the Component Dynamically Using Java ................................. 484
6.62.5. Details of Usage ................................................................................. 484
6.62.6. Look-and-Feel Customization .............................................................. 485
6.62.7. Relevant Resources Links ................................................................... 485
6.63. < rich:jQuery > ............................................................................................. 485
6.63.1. Description ......................................................................................... 485
6.63.2. Key Features ...................................................................................... 485
6.63.3. Creating the Component with a Page Tag ............................................ 486
6.63.4. Creating the Component Dynamically Using Java ................................. 487
6.63.5. Details of Usage ................................................................................. 487
6.63.6. Look-and-Feel Customization .............................................................. 491
6.63.7. Relevant Resources Links ................................................................... 491
6.64. < rich:listShuttle > ........................................................................................ 491
6.64.1. Description ......................................................................................... 491
6.64.2. Key Features ...................................................................................... 491
6.64.3. Creating the Component with a Page Tag ............................................ 495
6.64.4. Creating the Component Dynamically Using Java ................................. 495
6.64.5. Details of Usage ................................................................................. 495
6.64.6. JavaScript API .................................................................................... 500
6.64.7. Look-and-Feel Customization .............................................................. 500
6.64.8. Skin Parameters Redefinition .............................................................. 501
6.64.9. Definition of Custom Style Classes ...................................................... 503
6.64.10. Relevant Resources Links ................................................................. 507
6.65. < rich:message > ......................................................................................... 507
6.65.1. Description ......................................................................................... 507
6.65.2. Key Features ...................................................................................... 507
6.65.3. Creating the Component with a Page Tag ............................................ 510
xv
RichFaces Developer Guide
xvi
6.70. < rich:panel > .............................................................................................. 554
6.70.1. Description ......................................................................................... 554
6.70.2. Key Features ...................................................................................... 554
6.70.3. Creating the Component with a Page Tag ............................................ 555
6.70.4. Creating the Component Dynamically Using Java ................................. 556
6.70.5. Details of Usage ................................................................................. 556
6.70.6. Look-and-Feel Customization .............................................................. 558
6.70.7. Skin Parameters Redefinition .............................................................. 558
6.70.8. Definition of Custom Style Classes ...................................................... 559
6.70.9. Relevant Resources Links ................................................................... 561
6.71. < rich:panelBar > ......................................................................................... 561
6.71.1. Description ......................................................................................... 561
6.71.2. Key Features ...................................................................................... 561
6.71.3. Creating the Component with a Page Tag ............................................ 563
6.71.4. Creating the Component Dynamically Using Java ................................. 564
6.71.5. Details of Usage ................................................................................. 564
6.71.6. Look-and-Feel Customization .............................................................. 564
6.71.7. Skin Parameters Redefinition .............................................................. 564
6.71.8. Definition of Custom Style Classes ...................................................... 565
6.71.9. Relevant Resources Links ................................................................... 567
6.72. < rich:panelBarItem > ................................................................................... 567
6.72.1. Description ......................................................................................... 567
6.72.2. Key Features ...................................................................................... 567
6.72.3. Creating the Component with a Page Tag ............................................ 568
6.72.4. Creating the Component Dynamically Using Java ................................. 569
6.72.5. Details of Usage ................................................................................. 569
6.72.6. Look-and-Feel Customization .............................................................. 570
6.72.7. Skin Parameters Redefinition .............................................................. 570
6.72.8. Definition of Custom Style Classes ...................................................... 570
6.73. < rich:panelMenu > ...................................................................................... 573
6.73.1. Description ......................................................................................... 573
6.73.2. Key Features ...................................................................................... 573
6.73.3. Creating the Component with a Page Tag ............................................ 579
6.73.4. Creating the Component Dynamically Using Java ................................. 579
6.73.5. Details of Usage ................................................................................. 580
6.73.6. JavaScript API .................................................................................... 582
6.73.7. Look-and-Feel Customization .............................................................. 583
6.73.8. Definition of Custom Style Classes ...................................................... 583
6.73.9. Relevant Resources Links ................................................................... 585
6.74. < rich:panelMenuGroup > ............................................................................. 585
6.74.1. Description ......................................................................................... 585
6.74.2. Key Features ...................................................................................... 585
6.74.3. Creating the Component with a Page Tag ............................................ 591
6.74.4. Creating the Component Dynamically Using Java ................................. 591
xvii
RichFaces Developer Guide
xviii
6.78.7. Look-and-Feel Customization .............................................................. 640
6.78.8. Skin Parameters Redefinition .............................................................. 641
6.78.9. Definition of Custom Style Classes ...................................................... 642
6.78.10. Relevant Resources Links ................................................................. 646
6.79. < rich:separator > ........................................................................................ 646
6.79.1. Description ......................................................................................... 646
6.79.2. Key Features ...................................................................................... 646
6.79.3. Creating the Component with a Page Tag ............................................ 647
6.79.4. Creating the Component Dynamically Using Java ................................. 648
6.79.5. Details of Usage ................................................................................. 648
6.79.6. Look-and-Feel Customization .............................................................. 649
6.79.7. Definition of Custom Style Classes ...................................................... 649
6.79.8. Relevant Resources Links ................................................................... 650
6.80. < rich:simpleTogglePanel > ........................................................................... 650
6.80.1. Description ......................................................................................... 650
6.80.2. Key Features ...................................................................................... 651
6.80.3. Creating the Component with a Page Tag ............................................ 654
6.80.4. Creating the Component Dynamically Using Java ................................. 655
6.80.5. Details of Usage ................................................................................. 655
6.80.6. Look-and-Feel Customization .............................................................. 656
6.80.7. Skin Parameters Redefinition .............................................................. 656
6.80.8. Definition of Custom Style Classes ...................................................... 657
6.80.9. Relevant Resources Links ................................................................... 659
6.81. < rich:spacer > ............................................................................................ 659
6.81.1. Description ......................................................................................... 659
6.81.2. Key Features ...................................................................................... 660
6.81.3. Creating the Component with a Page Tag ............................................ 661
6.81.4. Creating the Component Dynamically Using Java ................................. 661
6.81.5. Details of Usage ................................................................................. 662
6.81.6. Look-and-Feel Customization .............................................................. 662
6.81.7. Relevant Resources Links ................................................................... 662
6.82. < rich:suggestionbox > ................................................................................. 662
6.82.1. Description ......................................................................................... 662
6.82.2. Key Features ...................................................................................... 663
6.82.3. Creating the Component with a Page Tag ............................................ 669
6.82.4. Creating the Component Dynamically Using Java ................................. 670
6.82.5. Details of Usage ................................................................................. 670
6.82.6. JavaScript API .................................................................................... 673
6.82.7. Look-and-Feel Customization .............................................................. 674
6.82.8. Skin Parameters Redefinition .............................................................. 674
6.82.9. Definition of Custom Style Classes ...................................................... 675
6.82.10. Relevant Resources Links ................................................................. 677
6.83. < rich:tabPanel > ......................................................................................... 677
6.83.1. Description ......................................................................................... 677
xix
RichFaces Developer Guide
xx
6.88. < rich:toolBarGroup > ................................................................................... 720
6.88.1. Description ......................................................................................... 720
6.88.2. Key Features ...................................................................................... 720
6.88.3. ......................................................................................................... 722
6.88.4. Creating the Component with a Page Tag ............................................ 722
6.88.5. Creating the Component Dynamically Using Java ................................. 723
6.88.6. Details of Usage ................................................................................. 723
6.88.7. Look-and-Feel Customization .............................................................. 724
6.88.8. Definition of Custom Style Classes ...................................................... 724
6.88.9. Relevant resources links ..................................................................... 725
6.89. < rich:toolTip > ............................................................................................ 725
6.89.1. Description ......................................................................................... 725
6.89.2. Key Features ...................................................................................... 725
6.89.3. Creating the Component with a Page Tag ............................................ 728
6.89.4. Creating the Component Dynamically Using Java ................................. 729
6.89.5. Details of Usage ................................................................................. 729
6.89.6. JavaScript API .................................................................................... 732
6.89.7. Look-and-Feel Customization .............................................................. 732
6.89.8. Skin Parameters Redefinition .............................................................. 732
6.89.9. Definition of Custom Style Classes ...................................................... 733
6.89.10. Relevant Resources Links ................................................................. 734
6.90. < rich:tree > ................................................................................................. 734
6.90.1. Description ......................................................................................... 734
6.90.2. Key Features ...................................................................................... 735
6.90.3. Creating the Component with a Page Tag ............................................ 741
6.90.4. Creating the Component Dynamically Using Java ................................. 741
6.90.5. Details of Usage ................................................................................. 742
6.90.6. Built-In Drag and Drop ........................................................................ 746
6.90.7. Events handling .................................................................................. 748
6.90.8. Look-and-Feel Customization .............................................................. 749
6.90.9. Skin Parameters Redefinition: ............................................................. 749
6.90.10. Definition of Custom Style Classes .................................................... 749
6.90.11. Relevant Resources Links ................................................................. 751
6.91. < rich:treeNode > ......................................................................................... 751
6.91.1. Description ......................................................................................... 751
6.91.2. Key Features ...................................................................................... 752
6.91.3. Creating the Component with a Page Tag ............................................ 756
6.91.4. Creating the Component Dynamically Using Java ................................. 756
6.91.5. Details of Usage ................................................................................. 757
6.91.6. Built-in Drag and Drop ........................................................................ 758
6.91.7. Events Handling ................................................................................. 758
6.91.8. Look-and-Feel Customization .............................................................. 758
6.91.9. Skin Parameters Redefinition .............................................................. 759
6.91.10. Definition of Custom Style Classes .................................................... 759
xxi
RichFaces Developer Guide
xxii
Chapter 1.
Introduction
RichFaces is an open source framework that adds Ajax capability into existing JSF applications
without resorting to JavaScript.
• Intensify the whole set of JSF benefits while working with Ajax. RichFaces is fully integrated into
the JSF lifecycle. While other frameworks only give you access to the managed bean facility,
RichFaces advantages the action and value change listeners, as well as invokes server-side
validators and converters during the Ajax request-response cycle.
• Add Ajax capability to the existing JSF applications. Framework provides two components
libraries (Core Ajax and UI). The Core library sets Ajax functionality into existing pages, so
there is no need to write any JavaScript code or to replace existing components with new Ajax
ones. RichFaces enables page-wide Ajax support instead of the traditional component-wide
support and it gives the opportunity to define the event on the page. An event invokes an Ajax
request and areas of the page which become synchronized with the JSF Component Tree after
changing the data on the server by Ajax request in accordance with events fired on the client.
• Create quickly complex View basing on out of the box components. RichFaces UI library
contains components for adding rich user interface features to JSF applications. It extends
the RichFaces framework to include a large (and growing) set of powerful rich Ajax-enabled
components that come with extensive skins support. In addition, RichFaces components are
designed to be used seamlessly with other 3d-party component libraries on the same page, so
you have more options for developing your applications.
• Write your own custom rich components with built-in Ajax support. We're always working on
improvement of Component Development Kit (CDK) that was used for RichFaces UI library
creation. The CDK includes a code-generation facility and a templating facility using a JSP-
like syntax. These capabilities help to avoid a routine process of a component creation.
The component factory works like a well-oiled machine allowing the creation of first-class
rich components with built-in Ajax functionality even more easily than the creation of simpler
components by means of the traditional coding approach.
• Package resources with application Java classes. In addition to its core, Ajax functionality of
RichFaces provides an advanced support for the different resources management: pictures,
JavaScript code, and CSS stylesheets. The resource framework makes possible to pack easily
these resources into Jar files along with the code of your custom components.
1
Chapter 1. Introduction
• Easily generate binary resources on-the-fly. Resource framework can generate images,
sounds, Excel spreadsheets etc.. on-the-fly so that it becomes for example possible to create
images using the familiar approach of the "Java Graphics2D" library.
• Create a modern rich user interface look-and-feel with skins-based technology. RichFaces
provides a skinnability feature that allows easily define and manage different color schemes
and other parameters of the UI with the help of named skin parameters. Hence, it is possible
to access the skin parameters from JSP code and the Java code (e.g. to adjust generated on-
the-fly images based on the text parts of the UI). RichFaces comes with a number of predefined
skins to get you started, but you can also easily create your own custom skins.
• Test and create the components, actions, listeners, and pages at the same time. An automated
testing facility is in our roadmap for the near future. This facility will generate test cases for your
component as soon as you develop it. The testing framework will not just test the components,
but also any other server-side or client-side functionality including JavaScript code. What is
more, it will do all of this without deploying the test application into the Servlet container.
RichFaces UI components come ready to use out-of-the-box, so developers save their time and
immediately gain the advantage of the mentioned above features in Web applications creation.
As a result, usage experience can be faster and easily obtained.
2
Chapter 2.
Technical Requirements
RichFaces was developed with an open architecture to be compatible with the widest possible
variety of environments.
• Java
• JavaServer Faces
• RichFaces framework
• MyFaces 1.2
• Resin 3.1
• Jetty 6.1.x
• Glassfish (J2EE 5)
3
Chapter 2. Technical Requirements
• JBoss 4.2.x - 5
• Safari 2.0-3.1
Note:
This list is composed basing on reports received from our users. We assume the list can be
incomplete and absence of your environment in the list doesn't mean incompatibility.
We appreciate your feedback on platforms and browsers that aren't in the list but are compatible
with RichFaces. It helps us to keep the list up-to-date.
4
Chapter 3.
http://labs.jboss.com/jbossrichfaces/downloads
in the RichFaces project area under JBoss.
3.2. Installation
• Add the following content into the "WEB-INF/web.xml" file of your application:
...
<context-param>
<param-name>org.richfaces.SKIN</param-name>
<param-value>blueSky</param-value>
</context-param>
<filter>
<display-name>RichFaces Filter</display-name>
<filter-name>richfaces</filter-name>
<filter-class>org.ajax4jsf.Filter</filter-class>
</filter>
<filter-mapping>
<filter-name>richfaces</filter-name>
<servlet-name>Faces Servlet</servlet-name>
<dispatcher>REQUEST</dispatcher>
<dispatcher>FORWARD</dispatcher>
<dispatcher>INCLUDE</dispatcher>
</filter-mapping>
• Add the following lines for each JSP page of your application.
5
Chapter 3. Getting Started wi...
<xmlns:a4j="http://richfaces.org/a4j">
<xmlns:rich="http://richfaces.org/rich">
This simple application let you input some text into the <h:inputText> , send data to the server,
and see the server response as a value of <h:outputText> .
Only two tags distinguish this page from a "regular" JSF one. There are <rich:panel> and
<a4j:support> .
The <rich:panel> allows to place the page elements in rectangle panel that can be skinned.
6
Data Bean
The <a4j:support> with corresponding attributes (as it was shown in the previous example) adds
an Ajax support to the parent <h:inputText> tag. This support is bound to "onkeyup" JavaScript
event, so that each time when this event is fired on the parent tag, our application sends an Ajax
request to the server. It means that the text field pointed to our managed bean property contains
up-to-date value of our input.
The value of "reRender" attribute of the <a4j:support> tag defines which part(s) of our page is
(are) to be updated. In this case, the only part of the page to update is the <h:outputText> tag
because its ID value matches to the value of "reRender" attribute. As you see, it's not difficult to
update multiple elements on the page, only list their IDs as the value of "reRender" .
package demo;
3.3.3. faces-config.xml
Next, it's necessary to register your bean inside of the faces-config.xml file:
7
Chapter 3. Getting Started wi...
<property-name>text</property-name>
<value/>
</managed-property>
</managed-bean>
</faces-config>
Note:
3.3.4. Web.xml
It is also necessary to add jar files (see installation chapter) and modify the "web.xml" file:
<?xml version="1.0"?>
<web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-
app_2_4.xsd">
<display-name>a4jEchoText</display-name>
<context-param>
<param-name>org.richfaces.SKIN</param-name>
<param-value>blueSky</param-value>
</context-param>
<context-param>
<param-name>javax.faces.STATE_SAVING_METHOD</param-name>
<param-value>server</param-value>
</context-param>
<filter>
<display-name>RichFaces Filter</display-name>
<filter-name>richfaces</filter-name>
<filter-class>org.ajax4jsf.Filter</filter-class>
</filter>
<filter-mapping>
<filter-name>richfaces</filter-name>
<servlet-name>Faces Servlet</servlet-name>
<dispatcher>REQUEST</dispatcher>
<dispatcher>FORWARD</dispatcher>
<dispatcher>INCLUDE</dispatcher>
</filter-mapping>
<listener>
<listener-class>com.sun.faces.config.ConfigureListener</listener-class>
8
Deployment
</listener>
3.3.5. Deployment
Finally, you should be able to place this application on your Web server.To start your project, point
your browser at http://localhost:8080/a4jEchoText/echo.jsf
9
10
Chapter 4.
11
Chapter 4. Settings for diffe...
12
Web Application Descriptor Parameters
13
Chapter 4. Settings for diffe...
Note:
java.sun.com [http://java.sun.com/javaee/javaserverfaces/]
14
Apache MyFaces
Additional information how to get ViewExpiredExceptions when using RichFaces with JSF 1.2
you can find here [http://wiki.jboss.org/auth/wiki//RichFacesCookbook/ViewExpiredException].
There are some problems with different filters defined in the web.xml file clashing. To avoid these
problems, the RichFaces filter must be the first one among other filters in the web.xml configuration
file.
There's one more problem while using MyFaces + Seam . If you use this combination you should
use <a4j:page> inside <f:view> (right after it in your code) wrapping another content inside
your pages because of some problems in realization of <f:view> in myFaces.
You should also take into account that some JSF frameworks such as Facelets use their
own ViewHandler and need to have it first in the chain of ViewHandlers and the RichFaces
AjaxViewHandler is not an exception. At first RichFaces installs its ViewHandler in any case, so in
case of two frameworks, for example RichFaces + Facelets, no changes in settings are required.
Although, when more then one framework (except RichFaces) is used, it's possible to use the
VIEW_HANDLERS parameter defining these frameworks view handlers according to its usage order
in it. For example, the declaration:
Example:
<context-param>
<param-name>org.ajax4jsf.VIEW_HANDLERS</param-name>
<param-value>com.sun.facelets.FaceletViewHandler</param-value>
</context-param>
says that Facelets will officially be the first, however AjaxViewHandler will be a little ahead
temporarily to do some small, but very important job.
15
Chapter 4. Settings for diffe...
Note:
<filter>
<display-name>RichFaces Filter</display-name>
<filter-name>richfaces</filter-name>
<filter-class>org.ajax4jsf.Filter</filter-class>
</filter>
<filter-mapping>
<filter-name>richfaces</filter-name>
<url-pattern>*.seam</url-pattern>
</filter-mapping>
<context-param>
<param-name>org.ajax4jsf.VIEW_HANDLERS</param-name>
<param-value>org.jboss.seam.ui.facelet.SeamFaceletViewHandler</param-value>
</context-param>
<listener>
<listener-class>org.jboss.seam.servlet.SeamListener</listener-class>
</listener>
16
JBoss Seam Support
<servlet>
<servlet-name>Seam Resource Servlet</servlet-name>
<servlet-class>org.jboss.seam.servlet.ResourceServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Seam Resource Servlet</servlet-name>
<url-pattern>/seam/resource/*</url-pattern>
</servlet-mapping>
<filter>
<filter-name>Seam Filter</filter-name>
<filter-class>org.jboss.seam.web.SeamFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>Seam Filter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<listener>
<listener-class>org.apache.myfaces.webapp.StartupServletContextListener</listener-class>
</listener>
<context-param>
<param-name>javax.faces.STATE_SAVING_METHOD</param-name>
<param-value>client</param-value>
</context-param>
<context-param>
<param-name>javax.faces.DEFAULT_SUFFIX</param-name>
<param-value>.xhtml</param-value>
</context-param>
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
17
Chapter 4. Settings for diffe...
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.seam</url-pattern>
</servlet-mapping>
</web-app>
Seam 2 supports RichFaces Filter. Thus your web.xml for Seam 2 must be like this:
<context-param>
<param-name>org.ajax4jsf.VIEW_HANDLERS</param-name>
<param-value>com.sun.facelets.FaceletViewHandler</param-value>
</context-param>
<listener>
<listener-class>org.jboss.seam.servlet.SeamListener</listener-class>
</listener>
<servlet>
<servlet-name>Seam Resource Servlet</servlet-name>
<servlet-class>org.jboss.seam.servlet.SeamResourceServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Seam Resource Servlet</servlet-name>
<url-pattern>/seam/resource/*</url-pattern>
</servlet-mapping>
<filter>
<filter-name>Seam Filter</filter-name>
<filter-class>org.jboss.seam.servlet.SeamFilter</filter-class>
</filter>
18
Portlet Support
<filter-mapping>
<filter-name>Seam Filter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<context-param>
<param-name>javax.faces.DEFAULT_SUFFIX</param-name>
<param-value>.xhtml</param-value>
</context-param>
<context-param>
<param-name>facelets.DEVELOPMENT</param-name>
<param-value>true</param-value>
</context-param>
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.seam</url-pattern>
</servlet-mapping>
</web-app>
Only one issue still persists while using Seam with MyFaces. Look at myFaces part of this section.
Detailed information on how to integrate Richfaces and Trinidad and how to hide ".seam" postfix
in the URL you can find here [http://wiki.jboss.org/auth/wiki/RichFacesWithTrinidad]
Example:
19
Chapter 4. Settings for diffe...
...
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>0</load-on-startup>
</servlet>
...
This is because, EAServer calls servlet init() before the ServletContextInitializer. Not an
EAServer bug, this is in Servlet 2.3 spec.
...
<imported-shared-libraries>
<remove-inherited name="oracle.xml"/>
<remove-inherited name="oracle.xml.security"/>
</imported-shared-libraries>
...
20
Chapter 5.
21
Chapter 5. Basic concepts of ...
RichFaces allows to define (by means of JSF tags) different parts of a JSF page you wish to
update with an Ajax request and provide a few options to send Ajax requests to the server. Also
JSF page doesn't change from a "regular" JSF page and you don't need to write any JavaScript
or XMLHTTPRequest objects by hands, everything is done automatically.
22
RichFaces Architecture Overview
Ajax Filter. To get all benefits of RichFaces , you should register a Filter in web.xml file of
your application. The Filter recognizes multiple request types. Necessary information about Filter
configuration can be found in the "Filter configuration" section. The sequence diagram on Figure
3 shows the difference in processing of a "regular" JSF request and an Ajax request.
In the first case the whole JSF tree will be encoded, in the second one option it depends on the
"size" of the Ajax region. As you can see, in the second case the filter parses the content of an
Ajax response before sending it to the client side.
23
Chapter 5. Basic concepts of ...
In both cases, the information about required static or dynamic resources that your application
requests is registered in the ResourseBuilder class.
When a request for a resource comes (Figure 4), the RichFaces filter checks the Resource Cache
for this resource and if it is there, the resource is sent to the client. Otherwise, the filter searches for
the resource among those that are registered by the ResourceBuilder. If the resource is registered,
the RichFaces filter will send a request to the ResourceBuilder to create (deliver) the resource.
24
Limitations and Rules
AJAX Containers. AjaxContainer is an interface that describes an area on your JSF page that
should be decoded during an Ajax request. AjaxViewRoot and AjaxRegion are implementations
of this interface.
JavaScript Engine. RichFaces JavaScript Engine runs on the client-side. It knows how to
update different areas on your JSF page based on the information from the Ajax response. Do
not use this JavaScript code directly, as it is available automatically.
• Any Ajax framework should not append or delete, but only replace elements on the page. For
successful updates, an element with the same ID as in the response must exist on the page.
25
Chapter 5. Basic concepts of ...
If you'd like to append any code to a page, put in a placeholder for it (any empty element). For
the same reason, it's recommended to place messages in the "AjaxOutput" component (as
no messages is also a message).
• Don't use <f:verbatim> for self-rendered containers, since this component is transient and
not saved in the tree.
• Ajax requests are made by XMLHTTPRequest functions in XML format, but this XML bypasses
most validations and the corrections that might be made in a browser. Thus, create only a strict
standards-compliant code for HTML and XHTML, without skipping any required elements or
attributes. Any necessary XML corrections are automatically made by the XML filter on the
server, but lot's of unexpected effects can be produced by an incorrect HTML code.
• The RichFaces ViewHandler puts itself in front of the Facelets ViewHandlers chain.
• RichFaces components uses their own renderers. On the Render Response Phase RichFaces
framework makes a traversal of the component tree, calls its own renderer and put the result
into the Faces Response.
"reRender" is a key attribute. The attribute allows to point to area(s) on a page that should be
updated as a response on Ajax interaction. The value of the "reRender" attribute is an id of the
JSF component or an id list.
...
<a4j:commandButton value="update" reRender="infoBlock"/>
...
<h:panelGrid id="infoBlock">
...
</h:panelGrid>
...
The value of "reRender" attribute of the <a4j:commandButton> tag defines which part(s) of your
page is (are) to be updated. In this case, the only part of the page to update is the <h:panelGrid>
26
Re-Rendering
tag because its ID value matches to the value of "reRender" attribute. As you see, it's not difficult
to update multiple elements on the page, only list their IDs as the value of "reRender" .
...
<h:form id="form1">
...
<a4j: commandButton value="Usual Way" reRender="infoBlock, infoBlock2" />
<a4j:commandButton value="Shortcut" reRender=":infoBlockl,:sv:infoBlock2" />
...
</h:form>
<h:panelGrid id="infoBlock">
...
</h:panelGrid>
...
<f:subview id="sv">
<h:panelGrid id="infoBlock2">
...
</h:panelGrid>
...
</f:subview>
...
It's also possible to use JSF EL expression as a value of the reRender attribute. It might be a
property of types Set, Collection, Array or simple String. The EL for reRender is resolved right
before the Render Response phase. Hence, you can calculate what should be re-rendered on
any previous phase during the Ajax request processing.
Most common problem with using reRender is pointing it to the component that has a "rendered"
attribute. Note, that JSF does not mark the place in the browser DOM where the outcome of the
component should be placed in case the "rendered" condition returns false. Therefore, after the
component becomes rendered during the Ajax request, RichFaces delivers the rendered code to
the client, but does not update a page, because the place for update is unknown. You need to
point to one of the parent components that has no "rendered" attribute. As an alternative, you
can wrap the component with <a4j:outputPanel> layout="none" .
27
Chapter 5. Basic concepts of ...
"ajaxRendered" attribute of the <a4j:outputPanel> set to "true" allows to define the area of the
page that will be re-rendered even if it is not pointed in the reRender attribute explicitly. It might be
useful if you have an area on a page that should be updated as a response on any Ajax request.
For example, the following code allows to output error messages regardless of what Ajax request
causes the Validation phase failed.
...
<a4j:outputPanel ajaxRendered="true">
<h:messages />
</a4j:outputPanel>
...
...
<h:form>
<h:inputText value="#{person.name}">
<a4j:support event="onkeyup" reRender="test" limitToList="true"/>
</h:inputText>
<h:outputText value="#{person.name}" id="test"/>
</form>
...
"eventsQueue" attribute defines the name of the queue that will be used to order upcoming
Ajax requests. By default, RichFaces does not queue Ajax requests. If events are produced
simultaneously, they will come to the server simultaneously. JSF implementations (especially, the
very first ones) does not guaranty that the request that comes first will be served or passed into
the JSF lifecycle first. The order how the server side data will be modified in case of simultaneous
request might be unpredictable. Usage of eventsQueue attribute allows to avoid possible mess.
Define the queue name explicitly, if you expect intensive Ajax traffic in your application.
The next request posted in the same queue will wait until the previos one is not processed and
Ajax Response is returned back if the "eventsQueue" attribute is defined. In addition, RichFaces
starts to remove from the queue "similar" requests. "Similar'"requests are the requests produced
by the same event. For example, according to the following code, only the newest request will be
sent to the server if you type very fast and has typed the several characters already before the
previous Ajax Response is back.
28
Data Processing Options
...
<h:inputText value="#{userBean.name}">
<a4j:support event="onkeyup" eventsQueue="foo" reRender="bar" />
</h:inputText>
...
"requestDelay" attribute defines the time (in ms) that the request will be wait in the queue before
it is ready to send. When the delay time is over, the request will be sent to the server or removed
if the newest "similar" request is in a queue already .
"ignoreDupResponses" attribute orders to ignore the Ajax Response produced by the 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 loses the actuality.
Defining the "eventsQueue" along with "requestDelay" allows to protect against unnecessary
traffic flood and synchronizes Ajax requests order. If you have several sources of Ajax requests,
you can define the same queue name there. This might be very helpful if you have Ajax
components that invoke request asynchronously from the ones produced by events from users.
For example, <a4j:poll> or <a4j:push> . In case the requests from such components modify
the same data, the synchronization might be very helpful.
"timeout" attribute is used for setting response waiting time on a particular request. If a response
is not received during this time, the request is aborted.
RichFaces uses form based approach for Ajax request sending. This means each time, when you
click an Ajax button or <a4j:poll> produces an asynchronous request, the data from the closest
JSF form is submitted with the XMLHTTPRequest object. The form data contains the values from
the form input element and auxiliary information such as state saving data.
When "ajaxSingle" attribute value is "true" , it orders to include only a value of the current
component (along with <f:param> or <a4j:action> param values if any) to the request map. In
case of <a4j:support> , it is a value of the parent component. An example is placed below:
...
<h:form>
<h:inputText value="#{person.name}">
<a4j:support event="onkeyup" reRender="test" ajaxSingle="true"/>
</h:inputText>
29
Chapter 5. Basic concepts of ...
<h:inputText value="#{person.middleName}"/>
</form>
...
In this example the request contains only the input component causes the request generation, not
all the components contained on a form, because of ajaxSingle="true" usage.
Note, that ajaxSingle="true" reduces the upcoming traffic, but does not prevent decoding other
input components on the server side. Some JSF components, such as <h:selectOneMenu> do
recognize the missing data in the request map value as a null value and try to pass the validation
process with a failed result. Thus, use <a4j:region> to limit a part of the component tree that will
be processed on the server side when it is required.
"immediate" attribute has the same purpose as any other non-JSF component. The default
"ActionListener" should be executed immediately (i.e. during the Apply Request Values phase
of a request processing lifecycle), rather than waiting until the Invoke Application phase. Using
immediate="true" is one of the ways to have some data model values updated when other
cannot be updated because of a problem with passing the Validation phase successfully. This
might be important inside the <h:dataTable> like components where using <a4j:region> is
impossible due to the <h:dataTable> component architecture.
"bypassUpdates" attribute allows to bypass the Update Model phase. It might be useful if you need
to check your input against the available validator, but not to update the model with those data.
Note, that an action will be invoked at the end of the Validation phase only if the Validation phase
is passed successfully. The listeners of the Application phase will not be invoked in any case.
"action" method must return null if you want to have an Ajax Response with a partual page update.
This is regular mode called "Ajax request generates Non-Ajax Response". In case of action
does not return null, but the action outcome that matches one of navigation rules, RichFaces starts
to work in "Ajax request generates Non-Ajax Response" mode. This mode might be helpful
in two major cases:
• RichFaces allows to organize a page flow inside the <a4j:include> component. This is a
typical scenario for Wizard like behavior. The new content is rendered inside the <a4j:include>
area. The content is taken from the navigation rule of the faces configuration file (usually, the
faces-config.xml). Note, that the content of the "wizard" is not isolated from the rest of the page.
The included page should not have own <f:view> (it does not matter if you use facelets). You
need to have an Ajax component inside the <a4j:include> to navigate between the wizard
pages. Otherwize, the whole page update will be performed.
30
JavaScript Interactions
• If you want to involve the server side validators and navigate to the next page only if
the Validation phase is passed successfully, you can replace <h:commandButton> with
<a4j:commandButton> and point to the action method that navigates to the next page. If
Validation process fails, the partial page update will occur and you will see an error message.
Otherwize, the application proceeds to the next page. Make sure, you define <redirect/> option
for the navigation rule to avoid memory leaks.
RichFaces allows writing Ajax-enabled JSF application without writing any Javascript code.
However, you can still invoke the JavaScript code if you need. There are several ajax attributes
that helps to do it.
"onsubmit" attribute allows to invoke JavaScript code before an Ajax request is sent. If "onsubmit"
returns "false" , the Ajax request is canceled. The code of "onsubmit" is inserted before the
RichFaces Ajax call. Hence, the "onsubmit" should not has a "return" statement if you want
the Ajax request to be sent. If you are going to invoke a JavaScript function that returns "true"
or "false" , use the conditional statement to return something only when you need to cancel the
request. For example:
...
onsubmit="if (mynosendfunct()==false){return false}"
...
"onclick" attribute is similar to the "onsubmit" , but for clickable components such as
<a4j:commandLink> and <a4j:commandButton> . If it returns "false" , the Ajax request is
canceled also.
"oncomplete" attribute allows to invoke the JavaScript code right after the Ajax Response is
returned back and the DOM tree of the browser is updated. RichFaces registers the code for
further invocation of XMLHTTP request object before an Ajax request is sent. This means the
code will not be changed during processing of the request on the server if you use JSF EL value
binding. Also, you cannot use "this'" inside the code, because it will not point the component where
Ajax request was initiated.
"onbeforedomupdate" attribute defines JavaScript code for call after Ajax response receiving and
before updating DOM on a client side.
"data" attribute allows to get the additional data from the server during an Ajax call. You can use
JSF EL to point the property of the managed bean and its value will be serialized in JSON format
and be available on the client side. You can refer to it using the "data" variable. For example:
...
31
Chapter 5. Basic concepts of ...
RichFaces allows to serialize not only primitive types into JSON format, but also complex types
including arrays and collections. The beans should be serializable to be refered with "data" .
• rich:clientId('id') - returns client id by short id or null if the component with the id specified
hasn't been found
...
<h:inputText id="myInput">
<a4j:support event="onkeyup" reRender="outtext"/>
</h:inputText>
<h:outputText id="outtext" value="#{rich:findComponent('myInput').value}" />
...
...
<a4j:poll intervall="1000" action="#{repeater.action}" reRender="text">
<table>
<tbody>
<a4j:repeat value="#{bean.props}" var="detail" ajaxKeys="#{repeater.ajaxedRowsSet}">
<tr>
<td>
<h:outputText value="detail.someProperty" id="text"/>
</td>
</tr>
</a4j:repeat>
32
Other useful attributes
</tbody>
</table>
</a4j:poll>
...
...
<a4j:region id="extr">
<h:form>
<h:outputText value="Status:" />
<a4j:status id="commonstatus" startText="In Progress...." stopText=""/>
<h:panelGrid columns="2">
<h:outputText value="Name"/>
<h:inputText id="name" value="#{userBean.name}">
<a4j:support event="onkeyup" reRender="out" />
</h:inputText>
<h:outputText value="Job"/>
<a4j:region id="intr">
<h:inputText id="job" value="#{userBean.job}">
<a4j:support event="onkeyup" reRender="out" status="commonstatus"/>
</h:inputText>
</a4j:region>
</h:panelGrid>
<a4j:region>
<h:outputText id="out" value="Name: #{userBean.name}, Job: #{userBean.job}" />
<br />
<a4j:commandButton ajaxSingle="true" value="Clean Up Form" reRender="name,
job, out" status="commonstatus">
<a4j:actionparam name="n" value="" assignTo="#{userBean.name}" />
<a4j:actionparam name="j" value="" assignTo="#{userBean.job}" />
</a4j:commandButton>
</a4j:region>
</h:form>
</a4j:region>
...
33
Chapter 5. Basic concepts of ...
Other useful attribute is "focus" . It points to an ID of a component where focus will be set after
an Ajax request.
All these tags hide the usual JavaScript activities that are required for an XMHTTPRequest object
building and an Ajax request sending. Also, they allow you to decide which components of your
JSF page are to be re-rendered as a result of the Ajax response (you can list the IDs of these
components in the "reRender" attribute).
The <a4j:support> tag allows you to add Ajax functionality to standard JSF components and
send Ajax request onto a chosen JavaScript event: "onkeyup" , "onmouseover" , etc.
The easiest way to describe an Ajax region on your JSF page is to do nothing, because the content
between the <f:view> and </f:view> tags is considered the default Ajax region.
You may define multiple Ajax regions on the JSF page (they can even be nested) by using the
<a4j:region> tag.
If you wish to render the content of an Ajax response outside of the active region then the value
of the "renderRegionOnly" attribute should be set to "false" ("false" is default value). Otherwise,
your Ajax updates are limited to elements of the active region.
34
Decide what to process
But you can not use this approach if your page contains, e.g. a <f:verbatim> tag and you wish
to update its content on an Ajax response.
The problem with the <f:verbatim/> tag as described above is related to the value of the
transientFlag of JSF components. If the value of this flag is true, the component must not
participate in state saving or restoring of process.
In order to provide a solution to this kind of problems, RichFaces uses the concept of an output
panel that is defined by the <a4j:outputPanel> tag. If you put a <f:verbatim> tag inside of the
output panel, then the content of the <f:verbatim/> tag and content of other panel's child tags
could be updated on Ajax response. There are two ways to control this:
• By setting the "reRender" attribute value of an Action Component to the output panel ID.
The "process" attribute allows to define the ids of components to be processed together with the
component which is marked as ajaxSingle or wrapped to region.
You could make use of the "process" attribute when you need to process only two components
in the different parts of view.
Imagine you need to process only two input fields but not all the view. If you wrap the first input
to region or make <a4j:support> component with ajaxSingle="true" nested the second input
will not be processed.
...
<h:inputText value="#{bean.name}" id="name">
<a4j:support ajaxSingle="true" process="email" event="onblur" reRender="someOut"/>
</h:inputText>
<h:inputTextarea value="#{bean.description}" id="desc" />
<h:inputText value="#{bean.email}" id="email">
<a4j:support ajaxSingle="true" process="name" event="onblur" reRender="someOut"/>
</h:inputText>
...
In the example above when the input field with the id="name" looses focus, an AJAX request is
sent. So only two input fields (with id="name" and additionally with id="email") are processed:
decoding, conversion/validation, value applying phases are executed. The input field with the
id="email" is handled the same way on blur event.
35
Chapter 5. Basic concepts of ...
An example of how to set a Filter in a web.xml file of your application is placed below.
Example:
...
<filter>
<display-name>RichFaces Filter</display-name>
<filter-name>richfaces</filter-name>
<filter-class>org.ajax4jsf.Filter</filter-class>
</filter>
...
Note:
Fast Filter is deprecated and available only for backward compatibility with previous
RichFaces versions. Fast Filter usage isn't recomended, because there is another
way to use its functionality by means of Neko filter type [36] .
In RichFaces 3.2 filter configuration becomes more flexible. It's possible to configure different
filters for different sets of pages for the same application.
• TIDY
"TIDY" filter type based on the Tidy parser. This filter is recommended for applications with
complicated or non-standard markup when all necessary code corrections are made by the filter
when a response comes from the server.
• NEKO
"NEKO" filter type corresponds to the former "Fast Filter" and it's based on the Neko parser. In
case of using this filter code isn't strictly verified. Use this one if you are sure that your application
markup is really strict for this filter. Otherwise it could cause lot's of errors and corrupt a layout as
a result. This filter considerably accelerates all Ajax requests processing.
36
Filter Configuration
• NONE
No correction.
Example:
...
<context-param>
<param-name>org.ajax4jsf.xmlparser.ORDER</param-name>
<param-value>NONE,NEKO,TIDY</param-value>
</context-param>
<context-param>
<param-name>org.ajax4jsf.xmlparser.NONE</param-name>
<param-value>/pages/performance\.xhtml,/pages/default.*\.xhtml</param-value>
</context-param>
<context-param>
<param-name>org.ajax4jsf.xmlparser.NEKO</param-name>
<param-value>/pages/repeat\.xhtml</param-value>
</context-param>
<filter>
<display-name>RichFaces Filter</display-name>
<filter-name>richfaces</filter-name>
<filter-class>org.ajax4jsf.Filter</filter-class>
</filter>
<filter-mapping>
<filter-name>richfaces</filter-name>
<servlet-name>Faces Servlet</servlet-name>
<dispatcher>FORWARD</dispatcher>
<dispatcher>REQUEST</dispatcher>
<dispatcher>INCLUDE</dispatcher>
</filter-mapping>
...
The example shows that ORDER parameter defines the order in which particular filter types are
used for pages code correction.
First of all "NONE" type is specified for the filter. Then two different sets of pages are defined for
which two filter types (NONE and NEKO) are used correspondingly. If a page relates to the first
set that is defined in the following way:
37
Chapter 5. Basic concepts of ...
<param-value>/pages/performance\.xhtml,/pages/default.*\.xhtml</param-value>,
it's not corrected, because filter type for this page is defined as "NONE". If a page is not from the
first set, then "NEKO" type is set.
If a page relates to the second set that is defined in the following way:
<param-value>/pages/repeat\.xhtml</param-value>,
then "NEKO" filter type is used for correction. If it's not related to the second set, "TIDY" type is
set for the filter ("TIDY" filter type is used for code correction).
org.richfaces.LoadScriptStrategy
The following declaration in your web.xml allows loading the integrated script files.
...
<context-param>
<param-name>org.richfaces.LoadScriptStrategy</param-name>
<param-value>ALL</param-value>
</context-param>
...
...
<context-param>
<param-name>org.richfaces.LoadScriptStrategy</param-name>
<param-value>DEFAULT</param-value>
</context-param>
...
The third possible value is "NONE". You have no a special reason to use it unless you obtain the
newest (or modified) version of the script and want to include it manually in a page header.
38
Request Errors and Session Expiration
Handling
Note:
If you use ALL value of Scripts Load Strategy, the JavaScript files compression
turns off!
org.richfaces.LoadStyleStrategy
The following declaration allows to load only one integrated style sheet file.
...
<context-param>
<param-name>org.richfaces.LoadStyleStrategy</param-name>
<param-value>ALL</param-value>
</context-param>
...
The integrated style sheet contains style for all shipped components. The skinnability feature still
works.
The "NONE" stops loading the styles at all. The earlier introduced plain skin resets all color and
font parameters to null. The "NONE" value for org.richfaces.LoadStyleStrategy means that
predefined styles for RichFaces are not used.
<context-param>
<param-name>org.ajax4jsf.handleViewExpiredOnClient</param-name>
<param-value>true</param-value>
</context-param>
39
Chapter 5. Basic concepts of ...
To execute your own code on the client in case of an error during Ajax request, it's necessary to
redefine the standard "A4J.AJAX.onError" method:
A4J.AJAX.onError = function(req,status,message){
window.alert("Custom onError handler "+message);
}
Thus, it's possible to create your own handler that is called on timeouts, inner server errors, and
etc.
It's possible to redefine also the "onExpired" framework method that is called on the "Session
Expiration" event.
Example:
A4J.AJAX.onExpired = function(loc,expiredMsg){
if(window.confirm("Custom onExpired handler "+expiredMsg+" for a location: "+loc)){
return loc;
} else {
return false;
}
}
40
Skinnability
5.9. Skinnability
Hence, if you want to change the application palette, you have to change all interrelating values,
otherwise your interface can appear a bit clumsy. The chances of such an interface coming
about is very high, as CSS editing usually becomes the duty of a general developer who doesn't
necessarily have much knowledge of user interface design.
Moreover, if a customer wishes to have an interface look-and-feel that can be adjusted on-the-fly
by an end user, your work is multiplied, as you have to deal with several CSS files variants, each
of which contains the same values repeated numerous times.
These problems can be solved with the skinnability system built into the RichFaces project and
realized fully in RichFaces. Every named skin has some skin-parameters for the definition of a
palette and the other parameters of the user interface. By changing just a few parameters, you
can alter the appearance of dozens of components in an application in a synchronized fashion
without messing up user interface consistency.
The skinnability feature can't completely replace standard CSS and certainly doesn't eliminate
its usage. Skinnability is a high-level extension of standard CSS, which can be used together
with regular CSS declarations. You can also refer to skin parameters in CSS via JSF Expression
Language. You have the complete ability to synchronize the appearance of all the elements in
your pages.
The color scheme of the component can be applied to its elements using any of three style classes:
41
Chapter 5. Basic concepts of ...
This contains style parameters linked to some constants from a skin. It is defined for every
component and specifies a default representation level. Thus, an application interface could be
modified by changing the values of skin parameters.
This class name is defined for every component element and inserted into the framework to
allow defining a class with the same name into its CSS files. Hence, the appearance of all
components that use this class is extended.
It's possible to use one of the styleClass parameters for component elements and define your
own class in it. As a result, the appearance of one particular component is changed according
to a CSS style parameter specified in the class.
5.9.3. Example
Example:
The code generates a panel component on a page, which consists of two elements: a wrapper
<div> element and a <div> element for the panel body with the particular style properties. The
wrapper <div> element looks like:
Example:
It's possible to change all colors for all panels on all pages by changing these skin parameters.
42
Skin Parameters Tables in RichFaces
However, if a <rich:panel> class is specified somewhere on the page, its parameters are also
acquired by all panels on this page.
A developer may also change the style properties for a particular panel. The following definition:
Example:
Could add some style properties from customClass to one particular panel, as a result we get
three styles:
Example:
RichFaces provides eight predefined skin parameters (skins) at the simplest level of common
customization:
• DEFAULT
• plain
• emeraldTown
• blueSky
• wine
• japanCherry
• ruby
• classic
• deepMarine
43
Chapter 5. Basic concepts of ...
To plug one in, it's necessary to specify a skin name in the org.richfaces.SKIN context-param.
Here is an example of a table with values for one of the main skins, "blueSky" .
44
Creating and Using Your Own Skin File
Skin "plain" was added from 3.0.2 version. It doesn't have any parameters. It's necessary for
embedding RichFaces components into existing projecst which have its own styles.
To get detailed information on particular parameter possibilities, see the chapter where each
component has skin parameters described corresponding to its elements.
• Create a file and define in it skin constants which are used by style classes (see section
"Skin Parameters Tables in RichFaces" ). The name of skin file should correspond to the
following format: <name>.skin.properties . As an example of such file you can see RichFaces
predefined skin parameters (skins): blueSky, classic, deepMarine, etc. These files are located
in the richfaces-impl-xxxxx.jar inside the /META-INF/skins folder.
• Add a skin definition <contex-param> to the web.xml of your application. An example is placed
below:
Example:
...
<context-param>
<param-name>org.richfaces.SKIN</param-name>
<param-value>name</param-value>
</context-param>
...
• Put your <name>.skin.properties file in one of the following classpath elements: META-INF/
skins/ or classpath folder (e.g. WEB-INF/classes).
45
Chapter 5. Basic concepts of ...
skins that are applied consistently to a whole set of components. You can look at examples of
predefined skins at:
http://livedemo.exadel.com/richfaces-demo/ [http://livedemo.exadel.com/richfaces-demo/]
You may simply control the look-and-feel of your application by using the skinnability service of the
RichFaces framework. With the means of this service you can define the same style for rendering
standard JSF components and custom JSF components built with the help of RichFaces.
• Create a custom render kit and register it in the faces-config.xml like this:
<render-kit>
<render-kit-id>NEW_SKIN</render-kit-id>
<render-kit-class>
org.ajax4jsf.framework.renderer.ChameleonRenderKitImpl
</render-kit-class>
</render-kit>
• Then you need to create and register custom renderers for the component based on the look-
and-feel predefined variables:
<renderer>
<component-family>javax.faces.Command</component-family>
<renderer-type>javax.faces.Link</renderer-type>
<renderer-class>
newskin.HtmlCommandLinkRenderer
</renderer-class>
</renderer>
• Finally, you need to place a properties file with skin parameters into the class path root. There
are two requirements for the properties file:
• The first line in this file should be render.kit=<render-kit-id> in this case, it would be
called render.kit=NEW_SKIN .
http://java.sun.com/javaee/javaserverfaces/reference/docs/index.html [http://java.sun.com/
javaee/javaserverfaces/reference/docs/index.html]
46
Standard controls skinning
Standard controls skinning feature provides 2 levels of skinning - standard and extended, while
skinning is based on detecting browser user agent. If user agent is not detected, Advanced level
is used.
• Internet Explorer 6
• Opera
• Safari
• Extended extends basic level introducing broader number of style properties and is applied to
browsers with rich visual styling capability of controls
• Mozilla Firefox
• input
• select
• textarea
• keygen
• isindex
• legend
• fieldset
47
Chapter 5. Basic concepts of ...
• hr
Example:
...
.rich-container select {
//class content
}
...
• Elements that have class name corresponding to one of the basic elements name/type mapped
by the following scheme rich-<elementName>[-<elementType>] . See the example:
Example:
...
.rich-select {
//class content
}
.rich-input-text {
//class content
48
Standard controls skinning
...
Note:
a elements have classes based on "link" and pseudo class name, e.g.: rich-link,
rich-link-hover, rich-link-visited
Additionally, the predefined rich CSS classes that we provide can be used not only as classes for
basic HTML elements but also as classes for creation of complex elements .
...
<u:selector name=".rich-box-bgcolor-header">
<u:style name="background-color" skin="headerBackgroundColor" />
</u:selector>
<u:selector name=".rich-box-bgcolor-general">
<u:style name="background-color" skin="generalBackgroundColor" />
</u:selector>
...
//gradient elements
...
<u:selector name=".rich-gradient-menu">
<u:style name="background-image">
<f:resource f:key="org.richfaces.renderkit.html.gradientimages.MenuGradientImage"/>
</u:style>
<u:style name="background-repeat" value="repeat-x" />
</u:selector>
<u:selector name=".rich-gradient-tab">
<u:style name="background-image">
<f:resource f:key="org.richfaces.renderkit.html.gradientimages.TabGradientImage"/>
</u:style>
<u:style name="background-repeat" value="repeat-x" />
</u:selector>
...
To get a better idea of standard component skinning we recommend to explore CSS files located
in ui/core/src/main/resources/org/richfaces/ folder of RichFaces svn.
49
Chapter 5. Basic concepts of ...
Table 5.3. Html Elements Skin Bindings for input, select, textarea, button,
keygen, isindex, legend
50
Standard controls skinning
51
Chapter 5. Basic concepts of ...
52
Standard controls skinning
Table 5.23. Html Elements Skin Bindings for input, select, textarea, button,
keygen, isindex
53
Chapter 5. Basic concepts of ...
54
Standard controls skinning
button[type="submit"][disabled], input[type="reset"][disabled],
input[type="submit"][disabled], input[type="button"][disabled]
55
Chapter 5. Basic concepts of ...
However, if a develop doesn't want to the rich components and standard HTML controls to be
skinned automatically and perform the skinnability implementation himself, he might encounter
with a problem, i.e. standard HTML controls in such browsers as Opera and Safari are affected by
standard controls skinning featured. ( Here you can get more details on how to disable skinnability.)
In brief, to disable the skinnability mechanism of RichFaces you need to set the
"org.richfaces.LoadStyleStrategy" parameter to "NONE" in web.xml.
...
<context-param>
<param-name>org.richfaces.LoadStyleStrategy</param-name>
<param-value>NONE</param-value>
</context-param>
...
Additionally, you should include the style sheets that perform skinning of the rich component and
standard HTML controls.
In order to resolve the problem with extended skinning in Opera and Safari a client script
(skinning.js) is added to the RichFaces library. The script detects the browser type and enables
extended skinning only for those browsers that fully support it.
The script can be activated by inserting this JavaScript code to the page:
<script type="text/javascript">
window.RICH_FACES_EXTENDED_SKINNING_ON = true;
</script>
You also need to specify "media" attribute in the <link> tag which includes the
"extended_both.xcss" style sheet with "rich-extended-skinning".
56
XCSS file format
This is how you can include the style sheets to the page, in case automatic skinnability
implementation is disabled.
<link href='/YOUR_PROJECT_NAME/a4j_3_2_2-SNAPSHOTorg/richfaces/renderkit/html/css/
basic_both.xcss/DATB/eAF7sqpgb-jyGdIAFrMEaw__.jsf' type='text/css' rel='stylesheet'
class='component' />
<link media='rich-extended-skinning' href='/ YOUR_PROJECT_NAME /a4j_3_2_2-
SNAPSHOTorg/richfaces/renderkit/html/css/extended_both.xcss/DATB/eAF7sqpgb-
jyGdIAFrMEaw__.jsf' type='text/css' rel='stylesheet' class='component' />
<link href='/ YOUR_PROJECT_NAME /a4j_3_2_2-SNAPSHOT/org/richfaces/skin.xcss/DATB/
eAF7sqpgb-jyGdIAFrMEaw__.jsf' type='text/css' rel='stylesheet' class='component' />
Note
XCSS is an XML formatted CSS that adds extra functionality to the skinning process
XCSS extends skinning possibilities by parsing the XCSS file that contains all look-and-feel
parameters of a particular component into a standard CSS file that a web browser can recognize.
XCSS file contains CSS properties and skin parameters mappings. Mapping of a CSS selector
to a skin parameter is performed using < u:selector > and < u:style> XML tags that form the
mapping structure. Please study the example below.
...
<u:selector name=".rich-component-name">
<u:style name="background-color" skin="additionalBackgroundColor" />
<u:style name="border-color" skin="tableBorderColor" />
<u:style name="border-width" skin="tableBorderWidth" />
<u:style name="border-style" value="solid" />
</u:selector>
...
During processing the code in the shown example will be parsed into a standard CSS format.
57
Chapter 5. Basic concepts of ...
...
.rich-component-name {
background-color: additionalBackgroundColor; /*the value of the constant defined by your skin*/
border-color: tableBorderColor; /*the value of the constant defined by your skin*/
border-width: tableBorderWidth /*the value of the constant defined by your skin*/
border-style: solid;
}
...
The "name" attribute of <u:selector> tag defines the CSS selector, while "name" attribute of
the <u:style> tag defines what skin constant is mapped to a CSS property. The "value" attribute
of the <u:style> tag can also be used to assign a value to a CSS property.
CSS selectors with identical skinning properties can be set as a comma separated list.
...
<u:selector name=".rich-ordering-control-disabled, .rich-ordering-control-top, .rich-ordering-
control-bottom, .rich-ordering-control-up, .rich-ordering-control-down">
<u:style name="border-color" skin="tableBorderColor" />
</u:selector>
...
5.9.10. Plug-n-Skin
Plug-n-Skin is a feature that gives a developer an opportunity to easily create, customize and plug
into a project a custom skin. The skin can be created basing on parameters of some predefined
RichFaces skin.
The feature also provides an option to unify the appearance of rich controls with standard HTML
elements.
In order to create your own skin using Plug-n-Skin feature, you can follow these step by step
instructions.
First of all, you need to create a template for the new skin. Creation of the template can be
performed using Maven build and deployment tool. More information on how to configure Maven
for RichFaces here [http://wiki.jboss.org/wiki/HowToConfigureMavenForRichFaces] . You can
copy and paste these Maven instructions to command line and execute them.
...
mvn archetype:create
-DarchetypeGroupId=org.richfaces.cdk
58
Plug-n-Skin
-DarchetypeArtifactId=maven-archetype-plug-n-skin
-DarchetypeVersion=RF-VERSION
-DartifactId=ARTIFACT-ID
-DgroupId=GROUP-ID
-Dversion=VERSION
...
After this operation, a folder with the name of your "ARTIFACT-ID" appears. The folder contains
a template of Maven project.
Next steps will guide you though creating of the skin itself.
In the root folder of Maven project (the one that contains "pom.xml" file) you should run the
following command in the command line:
...
mvn cdk:add-skin -Dname=SKIN-NAME -Dpackage=SKIN-PACKAGE
...
• Dpackage base package of the skin. By default "groupId" of the project is used.
• DcreateExt if set to "true", extended CSS classes are added. For more information, please,
see "Standard controls skinning"
As a result of the performed operations the following files and folders are created:
59
Chapter 5. Basic concepts of ...
• XCSS files - XCSS files define the new look of RichFaces components affected by the new skin.
Location: "\src\main\resources\SKIN-PACKAGE\SKIN-NAME\css\"
• SKIN-NAME.properties - a XCSS file that contains properties of the new skin. Location:
"\src\main\resources\SKIN-PACKAGE\SKIN-NAME\css\"
• baseSkin – the name of the base skin to be used as basis. The look of the skin you define
will be affected by new style properties.
• generalStyleSheet - a path to the style sheet (SKIN-NAME.xcss) that imports style sheets of
the components to be affected by the new skin.
• extendedStyleSheet - a path to a style sheet that is used to unify the appearance of RichFaces
components and standard HTML controls. For additional information please read "Standard
controls skinning" chapter.
• gradientType is a predefined property to set the type of gradient applied to the new skin.
Possible values are glass, plastic, plain. More information on gradient implementation you
can find further in this chapter.
• SKIN-NAME.xcss - a XCSS file that imports XCSS files of the components to be affected by
the new skin. Location: "src\main\resources\META-INF\skins "
• XCSS files If the command is executed with the "DcreateExt" key set to "true", the XCSS
(extended_classes.xcss and extended.xcss) files that define style for standard controls will be
created. Location: "\src\main\resources\SKIN-PACKAGE\SKIN-NAME\css\".
• SKIN-NAME-ext.xcss / If the command is executed with the "DcreateExt" key set to "true", the
configuration SKIN-NAME-ext.xcss file that imports XCSS file defining styles for the standard
controls will be created. Location: "src\main\resources\META-INF\skins ".
• SKIN-NAME-resources.xml - the file contains the description of all listed above files. Location:
"src\main\config\resources ".
Now you can start editing the XCSS files located in "\src\main\resources\SKIN-PACKAGE\SKIN-
NAME\css\". New style properties can be assigned to the selectors (the selectors listed in the
XCSS files) in two ways, which are both valid, and it'up to the developer what way to choose.
• Applying a standard CSS coding approach, i.e. you can add css properties to the given selectors
are you normally do while doing CSS coding. The only thing, you have to keep in mind is that
the selectors must be inside <f:verbatim> <![CDATA[ ...]]> </f:verbatim> tags.
60
Plug-n-Skin
For example
...
.rich-calendar-cell {
background: #537df8;
}
...
• Using XCSS coding approach, the same way as XCSS files are normally formed in RichFaces.
The XCSS tags have to be placed outside <f:verbatim> <![CDATA[ ...]]> </f:verbatim>
tags.
...
<u:selector name=".rich-calendar-cell">
<u:style name="border-bottom-color" skin="panelBorderColor"/>
<u:style name="border-right-color" skin="panelBorderColor"/>
<u:style name="background-color" skin="tableBackgroundColor"/>
<u:style name="font-size" skin="generalSizeFont"/>
<u:style name="font-family" skin="generalFamilyFont"/>
</u:selector>
...
Having performed described above steps and edited the XCSS files you can proceed to building
the new skin and to plugging it into the project. Building the new skin can be done by executing
the given below command in the command line in the root folder of you skin project (the one that
contains pom.xml file).
...
mvn clean install
...
In addition Plug-n-Skin has a number of predefined gradients that you can also use to make your
application look nicer. The given below code snippet shows how a gradient can be used
...
<u:selector name=".rich-combobox-item-selected">
<u:style name="border-width" value="1px" />
61
Chapter 5. Basic concepts of ...
So, as you can see, the background-image CSS property is defined with <f:resource
f:key="org.richfaces.renderkit.html.CustomizeableGradient"> that sets the gradient.
While the gradient type can be specified in the SKIN-NAME.properties file with gradientType
property. The gradientType property can be set to one of the possible values glass, plastic, plain.
The gradient in it's turn can be can be adjusted using baseColor, gradientColor, gradientHeight,
valign attributes. Their usage is shown in the snippet above.
Now, you can use your newly-created and customized skin in your project by adding your new
skin parameters to web.xml file and placing the jar file with your skin ( the jar file is located in
"target" folder of your skin project) to "\WebContent\WEB-INF\lib\".
...
<context-param>
<param-name>org.ajax4jsf.SKIN</param-name>
<param-value>SKIN-NAME</param-value>
</context-param>
...
This section will cover some practical aspects of Plug-n-Skin implementation. It's assumed that
you have read the section of the guide that tells how the new skin using Plug-n-Skin prototype
can be created.
Above all, we need to create a new skin, in order to do that we just have to follow the steps
described in the previous section.
This command will be used to create a template of the new skin project.
62
Plug-n-Skin
mvn archetype:create
-DarchetypeGroupId=org.richfaces.cdk
-DarchetypeArtifactId=maven-archetype-plug-n-skin
-DarchetypeVersion=3.3.0-SNAPSHOT
-DartifactId=P-n-S
-DgroupId=GROUPID
-Dversion=1.0.-SNAPSHOT
Now you can browse the "P-n-S" folder to view what files and folders were created there.
Next, we will use Maven to add all needed files to the skin project. This will done by the following
command:
As you remember from the previous section "-DbaseSkin" key defines what RichFaces built-in
skin to be used as a base one, "-DcreateExt=true" determines that the new skin will come with
XCSS files that unify the look of the rich components with standard HTML controls.
So, now the files and folder with all needed resources are created and redefining/editing the new
skin can be started.
Now we can start editing XCSS files of the rich components. In order to see how the Plug-n-Skin
feature works we will change some style attributes of <rich:calendar> and some basic HTML
controls to see how they are affected by standard controls skinning.
• Recolor the current day's cell background of the <rich:calendar> to see how the new skin
created with the help of Plug-n-Skin feature affects the style of the component;
In oder to edit the style properties of <rich:calendar> you need to open the "calendar.xcss" file
located in "P-n-S\src\main\resources\skinpackage\plugnskindemo\css\". Once, you have opened
the file, please find ".rich-calendar-today" selector and amend it as follows: background-color:
#075ad1;. The current day's background color can be considered recolored.
Now we will see how font style of a standard HTML submit button can be changed. Please,
open "extended.xcss" file located in "P-n-S\src\main\resources\skinpackage\plugnskindemo\css\"
and put in font-weight: bold; inside the curly braces of these coma separated
selectors button[type="button"], button[type="reset"], button[type="submit"],
63
Chapter 5. Basic concepts of ...
button[type="button"], button[type="reset"],
button[type="submit"], input[type="re
input[type="submit"], input[type="button"] {
font-weight: bold;
}
All the changes that were planned to be preformed are done and now you can proceed to building
the new PlugnSkinDemo skin and import it into the project. As you read in the previous section,
the skin should be built in the "P-n-S" folder of the skin project be executing mvn clean install
command. This procedure results in creating a "target" folder that contains a .jar file with a
compiled new skin, it our case the file is named "P-n-S-1.0.-SNAPSHOT.jar". The next step is to
import the new PlugnSkinDemo skin into the project.
What you need to do, in order to have the new skin imported to the project is to
• Add the new skin's name to the "web.xml" file. It is done like this
<context-param>
<param-name>org.ajax4jsf.SKIN</param-name>
<param-value>PlugnSkinDemo</param-value>
</context-param>
Please, do not forget that standard controls skinning has to be enabled in the "web.xml" file, which
can be done by adding the following code to the "web.xml" file:
<context-param>
<param-name>org.richfaces.CONTROL_SKINNING</param-name>
<param-value>enable</param-value>
</context-param>
64
State Manager API
65
Chapter 5. Basic concepts of ...
RichFaces State API allows easily to define some set of states for the pages and any properties
for this states.
Actually States is a map where the entry key is a name of the State and the value is a State map.
Particular State map has entries with some names as keys and any objects as values that are used
after the state activation. Thus, in the State map you could define any values, method bindings,
or just some simple state variables (constants) which have different values for every State.
One of the most convenience features of the RichFaces State API is a navigation between states.
The RichFaces State API implements states change as the standard JSF navigation. Action
component just returns outcome and the RichFaces State API extension for the JSF navigation
handler checks whether this outcome is registered as a state change outcome or not. If the state
change outcome is found the corresponding state is activated. Otherwise the standard navigation
handling is called.
In order to use RichFaces State API you should follow the next steps:
66
State Manager API
...
<application>
<navigation-handler>org.richfaces.ui.application.StateNavigationHandler</navigation-
handler>
<el-resolver>org.richfaces.el.StateELResolver</el-resolver>
</application>
...
...
<factory>
<application-factory>org.richfaces.ui.application.StateApplicationFactory</application-
factory>
</factory>
...
...
<managed-bean>
<managed-bean-name>state</managed-bean-name>
<managed-bean-class>org.richfaces.ui.model.States</managed-bean-class>
<managed-bean-scope>request</managed-bean-scope>
<managed-property>
<property-name>states</property-name>
<property-class>org.richfaces.ui.model.States</property-class>
<value>#{config.states}</value>
</managed-property>
</managed-bean>
<managed-bean>
<managed-bean-name>config</managed-bean-name>
<managed-bean-class>org.richfaces.demo.stateApi.Config</managed-bean-class>
<managed-bean-scope>none</managed-bean-scope>
</managed-bean>
...
One bean ("config") defines and stores states as it is shown in the following example:
67
Chapter 5. Basic concepts of ...
...
public class Config {
/**
* @return States
*/
public States getStates() {
FacesContext facesContext = FacesContext.getCurrentInstance();
States states = new States();
68
State Manager API
beanExpression = expressionFactory.createValueExpression(facesContext
.getELContext(), "#{loginbean}", Bean.class);
states.put("bean", beanExpression);
beanExpression = expressionFactory.createValueExpression(facesContext
.getELContext(), "#{loginaction}", LoginAction.class);
states.put("action", beanExpression);
methodExpression = expressionFactory.createMethodExpression(
facesContext.getELContext(), "#{loginaction.ok}",
String.class, new Class[] {});
states.put("ok", methodExpression);
states.setNavigation("switch", "register");
return states;
}
}
...
The other bean ("state") with the type org.richfaces.ui.model.States has the "states"
managed property that is bound to the "config" bean which defines states.
...
<h:panelGrid columns="3">
<h:outputText value="username" />
<h:inputText value="#{state.bean.name}" id="name" required="true" />
<h:outputText value="password" />
<h:inputSecret value="#{state.bean.password}" id="password" required="true" />
<h:outputText value="confirm" rendered="#{state.showConfirm}" />
<h:inputSecret value="#{state.bean.confirmPassword}" rendered="#{state.showConfirm}"
id="confirm" required="true" />
</h:panelGrid>
69
Chapter 5. Basic concepts of ...
70
Chapter 6.
6.1.1. Description
The <a4j:ajaxListener> component is the same one as <f:actionListener> or
<f:valueChangeListener> , but for an Ajax container.
Name Value
listener-class org.ajax4jsf.framework.ajax.AjaxListener
event-class org.ajax4jsf.framework.ajax.AjaxEvent
tag-class org.ajax4jsf.taglib.html.jsp.AjaxListenerTag
Example:
...
<a4j:ajaxListener type="demo.Bean"/>
...
package demo;
71
Chapter 6. The RichFaces Comp...
...
}
import demo.ImplBean;
...
ImplBean myListener = new ImplBean();
...
Example:
...
<a4j:commandLink id="cLink" value="Click it To Send Ajax Request">
<a4j:ajaxListener type="demo.Bean"/>
</a4j:commandLink>
...
Example:
package demo;
import org.ajax4jsf.framework.ajax.AjaxEvent;
72
Relevant resources links
Name Value
component-type org.ajax4jsf.components.KeepAlive
component-family org.ajax4jsf.components.AjaxKeepAlive
component-class org.ajax4jsf.components.AjaxKeepAlive
Example:
Note, that to be put into the request scope the pointed bean should be registered inside faces-
config.xml file and marked with org.ajax4jsf.model.KeepAlive annotation.
73
Chapter 6. The RichFaces Comp...
Example:
The "beanName" attribute defines the request scope bean name you'd like to re-use. Note that
this attribute must point to a legal JSF EL expression which resolves to a managed mean instance.
For example for the above code the class definition may look like this one:
class MyClass{
...
private TestBean testBean;
// Getters and Setters for testBean.
...
}
The "ajaxOnly" attribute declares whether the value of the bean should be available during a
non-Ajax request. If the value of this attribute is "true" a request scope bean keeps the same value
during Ajax requests from the given page. If a non-Ajax request is sent from this page the bean
is re-created as a regular request scope bean.
Some additional information about usage of component can be found here [http://jboss.com/
index.html?module=bb&op=viewtopic&t=104989].
74
Creating on a page
More information about <f:param> and <f:actionListener> can be found here [http://
java.sun.com/javaee/javaserverfaces/1.2/docs/tlddocs/index.html].
Name Value
component-type org.ajax4jsf.ActionParameter
component-class org.ajax4jsf.component.html.HtmlActionParameter
Example:
75
Chapter 6. The RichFaces Comp...
Example:
import org.ajax4jsf.component.html.HtmlActionParameter;
...
HtmlActionParameter myActionParameter = new HtmlActionParameter();
...
At the render phase, it's decoded by parent component ( <h:commandLink> or like) as usual. At
the process request phase, if the parent component performs an action event, update the "value"
specified in the "assignTo" attribute as its "value" . If a "converter" attribute is specified, use it
to encode and decode the "value" to a string stored in the html parameter.
Example:
...
<script>
...
var foo = "bar";
...
</script>
...
<a4j:actionparam noEscape="true" name="param1" value="foo" assignTo="#{bean.prop1}"
/>
...
The <a4j:param> extends <f:param> , so the "name" attribute is mandatory. Otherwise, the
"value" misses due missing the request parameter name for it.
76
< a4j:commandButton >
6.4.1. Description
77
Chapter 6. The RichFaces Comp...
78
Description
79
Chapter 6. The RichFaces Comp...
80
Creating on a page
Name Value
component-type org.ajax4jsf.CommandButton
component-family javax.faces.Command
component-class org.ajax4jsf.component.html.HtmlAjaxCommandButton
renderer-type org.ajax4jsf.components.AjaxCommandButtonRenderer
Example:
...
<a4j:commandButton reRender="someData" action="#{bean.action1}" value="Link"/>
...
import org.ajax4jsf.component.html.HtmlAjaxCommandButton;
...
HtmlAjaxCommandButton myButton = new HtmlAjaxCommandButton();
...
This definition of the component provides a link, a click on the link causes an Ajax form submit
on the server, action1 method performance, and rendering of the component with someData id
after the response comes back from the server.
The component <a4j:commandButton> placed on a page generates the following HTML code:
...
<input type="submit" onclick="A4J.AJAX.Submit(...request parameters);return false;"
value="sort"/>
81
Chapter 6. The RichFaces Comp...
...
Hence, the utility method A4J.AJAX.Submit is called on a click, the method performs Ajax request
as the <a4j:support> component
Note:
AJAX support is built in and it's not necessary to add nested <a4j:support> to
the component.
The usage of the keyword 'this' in JavaScript code in the "oncomplete" attribute depends on the
location of <a4j:commandButton> . If the commandButton is situated outside the re-rendered
region you can use keyword 'this' as in the following example:
...
<h:form id="form">
<a4j:commandButton id="cbutton" action="director.rollCamera"
onclick="this.disabled=true"
oncomplete="this.disabled=false" />
</h:form>
...
Otherwise if the commandButton contained in re-rendered region the "oncomplete" attribute has
a problem obtaining a reference of the commandButton object when using the keyword 'this'.
In this case you can use the "oncomplete" attribute as in the following example:
...
<h:form id="form">
<a4j:commandButton id="cbutton" action="director.rollCamera"
onclick="this.disabled=true"
oncomplete="document.getElementById('form:cbutton').disabled=false" />
</h:form>
...
Common JSF navigation could be performed after an Ajax submit and partial rendering, but
Navigation Case must be defined as <redirect/> in order to avoid problems with some browsers.
As any Core Ajax component sending Ajax requests and processing server responses
<a4j:commandButton> has all attributes described above (see <a4j:support> chapter) that
provide the required behavior of requests sending (delay, limitation of submit area and rendering,
and etc.)
82
Relevant resources links
Information about the "process" attribute usage you can find here.
83
Chapter 6. The RichFaces Comp...
84
Description
85
Chapter 6. The RichFaces Comp...
86
Creating on a page
Name Value
component-type org.ajax4jsf.CommandLink
component-family javax.faces.Command
component-class org.ajax4jsf.component.html.HtmlAjaxCommandLink
renderer-type org.ajax4jsf.components.AjaxCommandLinkRenderer
Example:
87
Chapter 6. The RichFaces Comp...
...
<a4j:commandLink reRender="someData" action="#{bean.action1}" value="Link"/>
...
import org.ajax4jsf.component.html.HtmlAjaxCommandLink;
...
HtmlAjaxCommandLink myLink = new HtmlAjaxCommandLink();
...
This definition of the component provides a link, and a click on the link causes an Ajax form submit
on the server, "action1" method performance, and rendering of the component with "someData"
id after the response comes back from the server.
The component <a4j:commandLink> placed on a page generates the following HTML code:
...
<a href="#" onclick="A4J.AJAX.Submit(?"request parameters"); return false;">
<span>Link Value</span>
</a>
...
Hence, the utility method "A4J.AJAX.Submit" is called on a click, the method performs Ajax
request as the <a4j:support> component
Note:
AJAX support is built in and it's not necessary to add nested <a4j:support> to
the component.
Common JSF navigation could be performed after Ajax submit and partial rendering, but
Navigation Case must be defined as <redirect/> in order to avoid problems with some browsers.
88
Relevant resources links
As any Core Ajax component sending Ajax requests and processing server responses
<a4j:commandLink> has all attributes described above (see <a4j:support> chapter) that
provide the required behavior of requests sending (delay, limitation of submit area and rendering,
etc.)
Information about the "process" attribute usage you can find here.
89
Chapter 6. The RichFaces Comp...
90
Description
91
Chapter 6. The RichFaces Comp...
Name Value
component-type org.ajax4jsf.Form
component-family javax.faces.Form
component-class org.ajax4jsf.component.html.AjaxForm
renderer-type org.ajax4jsf.FormRenderer
Component definition on a page is similar to definition of the original component from JSF HTML
library.
Example:
<a4j:form>
<h:panelGrid>
<h:commandButton value="Button" action="#{userBean.nameItMark}" />
</h:panelGrid>
</a4j:form>
Example:
import org.ajax4jsf.component.html.AjaxForm;
...
AjaxForm myForm = new AjaxForm();
...
The difference with the original component is that all hidden fields required for command links are
always rendered and it doesn't depend on links rendering on the initial page. It solves the problem
with invalid links that weren't rendered on a page immediately, but after some Ajax request.
92
Relevant resources links
Beginning with release 1.0.5 additional attributes that make this form variant universal have
appeared.
If "ajaxSubmit" attribute is true, it becomes possible to set Ajax submission way for any
components inside, i.e. not a page URL is used as an "action" attribute, but the javascript:
A4J.AJAX.Submit(...)call. In this case, the "reRender" attribute contains a list of Ids of
components defined for re-rendering. If you have <h:commandButton> or <h:commandLink>
inside the form, they work as <a4j:commandButton> .
Example:
This example shows that in order to make <t:datascroller> submissions to be Ajax ones it's
required only to place this <t:datascroller> into <a4j:form> . In the other case it is necessary
to redefine renders for its child links elements that are defined as <h:commandLink> and can't
be made Ajax ones with using e.g. <a4j:support> .
With the help of "limitToList" attribute you can limit areas, which are updated after the responses.
If "limitToList" is true, only the reRender attribute is taken in account. Therefore, if you use blocks
of text wrapped with <a4j:outputPanel> and ajaxRendered= "true", blocks of text are ignored.
Information about the "process" attribute usage you can find here.
93
Chapter 6. The RichFaces Comp...
94
Description
95
Chapter 6. The RichFaces Comp...
Name Value
component-type javax.faces.HtmlCommandLink
component-family javax.faces.Command
component-class javax.faces.component.html.HtmlCommandLink
96
Creating the Component with a Page Tag
Name Value
renderer-type org.ajax4jsf.HtmlCommandLinkRenderer
Example:
import javax.faces.component.html.HtmlCommandLink;
...
HtmlCommandLink myCommandLink = new HtmlCommandLink();
...
Example:
<a4j:form>
...
<a4j:htmlComandLink action="action" value="link" rendered="#{bean.rendered}">
<f:param .../>
<a4j:htmlComandLink>
...
</a4j:form>
97
Chapter 6. The RichFaces Comp...
6.8.1. Description
The <a4j:jsFunction> component allows to invoke the server side data and return it in a JSON
format to use in a client JavaScript calls.
98
Description
99
Chapter 6. The RichFaces Comp...
Name Value
component-type org.ajax4jsf.Function
component-family org.ajax4jsf.components.ajaxFunction
component-class org.ajax4jsf.component.html.HtmlajaxFunction
renderer-type org.ajax4jsf.components.ajaxFunctionRenderer
Example:
...
<head>
<script>
<!--There is some script named "myScript" that uses parameters which will be taken from
server-->
</script>
</head>
<body>
...
<a4j:jsFunction data="#{bean.someProperty}" name="callScript"
oncomplete="myScript(data.subProperty1, data.subProperty2)"/>
...
100
Creating the Component Dynamically Using
Java
The script "myScript" is called after bean.someProperty data is returned from server(e.g. It'll
be object with two subproperties).
import org.ajax4jsf.component.html.HtmlajaxFunction;
...
HtmlajaxFunction myFunction = new HtmlajaxFunction();
...
When using the <a4j:jsFunction> it's possible to initiate the Ajax request from the JavaScript
and perform partial update of a page and/or invoke the JavaScript function with data returned by
Ajax response.
...
<body onload="callScript()">
...
<h:form>
...
<a4j:jsFunction name="callScript" data="#{bean.someProperty1}"
reRender="someComponent" oncomplete="myScript(data.subProperty1,
data.subProperty2)">
<a4j:actionParam name="param_name" assignTo="#{bean.someProperty2}"/>
</a4j:jsFunction>
...
</h:form>
...
</body>
...
101
Chapter 6. The RichFaces Comp...
similar to <a4j:commandButton> , but it could be activated from the JavaScript code. It allows
to invoke some server side functionality and use the returned data in the JavaScript function
invoked from "oncomplete" attribute. Hence it's possible to use <a4j:jsFunction> instead of
<a4j:commandButton> . You can put it anywhere, just don't forget to use <h:form> ... </h:form>
around it.
Information about the "process" attribute usage you can find here.
102
Creating on a page
Name Value
component-type org.ajax4jsf.Include
component-family javax.faces.Output
component-class org.ajax4jsf.component.html.Include
renderer-type org.ajax4jsf.components.AjaxIncludeRenderer
Example:
<h:panelGroup id="wizard">
103
Chapter 6. The RichFaces Comp...
For navigation inside a page defined in viewId any components responsible for Ajax requests to
the server generation are used.
Example:
...
<a4j:commandButton action="next" reRender="wizard"/>
...
Example:
<navigation-rule>
<from-view-id>/pages/include/first.xhtml</from-view-id>
<navigation-case>
<from-outcome>next</from-outcome>
<to-view-id>/pages/include/second.xhtml</to-view-id>
</navigation-case>
</navigation-rule>
In this case after a click on a button defined inside "first.xhtml" view, navigation is performed
after an Ajax request (the same as standard JSF one) only inside this view.
<import org.ajax4jsf.component.html.Include;
...
Include myInclude = new Include();
...
If <a4j:include> is defined this way, any Ajax request returning outcome inside generates
navigation with this <a4j:include> .
Ajax Action for navigation implementation inside view must be placed inside <a4j:include>
pages. Navigation defined by these pages is applied to the <a4j:include> element current for
them.
104
Relevant resources links
As in the general case for Ajax Action component, if the <a4j:action> component inside
<a4j:include> returns outcome defined as <redirect/>, Ajax submit is performed with navigation
of the whole page and not only of the current view.
Some additional information can be found on the Ajax4Jsf Users Forum [http://jboss.com/
index.html?module=bb&op=viewtopic&t=104158].
Name Value
component-type org.ajax4jsf.Bundle
component-family org.ajax4jsf.Bundle
component-class org.ajax4jsf.component.html.AjaxLoadBundle
Example:
105
Chapter 6. The RichFaces Comp...
Example:
import org.ajax4jsf.component.html.AjaxLoadBundle;
...
AjaxLoadBundle myBundle = new AjaxLoadBundle();
...
<a4j:loadBundle> allows to use reference to bundle messages during the Ajax re-rendering.
<a4j:loadBundle> is a substitute for the <f:loadBundle> in JSF 1.1 which is not a JSF
component originally. <f:loadBundle> is a jsp tag that load the bundle messages into the request
scope when page is rendered. As soon as each Ajax request works in own request scope, the
bundles loaded with <f:loadBundle> are unavailable. Instead of <f:loadBundle> that might
be located anywhere on a page, the <a4j:loadBundle> should be declared inside the <f:view>
(this does not matter in case on using Facelets) JSF 1.2 introduces the bundle registered in the
faces-config.xml. This fixed the problem with <f:loadBundle> . Therefore, you can use this JSF
1.2 way to declare your bundles.
6.11.1. Description
Inserts script links to the head element. Render the value of the component, after passing it to the
getResourceURL() method of the ViewHandler for this application, and passing the result through
the encodeResourceURL() method of the ExternalContext.
106
Creating on a page
Name Value
component-type org.ajax4jsf.LoadScript
component-family org.ajax4jsf.LoadScript
component-class org.ajax4jsf.component.html.HtmlLoadScript
renderer-type org.ajax4jsf.LoadScriptRenderer
Example:
<a4j:loadScript src="scripts/someScript.js"/>
Example:
import org.ajax4jsf.component.html.HtmlLoadScript;
...
HtmlLoadScript myScript = new HtmlLoadScript();
...
As it was mentioned above this component returns its value as the value of the "src" attribute
passing it to the getResourceURL() method of the ViewHandler for this application, and passing
the result through the encodeResourceURL() method of the ExternalContext.
107
Chapter 6. The RichFaces Comp...
It means that the Context is inserts automatically to the link. And calls like resource:// is properly
handled.
Except this - you may be free to put your script links right from the child page while using facelets
templates.
108
Creating the Component Dynamically Using
Java
Example:
<a4j:loadStyle src="styles/style.css"/>
import org.ajax4jsf.component.html.HtmlLoadStyle;
...
HtmlLoadScript myStyle = new HtmlLoadStyle();
...
It means that the Context is inserted automatically to the link. And calls like resource:// is
properly handled.
Except this - you may be free to put your stylesheet links right from the child page while using
facelets templates.
109
Chapter 6. The RichFaces Comp...
110
Creating the Component with a Page Tag
Name Value
component-type org.ajax4jsf.Log
component-family org.ajax4jsf.Log
component-class org.ajax4jsf.component.html.AjaxLog
renderer-type org.ajax4jsf.LogRenderer
Then, in order to open a log window, press "CTRL+SHIFT+L" on a page with the component.
Example:
import org.ajax4jsf.component.html.AjaxLog;
...
AjaxLog myLog = new AjaxLog();
...
Usage of the appropriate component attributes could change a representation level of debug
information as well as the hot key for a window opening.
The hot key could be changed with the "hotkey" attribute, where it's necessary to define one
letter that together with "CTRL+SHIFT" opens a window.
111
Chapter 6. The RichFaces Comp...
The "level" attribute with several possible values ("FATAL", "ERROR", "WARN", "INFO", "ALL")
could change a logging level.
The log could be generated not only in a new window, but also on the current page in a separate
<div> , this is also controlled with the "popup" attribute on the component.
Example:
The component defined this way is decoded on a page as <div> inside a page, where all the
information beginning with informational message is generated.
Note:
112
Description
113
Chapter 6. The RichFaces Comp...
114
Description
115
Chapter 6. The RichFaces Comp...
116
Creating on a page
Name Value
component-type org.ajax4jsf.MediaOutput
component-family org.ajax4jsf.Resource
component-class org.ajax4jsf.component.html.MediaOutput
renderer-type org.ajax4jsf.MediaOutputRenderer
Example:
...
<a4j:mediaOutput element="img" cacheable="false" session="true"
createContent="#{paintBean.paint}" value="#{paintData}"
mimeType="image/jpeg"/>
...
import org.ajax4jsf.component.html.MediaOutput;
...
MediaOutput myMedia = new MediaOutput ();
...
Example:
package demo;
117
Chapter 6. The RichFaces Comp...
Integer width=100;
Integer weight=50;
...
The Paint method of the paintBean class is a method transmitting graphical data into output
stream.
Example:
As it was shown in the example above there are two main components:
• Value specifies a bean class keeping data for transmitting into a method that transmits it into
a stream.
Note:
Hence, when using the component it's possible to output your data of any type on a page with
Ajax requests.
6.15.1. Description
The component is used for components grouping in the Ajax output area, which offers several
additional output opportunities such as inserting of non-present in tree components, saving of
transient elements after Ajax request and some others.
118
Description
119
Chapter 6. The RichFaces Comp...
Name Value
component-type org.ajax4jsf.OutputPanel
component-family javax.faces.Panel
component-type org.ajax4jsf.ajax.OutputPanel
component-class org.ajax4jsf.component.html.HtmlAjaxOutputPanel
renderer-type org.ajax4jsf.components.AjaxOutputPanelRenderer
Example:
<a4j:outputPanel>
<h:form>
120
Creating the Component Dynamically Using
Java
<h:outputText value="Some text"/>
<h:inputText id="text1" label="text1" value="#{rsBean.text1}">
</h:inputText>
</h:form>
</a4j:outputPanel>
Example:
import org.ajax4jsf.component.html.HtmlAjaxOutputPanel;
...
HtmlAjaxOutputPanel myPanel = new HtmlAjaxOutputPanel();
Example:
Example:
<a4j:outputPanel ajaxRendered="true">
121
Chapter 6. The RichFaces Comp...
<h:messages/>
</a4j:outputPanel>
On default <a4j:outputPanel> is output as a pair of opening and closing html <span> tag, but
with the help of the layout attribute this output way could be changed. There are three variants
for this component value:
• "inline" (default)
• "block"
• "none"
If layout="block" is chosen, the component is rendered as a pair of opening and closing <div>
tag, to which it's possible to apply any available style attributes available for block tags.
layout ="none" helps to avoid an unnecessary tag round a context that could or couldn't
be rendered according to the defined "rendered" attribute conditions. If an inner context isn't
rendered, <a4j:outputPanel> is rendered as a <span> tag with the id equal to an id of a
child component and display:none style. If a child component is rendered, <a4j:outputPanel>
doesn't present at all in a final code.
Example:
As you see, the code is very similar to the one shown above, but "reRender " attribute refers
directly to the updating panelGrid and not to the framing outputPanel, and it's more semantically
correct.
<a4j:outPanel> should be used for non-JSF component part framing, which is to be updated
on Ajax response, as RichFaces specifies the list of updating areas as a list of an existing JSF
component.
On default non-JSF context isn't saved in a component tree, but is rendered anew every time.
To accelerate the processing speed and Ajax response input speed, RichFaces saves non-JSF
context in a component tree on default. This option could be canceled by "keepTransient" attribute
that cancels transient flag forced setting for child components. This flag setting keeps the current
value set by child components.
122
Relevant resources links
Note:
In JSF 1.1 implementation and lower, where non-JSF context should be framed
with the <f:verbatim> component, <a4j:outputPanel> doesn't improve this
JSF implementation option in any way, so you still have to use this tag where it's
necessary without RichFaces usage.
RichFaces allows setting Ajax responses rendering directly basing on component tree nodes
without referring to the JSP (XHTML) page code. It could be defined by "selfRendered" attribute
setting to "true" on <a4j:region> and could help considerably speed up a response output.
However, if a transient flag is kept as it is, this rapid processing could cause missing of transient
components that present on view and don't come into a component tree. Hence, for any particular
case you could choose a way for you application optimization: speed up processing or redundant
memory for keeping tree part earlier defined a transient.
Some additional information about usage of component can be found here [http://www.jboss.com/
index.html?module=bb&op=viewtopic&p=4052203#4052203] .
6.16.1. Description
<a4j:page> is used for solving of incompatibility problems in early Ajax4jsf versions. The
component encodes the full html page structure.
123
Chapter 6. The RichFaces Comp...
Name Value
component-type org.ajax4jsf.components.Page
component-family org.ajax4jsf.components.AjaxRegion
component-class org.ajax4jsf.component.html.HtmlPage
renderer-type org.ajax4jsf.components.AjaxPageRenderer
124
Creating on a page
<f:view>
<a4j:page>
<f:facet name="head">
<!--...Head Content here-->
</f:facet>
<!--...Page Content here-->
</a4j:page>
</f:view>
import org.ajax4jsf.component.html.HtmlPage;
...
HtmlPage myPage = new HtmlPage();
...
The component is rendered as a full HTML page template as it is shown in the example [126].
The head section is defined with the help of the corresponding "head" facet. You do not need
to use "body" facet in order to define first body section. The second and more body sections is
defined with the help of the corresponding "body" facet.
The attribute "format" defines page layout format for encoding DOCTYPE.
Example:
125
Chapter 6. The RichFaces Comp...
Example:
126
Description
127
Chapter 6. The RichFaces Comp...
Name Value
component-type org.ajax4jsf.Poll
component-family org.ajax4jsf.components.AjaxPoll
component-class org.ajax4jsf.component.html.AjaxPoll
renderer-type org.ajax4jsf.components.AjaxPollRenderer
128
Creating on a page
Example:
import org.ajax4jsf.component.html.AjaxPoll;
...
AjaxPoll myPoll = new AjaxPoll();
...
The "timeout" attribute defines response waiting time in milliseconds. If a response isn't received
during this period a connection is aborted and the next request is sent. Default value for "timeout"
attribute isn't set.
The "enabled" attribute defines should the <a4j:poll> send request or not. It's necessary to
render the <a4j:poll> to apply the current value of "enabled" attribute. You can use an EL-
expression for "enabled" attribute to point to a bean property. An example of usage of mentioned
above attributes [129] is placed below:
Example:
...
<a4j:region>
<h:form>
<a4j:poll id="poll" interval="1000" enabled="#{userBean.pollEnabled}"
reRender="poll,grid"/>
</h:form>
129
Chapter 6. The RichFaces Comp...
</a4j:region>
<h:form>
<h:panelGrid columns="2" width="80%" id="grid">
<h:panelGrid columns="1">
<h:outputText value="Polling Inactive" rendered="#{not userBean.pollEnabled}"></
h:outputText>
<h:outputText value="Polling Active" rendered="#{userBean.pollEnabled}"></
h:outputText>
<a4j:commandButton style="width:120px" id="control"
value="#{userBean.pollEnabled?'Stop':'Start'} Polling"
reRender="poll, grid">
<a4j:actionParam name="polling" value="#{!userBean.pollEnabled}"
assignTo="#{userBean.pollEnabled}"/>
</a4j:commandButton>
</h:panelGrid>
<h:outputText id="serverDate" style="font-size:16px" value="Server Date:
#{userBean.date}"/>
</h:panelGrid>
</h:form>
...
The example shows how date and time are updated on a page in compliance with data taken
from a server. The <a4j:poll> componet sends requests to the server every second. "reRender"
attribute for <a4j:poll> contains value of its own Id. Hence, it renders itself for applying the current
value of "enabled" attribute.
Note:
Information about the "process" attribute usage you can find here.
130
< a4j:portlet >
The aditional information about component usage you can find here : RichFaces Users Forum
[http://jboss.com/index.html?module=bb&op=viewtopic&t=103909] .
Name Value
component-type org.ajax4jsf.Portlet
component-family org.ajax4jsf.component.Portlet
component-class org.ajax4jsf.component.html.HtmlPortlet
<f:view>
<a4j:portlet>
...
</a4j:portlet>
</f:view>
import org.ajax4jsf.component.html.HtmlPortlet;
131
Chapter 6. The RichFaces Comp...
...
HtmlPortlet myPortlet = new HtmlPortlet();
...
The aditional information about component usage you can find here: Ajax4Jsf Users Forum [http:/
/www.jboss.com/index.html?module=bb&op=viewtopic&t=107325].
Portlet Sample could be checked out from JBoss SVN: portal-echo application [http://
anonsvn.jboss.org/repos/ajax4jsf/trunk/samples/portal-echo/].
Usage instructions for this demo could be found at the corresponding: portal-echo application
[http://www.jboss.com/index.html?module=bb&op=viewtopic&t=107325].
The main difference between <a4j:push> and <a4j:poll> components is that <a4j:push>
makes request to minimal code only (not to JSF tree) in order to check the presence of messages
in the queue. If the message exists the complete request is performed. The component doesn't
poll registered beans but registers EventListener which receives messages about events.
132
Description
133
Chapter 6. The RichFaces Comp...
Name Value
component-type org.ajax4jsf.Push
component-family org.ajax4jsf.components.AjaxPush
component-class org.ajax4jsf.component.html.AjaxPush
renderer-type org.ajax4jsf.components.AjaxPushRenderer
134
Creating on a page
import org.ajax4jsf.component.html.AjaxPush;
...
AjaxPush myPush = new AjaxPush();
...
The bean, for example, could be subscribed to Java Messaging Service (JMS [http://java.sun.com/
products/jms/]) topic or it could be implemented as Message Driven Bean (MDB) in order to send
a message to the <a4j:push> component about an event presence. In the presence of the event
some action occurs.
Thus, a work paradigm with the <a4j:push> component corresponds to an anisochronous model,
but not to pools as for <a4j:poll> component. See the simplest example below:
Example:
...
class MyPushEventListener implements PushEventListener {
public void onEvent(EventObject evt) {
System.out.println(evt.getSource());
//Some action
}
...
Example:
...
public void addListener(EventListener listener) {
synchronized (listener) {
if (this.listener != listener) {
135
Chapter 6. The RichFaces Comp...
Example:
...
<a4j:status startText="in progress" stopText="done"/>
<a4j:form>
<a4j:region>
<a4j:push reRender="msg" eventProducer="#{pushBean.addListener}" interval="2000"/>
</a4j:region>
<a4j:outputPanel id="msg" >
<h:outputText value="#{pushBean.date}">
<f:convertDateTime type="time"/>
</h:outputText>
</a4j:outputPanel>
<a4j:commandButton value="Push!!" action="#{pushBean.push}" ajaxSingle="true"/>
</a4j:form>
...
The example shows how date is updated on a page in compliance with data taken from a server. In
the example "interval" attribute has value "2000". This attribute defines an interval in milliseconds
between the previous response and the next request. Default value is set to "1000" milliseconds
(1 second). It's possible to set value equal to "0". In this case connection is permanent.
The "timeout" attribute defines response waiting time in milliseconds. If a response isn't received
during this period a connection is aborted and the next request is sent. Default value for "timeout"
attribute isn't set. Usage of "interval" and "timeout" attributes gives an opportunity to set short
polls of queue state or long connections.
Note:
Information about the "process" attribute usage you can find here.
136
< a4j:region >
137
Chapter 6. The RichFaces Comp...
Name Value
component-class org.ajax4jsf.component.html.HtmlAjaxRegion
renderer-type org.ajax4jsf.components.AjaxRegionRenderer
<a4j:region>
<h:inputText value="#{userBean.name}">
<a4j:support event="onkeyup" reRender="outname" />
</h:inputText>
</a4j:region>
import org.ajax4jsf.component.html.HtmlAjaxRegion;
...
HtmlAjaxRegion newRegion = new HtmlAjaxRegion();
...
The region marks an area page that is decoded on the server. In most cases it is not necessary
to use the region, as ViewRoot is a default region. This component helps to reduce data quantity
processed by the server, but the region doesn't influence on the standard submission rules. It
means that:
• The area that is to be submitted onto the server should be embedded in <h:form>/<a4j:form>
component.
• The whole form is submitted on Ajax response and not a region that request is performed from.
Example:
<h:form id="form1">
138
Key attributes and ways of usage
<a4j:region>
<a4j:commandLink reRender="someID" value="Link" id="link1"/>
<!--..Some content that will be decoded on server after Ajax request.-->
</a4j:region>
<h:form>
Hence, the <a4j:commandLink> request generation causes full form1 form submission onto
the server, the only difference is that a component tree part decoded on the serve is the part
included into the region.
The regions could be nested in any order, the server picks out and decodes only the region, which
contains a particular component that sends a request.
Example:
<a4j:region>
<a4j:commandLink reRender="someID" value="Link" id="link1"/>
<a4j:region>
<a4j:commandLink reRender="someID" value="Link" id="link2"/>
<!--..Some content that will be decoded on server after Ajax request.-->
</a4j:region >
<!--..Some content that will be decoded on server after Ajax request.-->
</a4j:region >
Therefore, the external region is decoded for the "link1" and the internal one is decoded for
the "link2".
RichFaces allows setting Ajax responses rendering directly basing on component tree nodes
without referring to the JSP (XHTML) page code. It could be defined by "selfRendered" attribute
setting to "true" on <a4j:region> and could help considerably speed up a response output.
However, this rapid processing could cause missing of transient components that present on view
and don't come into a component tree as well as omitting of <a4j:outputPanel> usage described
below.
Example:
In this case, the processing is quicker and going on without referring to a page code, but the HTML
code that isn't saved in a component tree could be lost. Thus, this optimization should be very
139
Chapter 6. The RichFaces Comp...
The processing could be also accelerated if a region decoded for the processing passes straight
away into Encode. But to update some data out of the region or on another region, use the
"renderRegionOnly" attribute set to "false" ("true" on default) to change this behaviour.
Example:
<a4j:region renderRegionOnly="true">
<a4j:commandLink reRender="someID2" value="Link1" id="link1"/>
<h:panelGroup id="someId1">
</h:panelGroup>
</a4j:region>
<a4j:region renderRegionOnly="false">
<a4j:commandLink reRender="someID1" value="Link2" id="link2"/>
<h:panelGroup id="someId1">
</h:panelGroup>
</a4j:region>
This example shows that one of the regions is decoded when a link is used inside. Nevertheless,
if after processing the "link1" is clicked, the first region passes into Encode as a root region
and encode performance time is reduced. This optimization doesn't allow data update out of
the region and should be implemented very carefully. The data out of the region described with
renderRegionOnly="false" is updated successfully.
Starting from version 3.2.0 <a4j:region> can be used inside any iterative component (e.g.
<rich:column> , <rich:scrollableDataTable> ) and just re-render the components from the same
row without updating the whole table and without any additional listeners.
Example:
<rich:column>
<a4j:region>
<a4j:commandLink reRender="out"/>
</a4j:region>
</rich:column>
<rich:column>
<h:outputText id="out">
</rich:column>
140
Relevant resources links
Name Value
component-type org.ajax4jsf.Repeat
141
Chapter 6. The RichFaces Comp...
Name Value
component-family javax.faces.Data
component-class org.ajax4jsf.component.html.HtmlAjaxRepeat
renderer-type org.ajax4jsf.components.RepeatRenderer
The output is generated according to a collection contained in bean.props with the detail key
passed to child components.
import org.ajax4jsf.component.html.HtmlAjaxRepeat;
...
HtmlAjaxRepeat repeater = new HtmlAjaxRepeat ();
...
...
<a4j:poll intervall="1000" action="#{repeater.action}" reRender="text">
<table>
<tbody>
<a4j:repeat value="#{bean.props}" var="detail" ajaxKeys="#{repeater.ajaxedRowsSet}">
<tr>
<td>
<h:outputText value="detail.someProperty" id="text"/>
</td>
142
Relevant resources links
</tr>
</a4j:repeat>
</tbody>
</table>
</a4j:poll>
...
In the above-mentioned example the component <a4j:poll> sends Ajax requests every second,
calling the action method of the repeater bean.
Note:
The set could be defined during the action method processing using data on a
model from the property repeater.myRepeat
One more benefit of this component is absence of strictly defined markup as JSF HTML DataTable
and TOMAHAWK DataTable has, hence the components could be used more flexibly anywhere
where it's necessary to output the results of selection from some collection.
<ul>
<a4j:repeat ...>
<li>...<li/>
...
<li>...<li/>
</a4j:repeat>
</ul>
All other general attributes are defined according to the similar attributes of iterative components
( <h:dataTable> or <ui:repeat> ) and are used in the same way.
143
Chapter 6. The RichFaces Comp...
144
Creating on a page
Name Value
component-type org.ajax4jsf.Status
component-family javax.faces.Panel
component-class org.ajax4jsf.component.html.HtmlAjaxStatus
renderer-type org.ajax4jsf.components.AjaxStatusRenderer
145
Chapter 6. The RichFaces Comp...
In this case, text elements for the corresponding status are generated.
<a4j:status for="stat2">
<f:facet name="start">
<h:graphicImage value="ajax_process.png" />
</f:facet>
<f:facet name="stop">
<h:graphicImage value="ajax_stoped.png" />
</f:facet>
</a4j:status>
In this case, the elements are generated for each status and correspond the facets content.
import org.ajax4jsf.component.html.HtmlAjaxStatus;
...
HtmlAjaxStatus myStatus = new HtmlAjaxStatus();
...
• Definition with the "for" attribute on the <a4j:status> component. Here "for" attribute should
point at an Ajax container ( <a4j:region> ) id, which requests are tracked by a component.
• Definition with the "status" attribute obtained by any RichFaces library action component. The
attribute should point at the <a4j:status> component id. Then this <a4j:status> component
shows the status for the request fired from this action component.
146
Relevant resources links
The component creates two <span> or <div> elements depending on attribute "layout" with
content defined for each status, one of the elements (start) is initially hidden. At the beginning of
an Ajax request, elements state is inversed, hence the second element is shown and the first is
hidden. At the end of a response processing, elements display states return to its initial values.
Example:
<span id="j_id20:status.start">
Started
</span>
<span id="j_id20:status.stop" style="display: none">
Stopped
</span>
There is a possibility to group a <a4j:status> elements content into <div> elements, instead of
<span> . To use it, just redefine the "layout" attribute from "inline" (default) to "block".
147
Chapter 6. The RichFaces Comp...
6.23.1. Description
The <a4j:support> component adds an Ajax support to any existing JSF component. It allows a
component to generate asynchronous requests on the necessary event demand and with partial
update of page content after a response incoming from the server.
148
Description
149
Chapter 6. The RichFaces Comp...
Example:
<h:inputText value="#{bean.text}">
<a4j:support event="onkeyup" reRender="repeater"/>
</h:inputText>
<h:outputText id="repeater" value="#{bean.text}"/>
On every keyup event generated by an input field, a form is submitted on the server with the help
of Ajax and on a response coming from the server, element with repeater id, founded in a DOM
tree is redrawn according to a new data from the response.
150
Key attributes and ways of usage
Example:
ajaxSupport.setActionExpression(FacesContext.getCurrentInstance().getApplication().getExpressionFactory().creat
FacesContext.getCurrentInstance().getELContext(), "#{bean.action}", String.class, new
Class[] {}));
ajaxSupport.setEvent("onkeyup");
ajaxSupport.setReRender("output");
inputText.getFacets().put("a4jsupport", ajaxSupport);
Example:
...
<h:inputText value="#{bean.text}">
<a4j:support event="onkeyup" reRender="output" action="#{bean.action}"/>
</h:inputText>
...
Example:
As you see from the code, the "onkeyup" event calls a utility RichFaces method that submit a form
creating a special marks for a filter informing that it is an Ajax request. Thus, any supports quantity
could be added to every component, the supports define component behavior on these events.
151
Chapter 6. The RichFaces Comp...
Note
The components: <a4j:commandLink> , <a4j:commandButton> , <a4j:poll>
and others from RichFaces library are already supplied with <a4j:support>
functionality and there is no necessity to add the support to them.
With the help of "onsubmit" and "oncomplete" attributes the component allows using JavaScript
before (for request sending conditions checking) and after an Ajax response processing
termination (for performance of user-defined activities on the client)
Example:
<h:selectOneMenu value="#{bean.text}">
<f:selectItem itemValue="First Item" itemLabel="First Item"/>
<f:selectItem itemValue=" Second Item" itemLabel="Second Item"/>
<f:selectItem itemValue=" Third Item" itemLabel="Third Item"/>
<a4j:support event="onblur" reRender="panel" onsubmit="if(!confirm('Are you sure to
change the option ?'))
{form.reset(); return false;}" oncomplete="alert('Value succesfully stored')"/>
</h:selectOneMenu>
In example there is the condition checking (confirm) is used before request sending and message
printing after the request processing is over.
The components allows different Ajax request managing ways for its various optimization in
particular conditions such as:
• Limitation of the submit area and updating area for the request.
"ajaxSingle" is an attribute that allows submission on the server only component sending a
request, as if the component presented on a separate form.
"limitToList" is an attribute that allows to limit areas, which are updated after the responses.
Only these components defined in the "reRender" attribute are updated.
Example 1:
<h:form>
<h:inputText value="#{person.name}">
<a4j:support event="onkeyup" reRender="test" ajaxSingle="true"/>
</h:inputText>
<h:inputText value="#{person.middleName}"/>
</form>
152
Key attributes and ways of usage
In this example the request contains only the input component causes the request generation, not
all the components contained on a form, because of ajaxSingle="true" usage.
Example 2:
<h:form>
<a4j:outputPanel ajaxRendered="true">
<h:messages/>
</a4j:outputPanel>
<h:inputText value="#{person.name}">
<a4j:support event="onkeyup" reRender="test" limitToList="true"/>
</h:inputText>
<h:outputText value="#{person.name}" id="test"/>
</form>
In this example the component <h:messages> is always updated (as it capturing all Ajax
requests, located in ajaxRendered <a4j:outputPanel> ), except the case when a response is sent
from the input component from the example. On sending this component marks that updating area
is limited to the defined in it components, it means that on its usage with limitToList="true"
the only component updated is the one with id="test".
"eventQueue" is an attribute for naming of the queue where the next response is kept in till its
processing, but if the next event comes in till this time is over, the waiting event is taken away,
replacing with a new one.
"ignoreDupResponces" is an attribute that allows to disable any updates on the client after an
Ajax request if another Ajax request is already sent.
"timeout" is an attribute that allows to set a time interval in millisecond to define a maximum
time period of response wait time. In case of the interval interaction, a new request is sent and
the previous one is canceled. Postprocessing of a response isn't performed.
Example:
<h:form>
<h:inputText value="#{person.name}">
<a4j:support event="onkeyup" reRender="test"
requestDelay="1000" ignoreDupResponces="true" eventsQueue="myQueue"/>
</h:inputText>
<h:outputText value="#{person.name}" id="test"/>
153
Chapter 6. The RichFaces Comp...
</form>
This example clearly shows mentioned above attributes. If quick typing in a text field happens,
every next requests sending is delayed for a second and requests quantity is reduced. The
requests are kept in the queue till its the sending. Moreover, if the next request is already
sent, the rerendering after the previous request is banned, and it helps to avoid unnecessary
processing on the client.
Information about the "process" attribute usage you can find here.
154
Key Features
155
Chapter 6. The RichFaces Comp...
Name Value
component-type org.richfaces.ajaxValidator
component-class org.richfaces.component.html.HtmlajaxValidator
component-family org.richfaces.ajaxValidator
renderer-type org.richfaces.ajaxValidatorRenderer
tag-class org.richfaces.taglib.ajaxValidatorTag
Example:
...
<h:outputText value="Name:" />
<h:inputText value="#{userBean.name}" id="name" required="true">
<f:validateLength minimum="3" maximum="12"/>
<rich:ajaxValidator event="onblur"/>
</h:inputText>
...
Example:
156
Details of Usage
import org.richfaces.component.html.HtmlCalendar;
...
HtmlAjaxValidator myAjaxValidator= new HtmlAjaxValidator();
...
The following example demonstrates how the <rich:ajaxValidator> adds AJAX functionality
to standard JSF validators. The request is sent when the input field loses focus, the action is
determined by the "event" attribute that is set to "onblur".
...
<rich:panel>
<f:facet name="header">
<h:outputText value="User Info:" />
</f:facet>
<h:panelGrid columns="3">
<h:outputText value="Name:" />
<h:inputText value="#{userBean.name}" id="name" required="true">
<f:validateLength minimum="3" maximum="12"/>
<rich:ajaxValidator event="onblur"/>
</h:inputText>
<rich:message for="name" />
</h:panelGrid>
</rich:panel>
...
In the example above it's show how to work with standard JSF validators. The
<rich:ajaxValidator> component also works perfectly with custom validators enhancing their
usage with AJAX.
157
Chapter 6. The RichFaces Comp...
• Using Hibernate Validator, specifying a constraint for the data to be validated. A reference on
Hibernate Validator can be found here [http://www.hibernate.org/hib_docs/validator/reference/
en/html_single/].
The following example shows how the data entered by user can be validated using Hibernate
Validator.
...
<rich:panel>
<f:facet name="header">
<h:outputText value="User Info:" />
</f:facet>
<h:panelGrid columns="3">
<h:outputText value="Name:" />
<h:inputText value="#{validationBean.name}" id="name" required="true">
<rich:ajaxValidator event="onblur" />
</h:inputText>
<rich:message for="name" />
</h:panelGrid>
</rich:panel>
...
...
package org.richfaces.demo.validation;
import org.hibernate.validator.NotEmpty;
import org.hibernate.validator.Email;
import org.hibernate.validator.Length;
@NotEmpty
@Length(min=3,max=12)
private String name;
@Email (message="wrong email format")
@NotEmpty
private String email;
158
Relevant Resources Links
public ValidationBean() {
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
}
...
By default the Hibernate Validator generates an error message in 10 language, though you can
redefine the messages that are displayed to a user when validation fails. In the shows example it
was done by adding (message="wrong email format") to the @Email annotation.
159
Chapter 6. The RichFaces Comp...
Name Value
component-type org.richfaces.graphValidator
component-class org.richfaces.component.html.HtmlgraphValidator
component-family org.richfaces.graphValidator
renderer-type org.richfaces.graphValidatorRenderer
tag-class org.richfaces.taglib.graphValidatorTag
Example:
...
<h:outputText value="Name:" />
<h:inputText value="#{userBean.name}" id="name" required="true">
<f:validateLength minimum="3" maximum="12"/>
<rich:graphValidator event="onblur"/>
</h:inputText>
...
import org.richfaces.component.html.HtmlCalendar;
...
HtmlgraphValidator mygraphValidator= new HtmlgraphValidator();
160
Creating the Component Dynamically Using
Java
...
The following example demonstrate a pattern of how the <rich:graphValidator> can be used.
...
<rich:graphValidator>
<h:panelGrid columns="3">
<h:outputText value="Name:" />
<h:inputText value="#{validationBean.name}" id="name">
<f:validateLength minimum="2" />
</h:inputText>
<rich:message for="name" />
<h:outputText value="Email:" />
<h:inputText value="#{validationBean.email}" id="email" />
<rich:message for="email" />
</h:panelGrid>
</rich:graphValidator>
...
The data validation can be also performed using Hibernate Validator, the same way as it is done
with <rich:beanValidator> .
The components's architecture provides an option to bind the component to a managed bean,
which is done with the <value> attribute. The attribute ensures that the entered data is valid after
the model is updated by revalidating the bean properties.
...
<rich:graphValidator summary="Invalid values: " value="#{dayStatistics}">
<a4j:repeat value="#{dayStatistics.dayPasstimes}" var="pt" id="table">
<h:outputText value="#{pt.title}" />
<rich:inputNumberSpinner minValue="0" maxValue="24" value="#{pt.time}" id="time">
</rich:inputNumberSpinner>
<rich:message for="time" />
</a4j:repeat>
</rich:graphValidator>
161
Chapter 6. The RichFaces Comp...
...
Hence, the given above code will provide the functionality that is illustrated on the images below.
As you can see from the picture the "Games" field did not pass validation, as
<rich:graphValidator> can be used to perform validation of a single input item.
The figure above shows that the entered data was revalidated after all fields were completed, and
the data did not pass revalidation since the total sum was incorrect.
162
Key Features
Name Value
component-type org.richfaces.beanValidator
component-class org.richfaces.component.html.HtmlbeanValidator
component-family org.richfaces.beanValidator
renderer-type org.richfaces.beanValidatorRenderer
tag-class org.richfaces.taglib.beanValidatorTag
Example:
...
<h:inputText value="#{validationBean.email}" id="email">
<rich:beanValidator summary="Invalid email"/>
</h:inputText>
...
import org.richfaces.component.html.HtmlCalendar;
...
HtmlbeanValidator mybeanValidator= new HtmlbeanValidator();
...
163
Chapter 6. The RichFaces Comp...
The <rich:beanValidator> component is defined in the same way as any JSF validator. Look
at the example below.
...
<rich:panel>
<f:facet name="header">
<h:outputText value="#{validationBean.progressString}" id="progress"/>
</f:facet>
<h:panelGrid columns="3">
<h:outputText value="Name:" />
<h:inputText value="#{validationBean.name}" id="name">
<rich:beanValidator summary="Invalid name"/>
</h:inputText>
<rich:message for="name" />
<h:outputText value="Email:" />
<h:inputText value="#{validationBean.email}" id="email">
<rich:beanValidator summary="Invalid email"/>
</h:inputText>
<rich:message for="email" />
<f:facet name="footer">
<a4j:commandButton value="Submit" action="#{validationBean.success}"
reRender="progress"/>
</f:facet>
</h:panelGrid>
</rich:panel>
...
Please play close attention on the bean code that contains the constraints defined with Hibernate
annotation which perform validation of the input data.
package org.richfaces.demo.validation;
import org.hibernate.validator.Email;
import org.hibernate.validator.Length;
import org.hibernate.validator.NotEmpty;
164
Details of Usage
@NotEmpty
@Length(min=3,max=12)
private String name;
@Email
@NotEmpty
private String email;
public ValidationBean() {
}
As you can see from the example that in order to validate the <rich:beanValidator> should be
nested into a input JSF or RichFaces component.
The component has the only attribute - "summary" which displays validation messages about
validation errors.
165
Chapter 6. The RichFaces Comp...
• Popup representation
• Disablement support
• Cells customization
166
Key Features
167
Chapter 6. The RichFaces Comp...
168
Key Features
169
Chapter 6. The RichFaces Comp...
170
Key Features
171
Chapter 6. The RichFaces Comp...
172
Creating the Component with a Page Tag
Name Value
component-type org.richfaces.Calendar
component-class org.richfaces.component.html.HtmlCalendar
component-family org.richfaces.Calendar
renderer-type org.richfaces.CalendarRenderer
tag-class org.richfaces.taglib.CalendarTag
Example:
...
<rich:calendar popup="false"/>
...
Example:
import org.richfaces.component.html.HtmlCalendar;
...
HtmlCalendar myCalendar = new HtmlCalendar();
...
173
Chapter 6. The RichFaces Comp...
Figure 6.7. Using the "popup" attribute: calendar calls after you click on
the button.
With help of the "currentDate" attribute you can define month and year which will be displayed
currently.
The "todayControlMode" attribute defines the mode for "today" control. Possible values are:
• "select" - (default) in this state "Today" button activation will scroll the calendar to the current
date and it become selected date
• "scroll" - in this mode "Today" activation will simply scroll the calendar to current month without
changing selected day.
The <rich:calendar> component can render pages of days in two modes. A mode could be
defined with the "mode" attribute with two possible parameters: "ajax" and "client". Default
value is "client".
174
Details of Usage
• Ajax
Calendar requests portions of data from Data Model for a page rendering. If "dataModel" attribute
has "null" value, data requests are not sent. In this case the "ajax" mode is equal to the "client".
• Client
Calendar loads an initial portion of data in a specified range and use this data to render months.
Additional data requests are not sent.
Note:
"ondataselect" attribute is used to define an event that is triggered before date selection.
"ondateselected" attribute is used to define an event that is triggered after date selection.
For example, to fire some event after date selection you should use <a4j:support> . And it should
be bound to "ondateselected" event as it's shown in the example below:
...
<rich:calendar id="date" value="#{bean.dateTest}">
<a4j:support event="ondateselected" reRender="mainTable"/>
</rich:calendar>
...
"ondataselect" could be used for possibility of date selection canceling. See an example below:
...
<rich:calendar id="date" value="#{bean.dateTest}" ondateselect="if (!confirm('Are you sure to
change date?')){return false;}"/>
...
"oncurrentdataselect" event is fired when the "next/previous month" or "next/previous year" button
is pressed, but the value is not applied yet (you can change the logic of applying the value). Also
this event could be used for possibility of "next/previous month" or "next/previous year" selection
canceling. See an example below:
175
Chapter 6. The RichFaces Comp...
Example:
...
<rich:calendar id="date" value="#{bean.dateTest}" oncurrentdateselect="if (!confirm('Are you
sure to change month(year)?')){return false;}"
oncurrentdateselected="alert('month(year) select:'+event.rich.date.toString());"/>
...
How to use these attributes see also on the RichFaces Users Forum [http://www.jboss.com/
index.html?module=bb&op=viewtopic&p=4092275#4092275].
Information about the "process" attribute usage you can find here.
• "buttonLabel" defines a label for the button. If the attribute is set "buttonIcon" and
"buttonIconDisabled" are ignored
The "direction" and "jointPoint" attributes are used for defining aspects of calendar appearance.
176
Details of Usage
The "label" attribute is a generic attribute. The "label" attribute provides an association between
a component, and the message that the component (indirectly) produced. This attribute defines
the parameters of localized error and informational messages that occur as a result of conversion,
validation, or other application actions during the request processing lifecycle. With the help of
this attribute you can replace the last parameter substitution token shown in the messages. For
example, {1} for "DoubleRangeValidator.MAXIMUM", {2} for "ShortConverter.SHORT".
The "defaultTime" attribute to set the default time value for the current date in two cases:
• If another date is selected and the value of the "resetTimeOnDateSelect" attribute is set to
"true"
Also you can use "weekNumber" facet with available {weekNumber}, {elementId}
elements and "weekDay" facet with {weekDayLabel}, {weekDayLabelShort},
{weekDayNumber}, {isWeekend}, {elementId} elements. {weekNumber}, {weekDayLabel},
{weekDayLabelShort}, {weekDayNumber} elements could be used for labels output,
{isWeekend}, {elementId} - for additional processing in JavaScript code.
177
Chapter 6. The RichFaces Comp...
Example:
...
<!-- Styles for cells -->
<style>
.width100{
width:100%;
}
.talign{
text-align:center;
}
</style>
...
...
<rich:calendar id="myCalendar" popup="true" locale="#{calendarBean.locale}"
value="#{bean.date}"
preloadRangeBegin="#{bean.date}" preloadRangeEnd="#{bean.date}"
cellWidth="40px" cellHeight="40px">
178
Details of Usage
<f:facet name="header">
<h:panelGrid columns="2" width="100%" columnClasses="width100, fake">
<h:outputText value="{selectedDateControl}" />
<h:outputText value="{todayControl}" style="font-weight:bold; text-align:left"/>
</h:panelGrid>
</f:facet>
<f:facet name="weekDay">
<h:panelGroup style="width:60px; overflow:hidden;" layout="block">
<h:outputText value="{weekDayLabelShort}"/>
</h:panelGroup>
</f:facet>
<f:facet name="weekNumber">
<h:panelGroup>
<h:outputText value="{weekNumber}" style="color:red"/>
</h:panelGroup>
</f:facet>
<f:facet name="footer">
<h:panelGrid columns="3" width="100%" columnClasses="fake, width100 talign">
<h:outputText value="{previousMonthControl}" style="font-weight:bold;"/>
<h:outputText value="{currentMonthControl}" style="font-weight:bold;"/>
<h:outputText value="{nextMonthControl}" style="font-weight:bold;"/>
</h:panelGrid>
</f:facet>
<h:outputText value="{day}"></h:outputText>
</rich:calendar>
...
This is a result:
179
Chapter 6. The RichFaces Comp...
It is possible to show and manage date. Except scrolling controls you can use quick month and
year selection feature. It's necessary to click on its field, i.e. current month control, and choose
required month and year.
180
Details of Usage
Also the <rich:calendar> component allows to show and manage time. It's necessary to define
time in a pattern (for example, it could be defined as "d/M/yy HH:mm"). Then after you choose
some data in the calendar, it becomes possible to manage time for this date. For time editing it's
necessary to click on its field (see a picture below). To clean the field click on the "Clean".
It's possible to handle events for calendar from JavaScript code. A simplest example of usage
JavaScript API is placed below:
Example:
...
<rich:calendar value="#{calendarBean.selectedDate}" id="calendarID"
181
Chapter 6. The RichFaces Comp...
locale="#{calendarBean.locale}"
popup="#{calendarBean.popup}"
datePattern="#{calendarBean.pattern}"
showApplyButton="#{calendarBean.showApply}" style="width:200px"/>
<a4j:commandLink onclick="$('formID:calendarID').component.doExpand(event)"
value="Expand"/>
...
Also the discussion about this problem can be found on the RichFaces Users Forum [http://
www.jboss.com/index.html?module=bb&op=viewtopic&p=4078301#4078301].
The <rich:calendar> component provides the possibility to use a special Data Model to define
data for element rendering. Data Model includes two major interfaces:
• CalendarDataModel
• CalendarDataModelItem
• CalendarDataModelItem[] getData(Date[]);
This method is called when it's necessary to represent the next block of CalendarDataItems.
It happens during navigation to the next (previous) month or in any other case when calendar
renders. This method is called in "Ajax" mode when the calendar renders a new page.
• Date getDate() - returns date from the item. Default implementation returns date.
• String getStyleClass() - returns string appended to the style class for the date span. For
example it could be "relevant holyday". It means that the class could be defined like the "rich-
cal-day-relevant-holyday" one. Default implementation returns empty string.
• Object getData() - returns any additional payload that must be JSON-serializable object. It
could be used in the custom date representation on the calendar (inside the custom facet).
182
JavaScript API
Note:
Function Description
selectDate(date) Selects the date specified. If the date isn't in
current month - performs request to select
isDateEnabled(date) Checks if given date is selectable (to be
implemented)
enableDate(date) Enables date cell control on the calendar (to be
implemented)
disableDate(date) Disables date cell control on the calendar (to
be implemented)
enableDates(date[]) Enables dates cell controls set on the calendar
(to be implemented)
disableDates(date[]) Disables dates cell controls set on the calendar
(to be implemented)
nextMonth() Navigates to next month
nextYear() Navigates to next year
prevMonth() Navigates to previous month
prevYear() Navigates to previous year
today() Selects today date
getSelectedDate() Returns currently selected date
Object getData() Returns additional data for the date
getCurrentMonth() Returns number of the month currently being
viewed
getCurrentYear() Returns number of the year currently being
viewed
doCollapse() Collapses calendar element
183
Chapter 6. The RichFaces Comp...
Function Description
doExpand() Expands calendar element
resetSelectedDate() Clears a selected day value
doSwitch() Inverts a state for the popup calendar
There are two ways to redefine the appearance of all <rich:calendar> components at once:
Table 6.58. Skin parameters redefinition for footers (footer, optional footer)
and names of working days
184
Skin Parameters Redefinition
Table 6.60. Skin parameters redefinition for a toolBar and names of months
Table 6.63. Skin parameters redefinition for cell with a current date
185
Chapter 6. The RichFaces Comp...
Table 6.65. Skin parameters redefinition for a popup element during quick
month and year selection
Table 6.67. Skin parameters redefinition for a selected month and year
Table 6.68. Skin parameters redefinition for a hovered month and year
Table 6.69. Skin parameters redefinition for a month items near split line
186
Skin Parameters Redefinition
Table 6.72. Skin parameters redefinition for "ok" and "cancel" buttons
Table 6.73. Skin parameters redefinition for a popup element during time
selection
Table 6.74. Skin parameters redefinition for a wrapper <td> element for an
input field
187
Chapter 6. The RichFaces Comp...
Table 6.76. Skin parameters redefinition for a wrapper <td> element for
spinner buttons
On the screenshot there are classes names that define styles for component elements.
188
Definition of Custom Style Classes
189
Chapter 6. The RichFaces Comp...
190
Definition of Custom Style Classes
Table 6.77. Classes names that define an input field and a button
appearance
191
Chapter 6. The RichFaces Comp...
Table 6.80. Classes names that define a popup element during quick month
and year selection
Class name Description
rich-calendar-date-layout Defines styles for a popup element during quick
year selection
rich-calendar-editor-layout-shadow Defines styles for a shadow
rich-calendar-editor-btn Defines styles for an inactive boundary date
rich-calendar-date-layout-split Defines styles for a wrapper <td> element for
month items near split line
rich-calendar-editor-btn-selected Defines styles for an selected boundary date
rich-calendar-editor-btn-over Defines styles for a boundary date when
pointer was moved onto
rich-calendar-editor-tool-over Defines styles for a hovered toolbar items
rich-calendar-editor-tool-press Defines styles for a pressed toolbar items
rich-calendar-date-layout-ok Defines styles for a "ok" button
rich-calendar-date-layout-cancel Defines styles for a "cancel" button
Table 6.81. Classes names that define a popup element during time
selection
Class name Description
rich-calendar-time-layout Defines styles for a popup element during time
selection
rich-calendar-editor-layout-shadow Defines styles for a shadow
rich-calendar-time-layout-fields Defines styles for a wrapper <td> element for
input fields and buttons
rich-calendar-spinner-input-container Defines styles for a wrapper <td> element for
an input field
rich-calendar-spinner-input Defines styles for an input field
rich-calendar-spinner-buttons Defines styles for a wrapper <td> element for
spinner buttons
rich-calendar-spinner-up Defines styles for a "up" button
rich-calendar-spinner-down Defines styles for a "down" button
rich-calendar-time-layout-ok Defines styles for a "ok" button
rich-calendar-time-layout-cancel Defines styles for a "cancel" button
In order to redefine styles for all <rich:calendar> 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.
192
Definition of Custom Style Classes
Example:
...
.rich-calendar-today {
background-color: #FF0000;
}
...
This is a result:
Also it's possible to change styles of particular <rich:calendar> component. In this case you
should create own style classes and use them in corresponding <rich:calendar> styleClass
attributes. An example is placed below:
Example:
...
.myFontClass{
font-style: italic;
}
...
The "inputClass" attribute for <rich:calendar> is defined as it's shown in the example below:
Example:
193
Chapter 6. The RichFaces Comp...
This is a result:
Figure 6.17. Redefinition styles with own classes and styleClass attributes
As it could be seen on the picture above, the font style for output text was changed.
How to use JavaScript API see on the RichFaces Users Forum [http://www.jboss.com/
index.html?module=bb&op=viewtopic&p=4078301#4078301].
194
Key Features
• Disablement support
195
Chapter 6. The RichFaces Comp...
196
Key Features
197
Chapter 6. The RichFaces Comp...
Name Value
component-type org.richfaces.ComboBox
component-class org.richfaces.component.html.HtmlComboBox
component-family org.richfaces.ComboBox
renderer-type org.richfaces.renderkit.ComboBoxRenderer
tag-class org.richfaces.taglib.ComboBoxTag
Example:
...
<rich:comboBox value="#{bean.state}" suggestionValues="#{bean.suggestions}" />
...
198
Creating the Component Dynamically Using
Java
6.28.4. Creating the Component Dynamically Using Java
Example:
import org.richfaces.component.html.HtmlComboBox;
...
HtmlComboBox myComboBox = new HtmlComboBox();
...
There are two ways to get values for the popup list of suggestions:
Example:
...
<rich:comboBox value="#{bean.state}" suggestionValues="#{bean.suggestions}" />
...
• Using the <f:selectItem /> or <f:selectItems /> facets which considers only "value" attribute.
Example:
...
<rich:comboBox value="#{bean.state}" valueChangeListener="#{bean.selectionChanged}">
<f:selectItems value="#{bean.selectItems}"/>
<f:selectItem itemValue="Oregon"/>
<f:selectItem itemValue="Pennsylvania"/>
<f:selectItem itemValue="Rhode Island"/>
<f:selectItem itemValue="South Carolina"/>
</rich:comboBox>
...
199
Chapter 6. The RichFaces Comp...
Popup list content loads at page render time. No additional requests could be performed on the
popup calling.
The "directInputSuggestions" attribute defines, how the first value from the suggested one
appears in an input field. If it's "true" the first value appears with the suggested part highlighted.
Example:
...
<rich:comboBox value="#{bean.state}" suggestionValues="#{bean.suggestions}"
directInputSuggestions="true" />
...
This is a result:
The "selectFirstOnUpdate" attribute defines if the first value from suggested is selected in a popup
list. If it's "false" nothing is selected in the list before a user hovers some item with the mouse.
Example:
...
<rich:comboBox value="#{bean.state}" suggestionValues="#{bean.suggestions}"
selectFirstOnUpdate="false" />
...
This is a result:
200
Details of Usage
The "defaultLabel" attribute defines the default label of the input element. Simple example is
placed below.
Example:
...
<rich:comboBox value="#{bean.state}" suggestionValues="#{bean.suggestions}"
defaultLabel="Select a city..." />
...
This is a result:
With the help of the "disabled" attribute you can disable the whole <rich:comboBox>
component. See the following example.
Example:
...
<rich:comboBox value="#{bean.state}" suggestionValues="#{bean.suggestions}"
defaultLabel="Select a city..." disabled="true" />
...
This is a result:
• "onlistcall" which is fired before the list opening and gives you a possibility to cancel list popup/
update
201
Chapter 6. The RichFaces Comp...
• "onselect" which gives you a possibility to send AJAX request when item is selected
• "listWidth" and "listHeight" attributes specify popup list sizes with values in pixels
• "width" attribute customizes the size of input element with values in pixels.
Function Description
showList() Shows the popup list
hideList() Hides the popup list
enable() Enables the control for input
disable() Disables the control for input
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:comboBox> components at once:
202
Skin Parameters Redefinition
203
Chapter 6. The RichFaces Comp...
204
Definition of Custom Style Classes
205
Chapter 6. The RichFaces Comp...
206
Definition of Custom Style Classes
In order to redefine styles for all <rich:comboBox> 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-combobox-list-decoration{
background-color:#ecf4fe;
}
...
This is a result:
Also it's possible to change styles of particular <rich:comboBox> component. In this case you
should create own style classes and use them in corresponding <rich:comboBox> styleClass
attributes. An example is placed below:
Example:
...
.myClass{
font-weight:bold;
}
...
The "listClass" attribute for <rich:comboBox> is defined as it's shown in the example below:
Example:
207
Chapter 6. The RichFaces Comp...
This is a result:
As it could be seen on the picture above, the font weight for items was changed.
208
Key Features
Name Value
component-type org.richfaces.ComponentControl
component-class org.richfaces.component.html.HtmlComponentControl
component-family org.richfaces.ComponentControl
209
Chapter 6. The RichFaces Comp...
Name Value
renderer-type org.richfaces.ComponentControlRenderer
tag-class org.richfaces.taglib.ComponentControlTag
Example:
...
<rich:componentControl attachTo="doExpandCalendarID" for="ccCalendarID" event="onclick"
operation="Expand" />
...
import org.richfaces.component.html.HtmlComponentControl;
...
HtmlComponentControl myComponentControl = new HtmlComponentControl();
...
...
<rich:componentControl attachTo="doExpandCalendarID" event="onclick" for="ccCalendarID"
operation="Expand"/>
...
In other words it means "clicking on the component with ID 'doExpandCalendarID', expands the
component with ID 'ccCalendarID'". It can be said, that <rich:componentControl> connects
two components with the help of JavaScript API function.
Component ID, to wich the event, that invokes JavaScript API function is applied, is defined with
"attachTo" attribute (see the exapmle above). If "attachTo" attribute is not defined, the component
will be attached to the parent component.
210
Details of Usage
Example:
...
<h:commandButton value="Show Modal Panel">
<rich:componentControl for="ccModalPanelID" event="onclick" operation="show"/> <!--
attached to the commandButton-->
</h:commandButton>
...
On the result page the component is rendered to JavaScript code. This means, that it is possible
to invoke the <rich:componentControl> handler operation as usual JavaScript function. This
function is called by name, specified in the component "name" attribute. The definition of "name"
attribute is shown on the example below:
...
<rich:componentControl name="func" event="onRowClick" for="menu" operation="show" />
...
Example:
...
<rich:componentControl name="func" event="onRowClick" for="menu" operation="show"
params=##{car.model}"/>
...
The alternative way for parameters transferring uses <f:param> attribute. As the code above,
the following code will represent the same functionality.
Example:
...
211
Chapter 6. The RichFaces Comp...
With the help of the "attachTiming" attribute you can define the page loading phase when
<rich:componentControl> is attached to source component. Possible values are:
In order to use <rich:componentControl> with another component you should place the id of
this component into "for" attribute field. All operations with defined component you can find in
the JavaScript API section of defined component.
Example:
...
<f:view>
<h:form>
<br />
<rich:toolTip id="toolTipFor" followMouse="false" direction="top-right" mode="ajax"
value="This is button" horizontalOffset="5" verticalOffset="5" layout="block" />
</h:form>
<h:commandButton id="ButtonID" value="Button">
<rich:componentControl for="toolTipFor" attachTo="ButtonID" operation="show"
event="onclick"/>
</h:commandButton>
</f:view>
...
This is a result:
212
Look-and-Feel Customization
As it could be seen in the picture above, the <rich:toolTip> shows after you click the button.
• Disablement support
213
Chapter 6. The RichFaces Comp...
214
Key Features
Name Value
component-type org.richfaces.ContextMenu
component-class org.richfaces.component.html.ContextMenu
component-family org.richfaces.ContextMenu
215
Chapter 6. The RichFaces Comp...
Name Value
renderer-type org.richfaces.DropDownMenuRenderer
tag-class org.richfaces.taglib.ContextMenuTagHandler
Example:
...
<rich:contextMenu event="oncontextmenu" attached="true">
...
import org.richfaces.component.html.ContextMenu;
...
html.ContextMenu myContextMenu = new html.ContextMenu();
...
If "attached" value is "true" (default value), component is attached to the parent component or to
the component, which "id" is specified in the "attachTo" attribute. An example is placed below.
Example:
...
<rich:contextMenu event="oncontextmenu" attachTo="pic1" submitMode="none">
<rich:menuItem value="Zoom In" onclick="enlarge();" id="zin"/>
<rich:menuItem value="Zoom Out" onclick="decrease();" id="zout"/>
216
Details of Usage
</rich:contextMenu>
<h:panelGrid columns="1" columnClasses="cent">
<h:panelGroup id="picture">
<h:graphicImage value="/richfaces/jQuery/images/pic1.png" id="pic"/>
</h:panelGroup>
</h:panelGrid>
<h:panelGrid columns="1" columnClasses="cent">
<h:panelGroup id="picture1">
<h:graphicImage value="/richfaces/jQuery/images/pic2.png" id="pic1"/>
</h:panelGroup>
</h:panelGrid>
...
...
<script type="text/javascript">
function enlarge(){
document.getElementById('pic').width=document.getElementById('pic').width*1.1;
document.getElementById('pic').height=document.getElementById('pic').height*1.1;
}
function decrease(){
document.getElementById('pic').width=document.getElementById('pic').width*0.9;
document.getElementById('pic').height=document.getElementById('pic').height*0.9;
}
</script>
...
In the example a picture zooming possibility with <rich:contextMenu> component usage was
shown. The picture is placed on the <h:panelGroup> component. The <rich:contextMenu>
component is not nested to <h:panelGroup> and has a value of the "attachTo" attribute defined
as "pic1". Thus, the context menu is attached to the component, which "id" is "pic1". The
context menu has two items to zoom in (zoom out) a picture by "onclick" event. For earch item
corresponding JavaScript function is defined to provide necessary action as a result of the clicking
on it. For the menu is defined an "oncontextmenu" event to call the context menu on a right
click mouse event.
In the example the context menu is defined for the parent <h:panelGroup> component with a
value of "id" attribute equal to "picture" You should be careful with such definition, because
a client context menu is looked for a DOM element with a client Id of a parent component
on a server. If a parent component doesn't encode an Id on a client, it can't be found by the
<rich:contextMenu> and it's attached to its closest parent in a DOM tree.
217
Chapter 6. The RichFaces Comp...
If the "attached" attribute has "false" value, component activates via JavaScript API with
assistance of <rich:componentControl> . An example is placed below.
Example:
...
<h:form id="form">
<rich:contextMenu attached="false" id="menu" submitMode="ajax">
<rich:menuItem ajaxSingle="true">
<b>{car} {model}</b> details
<a4j:actionParam name="det" assignTo="#{ddmenu.current}" value="{car}
{model} details"/>
</rich:menuItem>
<rich:menuGroup value="Actions">
<rich:menuItem ajaxSingle="true">
Put <b>{car} {model}</b> To Basket
<a4j:actionParam name="bask" assignTo="#{ddmenu.current}"
value="Put {car} {model} To Basket"/>
</rich:menuItem>
<rich:menuItem value="Read Comments" ajaxSingle="true">
<a4j:actionParam name="bask" assignTo="#{ddmenu.current}"
value="Read Comments"/>
</rich:menuItem>
<rich:menuItem ajaxSingle="true">
Go to <b>{car}</b> site
<a4j:actionParam name="bask" assignTo="#{ddmenu.current}"
value="Go to {car} site"/>
</rich:menuItem>
</rich:menuGroup>
</rich:contextMenu>
<h:panelGrid columns="2">
<rich:dataTable value="#{dataTableScrollerBean.tenRandomCars}" var="car"
id="table"
onRowMouseOver="this.style.backgroundColor='#F8F8F8'"
onRowMouseOut="this.style.backgroundColor='#{a4jSkin.tableBackgroundColor}'"
rowClasses="cur">
<rich:column>
<f:facet name="header">Make</f:facet>
<h:outputText value="#{car.make}"/>
</rich:column>
<rich:column>
<f:facet name="header">Model</f:facet>
218
Details of Usage
<h:outputText value="#{car.model}"/>
</rich:column>
<rich:column>
<f:facet name="header">Price</f:facet>
<h:outputText value="#{car.price}" />
</rich:column>
<a4j:outputPanel ajaxRendered="true">
<rich:panel>
<f:facet name="header">Last Menu Action</f:facet>
<h:outputText value="#{ddmenu.current}"></h:outputText>
</rich:panel>
</a4j:outputPanel>
</h:panelGrid>
</h:form>
...
This is a result:
219
Chapter 6. The RichFaces Comp...
In the example the context menu is activated (by clicking on the left mouse button) on the table
via JavaScript API with assistance of <rich:componentControl> . The attribute "for" contains a
value of the <rich:contextMenu> Id. For menu appearance Java Script API function "show()"
is used. It is defined with "operation" attribute for the <rich:componentControl> component.
Context menu is recreated after the every call on a client and new {car} and {model} values are
inserted in it. In the example for a menu customization macrosubstitutions were used.
The <rich:contextMenu> component can be defined once on a page and can be used as
shared for different components (this is the main difference from the <rich:dropDownMenu>
component). It's necessary to define it once on a page (as it was shown in the example
above [218]) and activate it on required components via JavaScript API with assistance of
<rich:componentControl> .
• Server (default)
• Ajax
220
JavaScript API
• None
The "action" and "actionListener" item's attributes are ignored. Menu items don't fire any submits
themselves. The behavior is fully defined by the components nested inside items.
Note:
Note:
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:contextMenu> components at once:
221
Chapter 6. The RichFaces Comp...
222
Definition of Custom Style Classes
In order to redefine styles for all <rich:contextMenu> 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-menu-item{
font-style:italic;
}
...
This is a result:
In the example the font style for row items was changed.
Also it's possible to change styles of particular <rich:contextMenu> component. In this case you
should create own style classes and use them in corresponding <rich:contextMenu> styleClass
attributes. An example is placed below:
Example:
...
.myClass{
font-weight:bold;
}
...
The "rowClasses" attribute for <h:panelGrid> is defined as it's shown in the example below:
Example:
223
Chapter 6. The RichFaces Comp...
This is a result:
Figure 6.32. Redefinition styles with own classes and styleClass attributes
As it could be seen on the picture above, the font weight for row items was changed.
224
Key Features
225
Chapter 6. The RichFaces Comp...
226
Key Features
227
Chapter 6. The RichFaces Comp...
228
Creating the Component with a Page Tag
Example:
...
<rich:dataFilterSlider sliderListener="#{mybean.doSlide}" startRange="0"
endRange="50000" increment="10000" handleValue="1" />
...
import org.richfaces.component.html.HtmlDataFilterSlider;
...
HtmlDataFilterSlider mySlider = new HtmlDataFilterSlider();
...
229
Chapter 6. The RichFaces Comp...
Example:
...
<rich:dataFilterSlider sliderListener="#{mybean.doSlide}"
startRange="0"
endRange="50000"
increment="10000"
handleValue="1"
for="carIndex"
forValRef="inventoryList.carInventory"
filterBy="getMileage"
/>
...
<h:dataTable id="carIndex">
...
</h:dataTable>
...
• "forValRef" is a string which is used in a value attribute of the target UIData component. It's
designed for resetting the UIData component back to the original list provided by a backing bean.
• "filterBy" is a getter of an object member that is to be compared to a slider value. It's a value
that is used in results filtering.
"handleValue" is an attribute for keeping the current handler position on the dataFilterSlider
component. Based on the current value, appropriate values obtained from a getter method defined
in "filterBy" are filtered.
One more important attribute is a "storeResults" one that allows the dataFilterSlider component
to keep UIData target object in session.
If it's necessary the component submits a form on event of a handler state changing, use the
"onSlide" attribute ( "onChange" is its alias). When the attribute definition = "true",
submission on this event is defined.
Information about the "process" attribute usage you can find here.
230
Relevant Resources Links
• Skin support
231
Chapter 6. The RichFaces Comp...
232
Key Features
233
Chapter 6. The RichFaces Comp...
234
Key Features
Name Value
component-type org.richfaces.Datascroller
component-class org.richfaces.component.html.HtmlDatascroller
component-family org.richfaces.Datascroller
235
Chapter 6. The RichFaces Comp...
Name Value
renderer-type org.richfaces.DataScrollerRenderer
tag-class org.richfaces.taglib.DatascrollerTag
Example:
...
<h:dataTable id="table">
...
</h:dataTable>
...
<rich:datascroller for="table"/>
...
Example:
import org.richfaces.component.html.HtmlDatascroller;
...
HtmlDatascroller myScroll = new HtmlDatascroller();
...
The component should be placed into footer of the parent table or be bound to it with the "for"
attribute. Note, that "for" is evaluated on view build, not on view render, that is why it will ignore
JSTL tags.
The table should also have the defined "rows" attribute limiting the quantity of inputted table rows.
The scroller could limit the maximum quantity of rendered links on the table pages with the help
of the "maxPages" attribute.
236
Details of Usage
• The controls of fast switching: "first", "last", "next", "previous", "fastforward", "fastrewind"
The controls of fast switching are created adding the facets component with the corresponding
name:
Example:
...
<rich:datascroller for="table" maxPages="10">
<f:facet name="first">
<h:outputText value="First"/>
</f:facet>
<f:facet name="last">
<h:outputText value="Last"/>
</f:facet>
</rich:datascroller>
...
There are also facets used to create the disabled states: "first_disabled",
"last_disabled", "next_disabled", "previous_disabled", "fastforward_disabled",
"fastrewind_disabled".
237
Chapter 6. The RichFaces Comp...
The "page" is a value-binding attribute used to define and save current page number. The
example is placed below.
Example:
...
<h:form id="myForm">
<rich:dataTable id="carList" rows="7" value="#{dataTableScrollerBean.allCars}"
var="category">
<f:facet name="header">
<rich:columnGroup>
<h:column>
<h:outputText value="Make" />
</h:column>
<h:column>
<h:outputText value="Model" />
</h:column>
<h:column>
<h:outputText value="Price" />
</h:column>
</rich:columnGroup>
</f:facet>
<h:column>
<h:outputText value="#{category.make}" />
</h:column>
<h:column>
<h:outputText value="#{category.model}" />
</h:column>
<h:column>
<h:outputText value="#{category.price}" />
</h:column>
</rich:dataTable>
<rich:datascroller id="sc2" for="carList" reRender="sc1" maxPages="7"
page="#{dataTableScrollerBean.scrollerPage}" />
<h:panelGrid>
<h:panelGroup>
<h:outputText value="Set current page number:" />
<h:inputText value="#{dataTableScrollerBean.scrollerPage}" id="sc1" size="1"/>
<h:commandButton value="Set" />
</h:panelGroup>
</h:panelGrid>
</h:form>
238
Details of Usage
...
In the example above you can enter the page number you want and set it by clicking on the
<h:commandButton> . By the way, if you use <rich:datascroller> page links the input field
rerenders and current page number changes.
This is a result:
The "pageIndexVar" and "pagesVar" attributes define a request scope variables and provide
an ability to show the current page and the number of pages in the <rich:datascroller> .
These attributes are used for definition the names of variables, that is used in the facet with name
"pages" . An example can be found below:
Example:
...
<h:form>
<rich:dataTable value="#{capitalsBean.capitals}" var="cap" rows="5">
<rich:column>
<h:outputText value="#{cap.name}" />
</rich:column>
<f:facet name="footer">
<rich:datascroller pageIndexVar="pageIndex" pagesVar="pages">
<f:facet name="pages">
<h:outputText value="#{pageIndex} / #{pages}" />
</f:facet>
</rich:datascroller>
</f:facet>
239
Chapter 6. The RichFaces Comp...
</rich:dataTable>
</h:form>
...
It's possible to insert optional separators between controls. For this purpose use a
"controlSeparator" facet. An example is placed below.
...
<f:facet name="controlSeparator">
<h:graphicImage value="/image/sep.png"/>
</f:facet>
...
Starting from 3.2.1 of RichFaces multiple <rich:datascroller> instances behavior and page
bindings are corrected. Incorrect page after model changes handling is added. Phase Listener
called before RenderResponce scans the page for the <rich:datascroller> and performs the
following operations:
• Checks if the <rich:datascroller> is rendered. (If the checking generates an exception, the
<rich:datascroller> is considered to be not rendered )
Information about the "process" attribute usage you can find here.
Note:
Make sure, that all <rich:datascroller> components, defined for a table, have
same values for "pages" attributes. The page, specified in the last "page" , will
be rendered in browser.
There are two ways to redefine the appearance of all <rich:datascroller> components at once:
240
Skin Parameters Redefinition
On the screenshot there are classes names that define styles for component elements.
241
Chapter 6. The RichFaces Comp...
In order to redefine styles for all <rich:datascroller> components on a page using CSS, it's
enough to create classes with the same names (possible classes could be found in the table
above) and define necessary properties in them. An example is placed below:
Example:
...
.rich-datascr-button{
color: #CD6600;
}
...
This is a result:
242
Relevant Resources Links
Also it's possible to change styles of particular <rich:datascroller> component. In this case you
should create own style classes and use them in corresponding <rich:datascroller> styleClass
attributes. An example is placed below:
Example:
...
.myClass{
background-color: #C6E2FF;
}
...
The "styleClass" attribute for <rich:datascroller> is defined as it's shown in the example below:
Example:
This is a result:
Figure 6.39. Redefinition styles with own classes and styleClass attributes
As it could be seen on the picture above, background color of the selected cell on scroller was
changed.
The solution about how to do correct pagination using datascroller (load a part of
data from database) can be found on the RichFaces Users Forum [http://www.jboss.com/
index.html?module=bb&op=viewtopic&p=4060199#4060199].
243
Chapter 6. The RichFaces Comp...
244
Key Features
245
Chapter 6. The RichFaces Comp...
Name Value
component-type org.richfaces.Column
tag-class org.richfaces.taglib.ColumnsTagHandler
Example:
...
<rich:dataTable value="#{capitalsBean.capitals}" var="cap">
<rich:columns value="#{capitalsBean.labels}" var="col" index="index">
<h:outputText value="#{cap[index]}" />
</rich:columns>
246
Creating the Component Dynamically Using
Java
</rich:dataTable>
...
Example:
import org.richfaces.component.html.HtmlColumns;
...
HtmlColumns myColumns = new HtmlColumns();
...
The <rich:columns> component gets a list from data model and outputs corresponding set of
columns inside <rich:dataTable> on a page. It is possible to use "header" and "footer" facets
with <rich:columns> component.
The "value" and "var" attributes are used to access the values of collection.
Example:
...
<rich:dataTable value="#{capitalsBean.capitals}" var="cap">
<rich:columns value="#{capitalsBean.labels}" var="col" index="index">
<f:facet name="header">
<h:outputText value="#{col.text}" />
</f:facet>
<h:outputText value="#{cap[index]}" />
<f:facet name="footer">
<h:outputText value="#{col.text}" />
</f:facet>
</rich:columns>
</rich:dataTable>
...
The "rows" attribute defines the number of rows to be displayed. If the value of this attribute is
zero, all remaining rows in the table are displayed on a page.
247
Chapter 6. The RichFaces Comp...
The "begin" attribute contains the first iteration item. Note, that iteration begins from zero.
With the help of the attributes described below you can customize the output, i.e. define which
columns and how many rows appear on a page.
Example:
...
<rich:dataTable value="#{capitalsBean.capitals}" var="cap">
<rich:columns value="#{capitalsBean.labels}" var="col" index="index" rows="0"
columns="3" begin="1" end="2">
<f:facet name="header">
<h:outputText value="#{col.text}" />
</f:facet>
<h:outputText value="#{cap[index]}" />
</rich:columns>
</rich:dataTable>
...
In the example below, columns from first to second and all rows are shown in the
<rich:dataTable> .
The <rich:columns> component does not prevent to use <rich:column> . In the following
example one column renders in any way and another columns could be picked from the model.
248
Details of Usage
Example:
...
<rich:dataTable value="#{rowBean.rows}" var="row">
<rich:column>
<h:outputText value ="#{row.columnValue}"/>
</rich:column>
<rich:columns value="#{colBean.columns}" var="col">
<f:facet name="header">
<h:outputText value="#{col.header}"/>
</f:facet>
<h:outputText value="#{row.columnValue}"/>
<f:facet name="footer">
<h:outputText value="#{col.footer}"/>
</f:facet>
</rich:columns>
</rich:dataTable>
...
In order to group columns with text information into one row, use the "colspan" attribute, which
is similar to an HTML one. In the following example the third column contains 3 columns. In
addition, it's necessary to specify that the next column begins from the first row with the help of
the breakBefore = "true" .
Example:
...
<rich:dataTable value="#{columns.data1}" var="data">
<rich:column>
<h:outputText value="#{column.Item1}" />
</rich:column>
<rich:column>
<h:outputText value="#{column.Item2}" />
</rich:column>
<rich:column>
<h:outputText value="#{column.Item3}" />
</rich:column>
<rich:columns columns="3" colspan="3" breakBefore="true">
<h:outputText value="#{data.str0}" />
</rich:columns>
</rich:dataTable>
...
249
Chapter 6. The RichFaces Comp...
The same way is used for columns grouping with the "rowspan" attribute that is similar to an
HTML. The only thing to add in the example is an instruction to move onto the next row for each
next after the second column.
Example:
...
<rich:dataTable value="#{columns.data1}" var="data">
<rich:columns columns="2" rowspan="3">
<h:outputText value="#{data.str0}" />
</rich:columns>
<rich:column>
<h:outputText value="#{column.Item1}" />
</rich:column>
<rich:column breakBefore="true">
<h:outputText value="#{column.Item2}" />
</rich:column>
<rich:column breakBefore="true">
<h:outputText value="#{column.Item3}" />
</rich:column>
</rich:dataTable>
...
Note:
...
<rich:dataTable value="#{bean.data}" var="var">
<rich:columns value="#{var.columns}">
...
</rich:columns>
</rich:dataTable>
250
Look-and-Feel Customization
...
...
<c:forEach items="#{bean.data}" var="var">
<rich:columns value="#{var.columns}">
...
</rich:columns>
</c:forEach>
...
There are two ways to redefine the appearance of all <rich:columns> components at once:
In order to redefine styles for all <rich:columns> 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-table-subheadercell{
251
Chapter 6. The RichFaces Comp...
color: #a0a0a0;
}
...
This is a result:
Also it's possible to change styles of particular <rich:columns> component. In this case you
should create own style classes and use them in corresponding <rich:columns> styleClass
attributes. An example is placed below:
Example:
...
.myClass {
font-style: oblique;
}
...
The "styleClass" attribute for <rich:columns> is defined as it's shown in the example below:
Example:
<rich:columns styleClass="myClass">
This is a result:
252
Relevant Resources Links
Figure 6.43. Redefinition styles with own classes and styleClass attributes
As it could be seen on the picture above, the font style for columns was changed.
253
Chapter 6. The RichFaces Comp...
254
Creating the Component with a Page Tag
Name Value
component-type org.richfaces.ColumnGroup
component-class org.richfaces.component.html.HtmlColumnGroup
component-family org.richfaces.ColumnGroup
renderer-type org.richfaces.ColumnGroupRenderer
tag-class org.richfaces.taglib.ColumnGroupTag
Example:
...
<rich:columnGroup>
<rich:column>
<h:outputText value="Column1"/>
</rich:column>
<rich:column>
255
Chapter 6. The RichFaces Comp...
<h:outputText value="Column2"/>
</rich:column>
</rich:columnGroup>
...
Example:
import org.richfaces.component.html.HtmlColumnGroup;
...
HtmlColumnGroup myRow = new HtmlColumnGroup();
...
The <rich:columnGroup> component combines columns set wrapping them into the <tr>
element and outputting them into one row. Columns are combined in a group the same way as
when the "breakBefore" attribute is used for columns to add a moving to the next rows, but the
first variant is clearer from a source code. Hence, the following simple examples are very same.
Example:
...
<rich:dataTable value="#{capitalsBean.capitals}" var="cap" rows="5" id="sublist">
<rich:column colspan="3">
<f:facet name="header">State Flag</f:facet>
<h:graphicImage value="#{cap.stateFlag}"/>
</rich:column>
<rich:columnGroup>
<rich:column>
<h:outputText value="#{cap.state}"/>
</rich:column>
<rich:column >
<h:outputText value="#{cap.name}"/>
</rich:column>
<rich:column >
<h:outputText value="#{cap.timeZone}"/>
</rich:column>
</rich:columnGroup>
</rich:dataTable>
256
Details of Usage
...
Example:
...
<rich:dataTable value="#{capitalsBean.capitals}" var="cap" rows="5" id="sublist">
<rich:column colspan="3">
<f:facet name="header">State Flag</f:facet>
<h:graphicImage value="#{cap.stateFlag}"/>
</rich:column>
<rich:column breakBefore="true">
<h:outputText value="#{cap.state}"/>
</rich:column>
<rich:column breakBefore="true">
<h:outputText value="#{cap.name}"/>
</rich:column>
<rich:column >
<h:outputText value="#{cap.timeZone}"/>
</rich:column>
</rich:dataTable>
....
257
Chapter 6. The RichFaces Comp...
It's also possible to use the component for output of complex headers in a table. For example
adding of a complex header to a facet for the whole table looks the following way:
Example:
...
<f:facet name="header">
<rich:columnGroup>
<rich:column rowspan="2">
<h:outputText value="State Flag"/>
</rich:column>
<rich:column colspan="3">
<h:outputText value="State Info"/>
</rich:column>
<rich:column breakBefore="true">
<h:outputText value="State Name"/>
</rich:column>
<rich:column>
<h:outputText value="State Capital"/>
</rich:column>
<rich:column>
<h:outputText value="Time Zone"/>
</rich:column>
</rich:columnGroup>
258
Look-and-Feel Customization
</f:facet>
...
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:columnGroup> components at once:
Skin parameters redefinition for <rich:columnGroup> are the same as for the <rich:dataTable>
component.
Custom style classes for <rich:columnGroup> are the same as for the <rich:dataTable>
component.
In order to redefine styles for all <rich:columnGroup> 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.
259
Chapter 6. The RichFaces Comp...
Example:
...
.rich-table-cell{
color: #316ac5;
}
...
This is a result:
Also it's possible to change styles of particular <rich:columnGroup> component. In this case
you should create own style classes and use them in corresponding <rich:columnGroup>
styleClass attributes. An example is placed below:
Example:
...
.myClass{
background-color: #c0c0c0;
}
...
260
Relevant Resources Links
The "columnClasses" attribute for <rich:columnGroup> is defined as it's shown in the example
below:
Example:
<rich:columnGroup columnClasses="myClass">
This is a result:
Figure 6.48. Redefinition styles with own classes and styleClass attributes
As it could be seen on the picture above, the background color for columns was changed.
6.35.1. Description
261
Chapter 6. The RichFaces Comp...
262
Key Features
263
Chapter 6. The RichFaces Comp...
Name Value
component-type org.richfaces.Column
component-class org.richfaces.component.html.HtmlColumn
component-family org.richfaces.Column
renderer-type org.richfaces.ColumnRenderer
tag-class org.richfaces.taglib.ColumnTag
To create the simplest variant of column on a page, use the following syntax:
Example:
...
<rich:dataTable var="set">
<rich:column>
<h:outputText value="#{set.property1}"/>
</rich:column>
<!--Set of another columns and header/footer facets-->
</rich:dataTable>
...
Example:
import org.richfaces.component.html.HtmlColumn;
264
Details of Usage
...
HtmlColumn myColumn = new HtmlColumn();
...
To output a simple table, the <rich:column> component is used the same way as the standard
<h:column> , i.e. the following code on a page is used:
Example:
...
<rich:dataTable value="#{capitalsBean.capitals}" var="cap" rows="5">
<rich:column>
<f:facet name="header">State Flag</f:facet>
<h:graphicImage value="#{cap.stateFlag}"/>
</rich:column>
<rich:column>
<f:facet name="header">State Name</f:facet>
<h:outputText value="#{cap.state}"/>
</rich:column>
<rich:column >
<f:facet name="header">State Capital</f:facet>
<h:outputText value="#{cap.name}"/>
</rich:column>
<rich:column>
<f:facet name="header">Time Zone</f:facet>
<h:outputText value="#{cap.timeZone}"/>
</rich:column>
</rich:dataTable>
...
265
Chapter 6. The RichFaces Comp...
Now, in order to group columns with text information into one row in one column with a flag, use
the "colspan" attribute, which is similar to an HTML one, specifying that the first column contains
3 columns. In addition, it's necessary to specify that the next column begins from the first row with
the help of the breakBefore="true".
Example:
...
<rich:dataTable value="#{capitalsBean.capitals}" var="cap" rows="5">
<rich:column colspan="3">
<h:graphicImage value="#{cap.stateFlag}"/>
</rich:column>
<rich:column breakBefore="true">
<h:outputText value="#{cap.state}"/>
</rich:column>
<rich:column >
<h:outputText value="#{cap.name}"/>
</rich:column>
<rich:column>
<h:outputText value="#{cap.timeZone}"/>
</rich:column>
</rich:dataTable>
...
266
Details of Usage
The same way is used for columns grouping with the "rowspan" attribute that is similar to an HTML
one responsible for rows quantity definition occupied with the current one. The only thing to add
in the example is an instruction to move onto the next row for each next after the second column.
Example:
...
<rich:dataTable value="#{capitalsBean.capitals}" var="cap" rows="5">
<rich:column rowspan="3">
<f:facet name="header">State Flag</f:facet>
<h:graphicImage value="#{cap.stateFlag}"/>
</rich:column>
<rich:column>
<f:facet name="header">State Info</f:facet>
<h:outputText value="#{cap.state}"/>
</rich:column>
<rich:column breakBefore="true">
<h:outputText value="#{cap.name}"/>
</rich:column>
<rich:column breakBefore="true">
<h:outputText value="#{cap.timeZone}"/>
</rich:column>
</rich:dataTable>
...
267
Chapter 6. The RichFaces Comp...
As a result:
Hence, additionally to a standard output of a particular row provided with the <h:column>
component, it becomes possible to group easily the rows with special HTML attribute.
The columns also could be grouped in a particular way with the help of the <h:columnGroup>
component that is described in the following chapter.
6.35.6.1. Sorting
In order to sort the columns you should use "sortBy" attribute that indicates what values to be
sorted. In order to sort the column you should click on its header. See the following example.
Example:
...
<h:form>
<rich:dataTable value="#{capitalsBean.capitals}" var="cap" width="300px">
268
Sorting and Filtering
<f:facet name="header">
<h:outputText value="Sorting Example"/>
</f:facet>
<rich:column sortBy="#{cap.state}">
<f:facet name="header">
<h:outputText value="State Name"/>
</f:facet>
<h:outputText value="#{cap.state}"/>
</rich:column>
<rich:column sortBy="#{cap.name}">
<f:facet name="header">
<h:outputText value="State Capital"/>
</f:facet>
<h:outputText value="#{cap.name}"/>
</rich:column>
</rich:dataTable>
</h:form>
...
This is result:
The "selfSorted" attribute that would add the possibility of automatic sorting by clicking the column
header. Default value is "true". In the example below the second column is unavailable for sorting.
Example:
...
<rich:dataTable value="#{capitalsBean.capitals}" var="cap">
<rich:column>
269
Chapter 6. The RichFaces Comp...
<f:facet name="header">
<h:outputText value="State Flag"/>
</f:facet>
<h:graphicImage value="#{cap.stateFlag}"/>
</rich:column>
<rich:column sortBy="#{cap.state}" selfSorted="false">
<f:facet name="header">
<h:outputText value="State Name"/>
</f:facet>
<h:outputText value="#{cap.state}"/>
</rich:column>
</rich:dataTable>
...
"sortOrder" attribute is used for changing the sorting of columns by means of external controls.
Example:
...
<h:form>
<rich:dataTable value="#{capitalsBean.capitals}" var="cap" width="300px">
<f:facet name="header">
<h:outputText value="Sorting Example"/>
</f:facet>
<rich:column sortBy="#{cap.state}" sortOrder="ASCENDING">
<f:facet name="header">
<h:outputText value="State Name"/>
</f:facet>
<h:outputText value="#{cap.state}"/>
</rich:column>
<rich:column sortBy="#{cap.name}" sortOrder="DESCENDING">
<f:facet name="header">
<h:outputText value="State Capital"/>
</f:facet>
<h:outputText value="#{cap.name}"/>
</rich:column>
270
Sorting and Filtering
</rich:dataTable>
</h:form>
...
In the example above the first column is sorted in descending order. But if recurring rows appear
in the table the relative second column are sorted in ascending order.
You can customize the sorting's icon element using "rich-sort-icon" class.
The "sortPriority" attribute defines a set of column ids in the order the columns could be set.
If the columns sort order changed externally sort priorities could be used to define which columns
will be sorted first.
Example:
...
<rich:scrollableDataTable rowKeyVar="rkv" frozenColCount="1"
id="carList" columnClasses="col" value="#{dataTableScrollerBean.allCars}" var="category"
sortMode="single" binding="#{dataTableScrollerBean.table}"
selection="#{dataTableScrollerBean.selection}">
<rich:column id="make" sortable="true">
<f:facet name="header">
<h:outputText styleClass="headerText" value="Make"/>
</f:facet>
<h:outputText value="#{category.make}"/>
</rich:column>
271
Chapter 6. The RichFaces Comp...
<rich:column id="model">
<f:facet name="header">
<h:outputText styleClass="headerText" value="Model"/>
</f:facet>
<h:outputText value="#{category.model}"/>
</rich:column>
<rich:column id="price">
<f:facet name="header">
<h:outputText styleClass="headerText" value="Price"/>
</f:facet>
<h:outputText value="#{category.price}"/>
</rich:column>
</rich:scrollableDataTable>
...
"sortExpression" attribute defines a bean property which is used for sorting of a column.
6.35.6.2. Filtering
• Using built-in filtering. It uses startsWith() function to make filtering. In this case you need
to define "filterBy" attribute at column you want to be filterable. This attribute defines iterable
object property which is used when filtering performed.
The "filterValue" attribute is used to get or change current filtering value. It could be defined with
initial filtering value on the page or as value binding to get/change it on server. If the "filterValue"
attribute isn't empty from the beginning table is filtered on the first rendering.
272
Sorting and Filtering
You can customize the input form using "rich-filter-input" CSS class.
In order to change filter event you could use "filterEvent" attribute on column, e.g.
"onblur"(default value).
Example:
...
<rich:dataTable value="#{capitalsBean.capitals}" var="cap" width="500px">
<rich:column filterBy="#{cap.state}" filterValue="#{filterName.filterBean}"
filterEvent="onkeyup">
<h:outputText value="#{cap.state}"/>
</rich:column>
<rich:column filterBy="#{cap.name}" filterEvent="onkeyup">
<h:outputText value="#{cap.name}"/>
</rich:column>
</rich:dataTable>
...
• Using external filtering. In this case you need to write your custom filtering function or expression
and define controls.
The "filterExpression" attribute is used to define expression evaluated to boolean value. This
expression checks if the object satisfies filtering condition.
The "filterMethod" attribute is defined with method binding. This method accepts on Object
parameter and return boolean value. So, this method also could be used to check if the object
satisfies filtering condition. The usage of this attribute is the best way for implementing your
own complex business logic.
273
Chapter 6. The RichFaces Comp...
Example:
...
<rich:dataTable value="#{capitalsBean.capitals}" var="cap" id="table">
<rich:column filterMethod="#{filteringBean.filterStates}">
<f:facet name="header">
<h:inputText value="#{filteringBean.filterValue}" id="input">
<a4j:support event="onkeyup" reRender="table"
ignoreDupResponses="true" requestDelay="700" focus="input" />
</h:inputText>
</f:facet>
<h:outputText value="#{cap.state}" />
</rich:column>
<rich:column filterExpression="#{fn:containsIgnoreCase(cap.timeZone,
filteringBean.filterZone)}">
<f:facet name="header">
<h:selectOneMenu value="#{filteringBean.filterZone}">
<f:selectItems value="#{filteringBean.filterZones}" />
<a4j:support event="onchange" reRender="table" />
</h:selectOneMenu>
</f:facet>
<h:outputText value="#{cap.timeZone}" />
</rich:column>
</rich:dataTable>
...
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:column> components at once:
Skin parameters redefinition for <rich:column> are the same as for the <rich:dataTable>
component.
274
Definition of Custom Style Classes
Custom style classes for <rich:column> are the same as for the <rich:dataTable> component.
In order to redefine styles for all <rich:column> 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-table-cell{
font-style: italic;
}
...
This is a result:
Also it's possible to change styles of particular <rich:column> component. In this case you
should create own style classes and use them in corresponding <rich:column> styleClass
attributes. An example is placed below:
Example:
...
.myClass{
font-weight: bolder;
}
275
Chapter 6. The RichFaces Comp...
...
The "styleClass" attribute for <rich:column> is defined as it's shown in the example below:
Example:
<rich:column styleClass="myClass">
This is a result:
Figure 6.58. Redefinition styles with own classes and styleClass attributes
As it could be seen on the picture above, the font weight for second column was changed.
6.36.1. Description
The component to render data as a grid that allows choosing data from a model and obtains
built-in support of Ajax updates.
276
Key Features
277
Chapter 6. The RichFaces Comp...
278
Key Features
279
Chapter 6. The RichFaces Comp...
280
Creating the Component with a Page Tag
Name Value
component-type org.richfaces.DataGrid
component-class org.richfaces.component.html.HtmlDataGrid
component-family org.richfaces.DataGrid
renderer-type org.richfaces.DataGridRenderer
tag-class org.richfaces.taglib.DataGridTag
Example:
...
<rich:dataGrid value="#{dataTableScrollerBean.allCars}" var="car">
281
Chapter 6. The RichFaces Comp...
<h:outputText value="#{car.model}"/>
</rich:dataGrid>
...
import org.richfaces.component.html.HtmlDataGrid;
...
HtmlDataGrid myList = new HtmlDataGrid();
...
• Limit number of output elements ( "elements" attribute) and define first element for output (
"first" attribute)
Here is an example:
Example:
...
<rich:panel style="width:150px;height:200px;">
<h:form>
<rich:dataGrid value="#{dataTableScrollerBean.allCars}" var="car" columns="2"
elements="4" first="1">
<f:facet name="header">
<h:outputText value="Car Store"></h:outputText>
</f:facet>
<rich:panel>
<f:facet name="header">
<h:outputText value="#{car.make} #{car.model}"></h:outputText>
</f:facet>
<h:panelGrid columns="2">
282
Details of Usage
This is a result:
The component was created basing on the <a4j:repeat> component and as a result it could
be partially updated with Ajax. "ajaxKeys" attribute allows to define row keys that are updated
after an Ajax request.
Here is an example:
Example:
...
283
Chapter 6. The RichFaces Comp...
In the example "reRender" attribute contains value of "id" attribute for <rich:dataGrid>
component. As a result the component is updated after an Ajax request.
There are two ways to redefine the appearance of all <rich:dataGrid> components at once:
In order to redefine styles for all <rich:dataGrid> components on a page using CSS, it's
enough to create classes with the same names (possible classes are the same as for the
<rich:dataTable> ) and define necessary properties in them.
Example:
...
.rich-table-footercell{
color:#ff7800;
}
...
284
Definition of Custom Style Classes
This is a result:
Also it's possible to change styles of particular <rich:dataGrid> component. In this case you
should create own style classes and use them in corresponding <rich:dataGrid> styleClass
attributes. An example is placed below:
Example:
...
.myClass{
font-style:italic;
}
...
The "columnClasses" attribute for <rich:dataGrid> is defined as it's shown in the example
below:
Example:
This is a result:
285
Chapter 6. The RichFaces Comp...
Figure 6.62. Redefinition styles with own classes and styleClass attributes
As it could be seen on the picture above, the font style for columns was changed.
286
Key Features
287
Chapter 6. The RichFaces Comp...
Name Value
component-type org.richfaces.DataList
component-class org.richfaces.component.html.HtmlDataList
component-family org.richfaces.DataList
renderer-type org.richfaces.DataListRenderer
tag-class org.richfaces.taglib.DataListTag
To create the simplest variant of dataList on a page, use the following syntax:
Example:
...
<rich:dataList var="car" value="#{dataTableScrollerBean.allCars}" >
<h:outputText value="#{car.model}"/>
</rich:dataList>
...
288
Creating the Component Dynamically Using
Java
6.37.4. Creating the Component Dynamically Using Java
Example:
import org.richfaces.component.html.HtmlDataList;
...
HtmlDataList myList = new HtmlDataList();
...
The component has the "type" attribute, which corresponds to the "type" parameter for the
<UL> HTML element and defines a marker type. Possible values for "type" attribute are: "disc",
"circle", "square".
Here is an example:
...
<h:form>
<rich:dataList var="car" value="#{dataTableScrollerBean.allCars}" rows="5" type="disc"
title="Car Store">
<h:outputText value="#{car.make} #{car.model}"/><br/>
<h:outputText value="Price:" styleClass="label"></h:outputText>
<h:outputText value="#{car.price} "/><br/>
<h:outputText value="Mileage:" styleClass="label"></h:outputText>
<h:outputText value="#{car.mileage} "/><br/>
</rich:dataList>
</h:form>
...
This is a result:
289
Chapter 6. The RichFaces Comp...
In the example the "rows" attribute limits number of output elements of the list.
"first" attribute defines first element for output. "title" are used for popup title. See picture below:
The component was created basing on the <a4j:repeat> component and as a result it could
be partially updated with Ajax. "ajaxKeys" attribute allows to define row keys that are updated
after an Ajax request.
Here is an example:
Example:
...
<rich:dataList value="#{dataTableScrollerBean.allCars}" var="car" ajaxKeys="#{listBean.list}"
binding="#{listBean.dataList}" id="list" rows="5" type="disc">
290
Look-and-Feel Customization
...
</rich:dataList>
...
<a4j:commandButton action="#{listBean.action}" reRender="list" value="Submit"/>
...
In the example "reRender" attribute contains value of "id" attribute for <rich:dataList>
component. As a result the component is updated after an Ajax request.
There are two ways to redefine the appearance of all <rich:dataList> components at once:
291
Chapter 6. The RichFaces Comp...
In order to redefine styles for all <rich:dataList> 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-list-item{
font-style:italic;
}
...
This is a result:
In the example the font style for list item text was changed.
Also it's possible to change styles of particular <rich:dataLIst> component. In this case you
should create own style classes and use them in corresponding <rich:dataList> styleClass
attributes. An example is placed below:
Example:
...
292
Relevant Resources Links
.myClass{
background-color:#ffead9;
}
...
The "styleClass" attribute for <rich:dataList> is defined as it's shown in the example below:
Example:
This is a result:
Figure 6.68. Redefinition styles with own classes and styleClass attributes
As it could be seen on the picture above, background color for <rich:dataList> was changed.
6.38.1. Description
The component for ordered lists rendering that allows choosing data from a model and obtains
built-in support of Ajax updates.
293
Chapter 6. The RichFaces Comp...
294
Creating the Component with a Page Tag
Name Value
component-type org.richfaces.DataOrderedList
component-class org.richfaces.component.html.HtmlDataOrderedList
component-family org.richfaces.DataOrderedList
renderer-type org.richfaces.DataOrderedListRenderer
tag-class org.richfaces.taglib.DataOrderedListTag
295
Chapter 6. The RichFaces Comp...
Example:
...
<rich:dataOrderedList var="car" value="#{dataTableScrollerBean.allCars}" >
<h:outputText value="#{car.model}"/>
</rich:dataOrderedList>
...
Example:
import org.richfaces.component.html.HtmlDataOrderedList;
...
HtmlDataOrderedList myList = new HtmlDataOrderedList();
...
The component has the "type" attribute, which corresponds to the "type" parameter for the
<OL> HTML element and defines a marker type. Possible values for "type" attribute are: "A",
"a", "I", "i", "1".
Here is an example:
...
<h:form>
<rich:dataOrderedList var="car" value="#{dataTableScrollerBean.allCars}" rows="5"
type="1" title="Car Store">
<h:outputText value="#{car.make} #{car.model}"/><br/>
<h:outputText value="Price:" styleClass="label"></h:outputText>
<h:outputText value="#{car.price}" /><br/>
<h:outputText value="Mileage:" styleClass="label"></h:outputText>
<h:outputText value="#{car.mileage}" /><br/>
</rich:dataOrderedList>
</h:form>
...
This is a result:
296
Look-and-Feel Customization
In the example the "rows" attribute limits number of output elements of the list.
"first" attribute defines first element for output. "title" are used for popup title.
The component was created basing on the <a4j:repeat> component and as a result it could
be partially updated with Ajax. "ajaxKeys" attribute allows to define row keys that are updated
after an Ajax request.
Here is an example:
Example:
...
<rich:dataOrderedList value="#{dataTableScrollerBean.allCars}" var="car"
ajaxKeys="#{listBean.list}"
binding="#{listBean.dataList}" id="list">
...
</rich:dataOrderedList>
...
<a4j:commandButton action="#{listBean.action}" reRender="list" value="Submit"/>
...
In the example "reRender" attribute contains value of "id" attribute for <rich:dataOrderedList>
component. As a result the component is updated after an Ajax request.
There are two ways to redefine the appearance of all <rich:dataOrderedList> components at
once:
297
Chapter 6. The RichFaces Comp...
On the screenshot there are classes names that define styles for component elements.
In order to redefine styles for all <rich:dataOrderedList> 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-orderedlist{
background-color: #ebf3fd;
}
...
This is a result:
298
Definition of Custom Style Classes
Also it's possible to change styles of particular <rich:dataOrderedList> component. In this case
you should create own style classes and use them in corresponding <rich:dataOrderedList>
styleClass attributes. An example is placed below:
Example:
...
.myClass{
font-style: italic;
}
...
Example:
299
Chapter 6. The RichFaces Comp...
This is a result:
Figure 6.73. Redefinition styles with own classes and styleClass attributes
As it could be seen on the picture above, the font style was changed.
Here [http://livedemo.exadel.com/richfaces-demo/richfaces/dataLists.jsf?c=dataOrderedList]
you can see the example of <rich:dataOrderedList > usage and sources for the given example.
6.39.1. Description
The component for definition lists rendering that allows choosing data from a model and obtains
built-in support of Ajax updates.
300
Key Features
301
Chapter 6. The RichFaces Comp...
302
Creating the Component with a Page Tag
Example:
...
<rich:dataDefinitionList value="#{bean.capitals}" var="caps">
<f:facet name="term">Cars</f:facet>
<h:outputText value="#{car.model}"/>
</rich:dataDefinitionList>
...
import org.richfaces.component.html.HtmlDataDefinitionList;
...
HtmlDataDefinitionList myList = new HtmlDataDefinitionList();
...
The component has the "term" facet, which corresponds to the "type" parameter for the <DT>
HTML element.
Here is an example:
...
<h:form>
303
Chapter 6. The RichFaces Comp...
This is a result:
In the example the "rows" attribute limits number of output elements of the list.
"first" attribute defines first element for output. "title" are used for popup title.
The component was created basing on the <a4j:repeat> component and as a result it could
be partially updated with Ajax. "ajaxKeys" attribute allows to define row keys that are updated
after an Ajax request.
Here is an example:
Example:
...
<rich:dataDefinitionList value="#{dataTableScrollerBean.allCars}" var="car"
ajaxKeys="#{listBean.list}"
binding="#{listBean.dataList}" id="list">
...
304
Look-and-Feel Customization
</rich:dataDefinitionList>
...
<a4j:commandButton action="#{listBean.action}" reRender="list" value="Submit"/>
...
In the example "reRender" attribute contains value of "id" attribute for <rich:dataDefinitionList>
component. As a result the component is updated after an Ajax request.
There are two ways to redefine the appearance of all <rich:dataDefinitionList> components
at once:
305
Chapter 6. The RichFaces Comp...
In order to redefine styles for all <rich:dataDefinitionList> 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-definition-term{
font-weight:bold;
}
...
This is a result:
Example:
...
306
Relevant Resources Links
.myClass{
font-style: italic;
}
...
Example:
This is a result:
Figure 6.78. Redefinition styles with own classes and styleClass attributes
As it could be seen on the picture above, the font style for rows was changed.
6.40.1. Description
The component for tables rendering that allows choosing data from a model and obtains built-in
support of Ajax updates.
307
Chapter 6. The RichFaces Comp...
308
Key Features
309
Chapter 6. The RichFaces Comp...
310
Key Features
311
Chapter 6. The RichFaces Comp...
312
Creating the Component with a Page Tag
Example:
...
<rich:dataTable value="#{capitalsBean.capitals}" var="capitals">
<rich:column>
...
</rich:column>
</rich:dataTable>
...
import org.richfaces.component.html.HtmlDataTable;
...
HtmlDataTable myTable = new HtmlDataTable();
...
313
Chapter 6. The RichFaces Comp...
Here is an example:
Example:
...
<rich:dataTable value="#{capitalsBean.capitals}" var="capitals"
ajaxKeys="#{bean.ajaxSet}" binding="#{bean.table}" id="table">
...
</rich:dataTable>
...
<a4j:commandButton action="#{tableBean.action}" reRender="table" value="Submit"/>
...
In the example "reRender" attribute contains value of "id" attribute for <rich:dataTable>
component. As a result the component is updated after an Ajax request.
The component allows to use "header" , "footer" and "caption" facets for output. See an example
below:
Example:
...
<rich:dataTable value="#{capitalsBean.capitals}" var="cap" rows="5">
<f:facet name="caption"><h:outputText value="United States Capitals" /></f:facet>
<f:facet name="header"><h:outputText value="Capitals and States Table" /></f:facet>
<rich:column>
<f:facet name="header">State Flag</f:facet>
<h:graphicImage value="#{cap.stateFlag}"/>
<f:facet name="footer">State Flag</f:facet>
</rich:column>
<rich:column>
<f:facet name="header">State Name</f:facet>
<h:outputText value="#{cap.state}"/>
<f:facet name="footer">State Name</f:facet>
</rich:column>
<rich:column >
<f:facet name="header">State Capital</f:facet>
<h:outputText value="#{cap.name}"/>
<f:facet name="footer">State Capital</f:facet>
</rich:column>
<rich:column>
<f:facet name="header">Time Zone</f:facet>
<h:outputText value="#{cap.timeZone}"/>
<f:facet name="footer">Time Zone</f:facet>
314
Look-and-Feel Customization
</rich:column>
<f:facet name="footer"><h:outputText value="Capitals and States Table" /></f:facet>
</rich:dataTable>
...
This is a result:
You can find information how to remove header's gradient here [http://wiki.jboss.org/wiki/
RichFacesDataTableBackgroundOut].
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:dataTable> components at once:
315
Chapter 6. The RichFaces Comp...
On the screenshot there are classes names that define styles for component elements.
316
Definition of Custom Style Classes
Table 6.149. Classes names that define header and footer elements
317
Chapter 6. The RichFaces Comp...
Table 6.150. Classes names that define rows and cells of a table
In order to redefine styles for all <rich:dataTable> 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-table-cell{
font-weight:bold;
}
...
This is a result:
In the example the font weight for table cell was changed.
318
Relevant Resources Links
Also it's possible to change styles of particular <rich:dataTable> component. In this case you
should create own style classes and use them in corresponding <rich:dataTable> styleClass
attributes. An example is placed below:
Example:
...
.myClass{
font-style:italic;
}
...
The "headerClass" attribute for <rich:dataTable> is defined as it's shown in the example below:
Example:
This is a result:
Figure 6.83. Redefinition styles with own classes and styleClass attributes
As it could be seen on the picture above, the font style for header was changed.
Detailed information on how to set <rich:dataTable> border to "0px" you can find here [http://
wiki.jboss.org/auth/wiki/RichFacesDataTableBorderTo0] .
319
Chapter 6. The RichFaces Comp...
6.41.1. Description
The component is used for inserting subtables into tables with opportunity to choose data from a
model and built-in Ajax updates support.
320
Key Features
321
Chapter 6. The RichFaces Comp...
322
Key Features
Name Value
component-type org.richfaces.SubTable
component-class org.richfaces.component.html.HtmlSubTable
component-family org.richfaces.SubTable
renderer-type org.richfaces.SubTableRenderer
323
Chapter 6. The RichFaces Comp...
Name Value
tag-class org.richfaces.taglib.SubTableTag
Example:
...
<rich:dataTable value="#{capitalsBean.capitals}" var="capitals">
<rich:column>
...
</rich:column>
<rich:subTable value=#{capitals.details} var="detail">
<rich:column>
...
</rich:column>
</rich:subTable>
</rich:dataTable>
...
Example:
import org.richfaces.component.html.HtmlSubTable;
...
HtmlSubTable mySubTable = new HtmlSubTable();
...
The <rich:subTable> component is similar to the <h:dataTable> one, except Ajax support
and skinnability. One more difference is that the component doesn't add the wrapping <table>
and <tbody> tags. Ajax support is possible, because the component was created basing on
the <a4j:repeat> component and as a result it could be partially updated with Ajax. "ajaxKeys"
attribute allows to define row keys that is updated after an Ajax request.
Here is an example:
Example:
324
Look-and-Feel Customization
...
<rich:dataTable value="#{capitalsBean.capitals}" var="capitals">
<rich:column>
...
</rich:column>
<rich:subTable value="#{capitals.details}" var="detail" ajaxKeys="#{bean.ajaxSet}"
binding="#{bean.subtable}" id="subtable">
<rich:column>
...
</rich:column>
</rich:subTable>
</rich:dataTable>
...
<a4j:commandButton action="#{tableBean.action}" reRender="subtable"/>
...
In the example "reRender" attribute contains value of "id" attribute for <rich:subTable>
component. As a result the component is updated after an Ajax request.
The component allows to use "header" and "footer" facets for output. See an example for
<rich:dataTable> component [314].
There are two ways to redefine the appearance of all <rich:subTable> components at once:
325
Chapter 6. The RichFaces Comp...
Table 6.154. Classes names that define header and footer elements
326
Definition of Custom Style Classes
In order to redefine styles for all <rich:subTable> 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-subtable-footer{
font-weight: bold;
}
...
This is a result:
327
Chapter 6. The RichFaces Comp...
Also it's possible to change styles of particular <rich:subTable> component. In this case you
should create own style classes and use them in corresponding <rich:subTable> styleClass
attributes. An example is placed below:
Example:
...
.myClass{
background-color: #fff5ec;
}
...
The "columnClasses" attribute for <rich:subTable> is defined as it's shown in the example
below:
Example:
This is a result:
328
< rich:dndParam >
Figure 6.87. Redefinition styles with own classes and styleClass attributes
As it could be seen on the picture above, the background color for columns was changed.
6.42.1. Description
329
Chapter 6. The RichFaces Comp...
Name Value
component-type org.richfaces.DndParam
component-class org.richfaces.component.html.HtmlDndParam
tag-class org.richfaces.taglib.DndParamTag
Example:
...
<rich:dragSupport dragType="file">
<rich:dndParam name="testDrag" value="testDragValue"
type="drag"/>
</rich:dragSupport>
...
import org.richfaces.component.html.HtmlDndParam;
...
HtmlDndParam myDparam = new HtmlDndParam();
...
Variants of usage:
In this case, dndParam is of a drag type and is defined in the following way:
330
Details of Usage
Example:
...
<rich:dragSupport ...>
<rich:dndParam type="drag" name="dragging">
<h:graphicImage value="/img/product1_small.png"/>
</rich:dndParam>
<h:graphicImage value="product1.png"/>
</rich:dragSupport>
...
Here dndParam defines an icon that is used by an indicator when a drag is on the place of a
default icon (e.g. a minimized image of a draggable element)
In this case dndParam is of a drag type and is defined in the following way:
Example:
...
<rich:dragSupport ...>
<rich:dndParam type="drag" name="label" value="#{msg.subj}"/>
...
</rich:dragSupport>
...
The parameter is transmitted into an indicator for usage in an informational part of the
dragIndicator component (inside an indicator a call to {label} happens)
• Parameters passing happens when dragged content is brought onto some zone with
dropSupport
In this case dndParam is of a drop type and is defined in the following way:
Example:
...
<rich:dropSupport ...>
<rich:dndParam type="drop" name="comp" >
<h:graphicImage height="16" width="16" value="/images/comp.png"/>
</rich:dndParam>
331
Chapter 6. The RichFaces Comp...
...
</rich:dropSupport >
...
Here, dndParam passes icons into an indicator, if dragged content of a comp type is above the
given drop zone that processes it on the next drop event.
6.43.1. Description
This is a component for defining what appears under the mouse cursor during drag-and-drop
operations. The displayed drag indicator can show information about the dragged elements.
332
Creating the Component with a Page Tag
Name Value
component-type org.richfaces.Draggable
component-class org.richfaces.component.html.HtmlDragIndicator
component-family org.richfaces.DragIndicator
renderer-type org.richfaces.DragIndicatorRenderer
tag-class org.richfaces.taglib.DragIndicatorTag
Example:
...
<rich:dragIndicator id="indicator">
<f:facet name="single">
<f:verbatim>
<b>Single item</b> {DragInfo}
</f:verbatim>
</f:facet>
</rich:dragIndicator>
...
<rich:dragSupport dragType="text" dragIndicator="indicator">
...
import org.richfaces.component.html.HtmlDragIndicator;
...
333
Chapter 6. The RichFaces Comp...
In the simplest way the component could be defined empty - in that case a default indicator is
shown like this:
For indicator customization you need to define one of the following facets:
• "single"
• "multiple"
Indicator shown when dragging several components (for future components that will support
multiple selection).
Thus for specify a look-and-feel you have to define one of these facets and include into it a content
that should be shown in indicator.
To place some data from drag or drop zones into component you can use macro definitions. They
are being defining in the following way:
• <rich:dndParam> component with a specific name and value is being included into a drag/drop
support component (an image can be defined as placed inside <rich:dndParam> without
defining a value).
• in needed place a parameter value is included into the marking of indicator using syntax (name
of parameter)
334
Details of Usage
...
<rich:dropSupport...>
<rich:dndParam name="testDrop">
<h:graphicImage value="/images/file-manager.png" />
</rich:dndParam>
</rich:dropSupport>
...
...
<f:facet name="single">
{testDrop}
</f:facet>
...
• marker
• label
Thus including one of these elements in the marking of indicator, in other words after setting up
appropriate parameters in DnD components and defining only default indicator - without specifying
facets - a developer gets these parameters values displayed in indicator in the order "marker
- label".
The macro definition "marker" can be customized depending on what a draggable element is
located over. For that you should define one of these three parameters (specify a parameter with
one of three names):
• accept
Parameter will be set instead of {marker} into indicator when a draggable element is positioned
over drop zone that accept this type of elements
335
Chapter 6. The RichFaces Comp...
• reject
Parameter is set instead of {marker} into indicator when a draggable element is positioned over
drop zone that doesn't accept this type of elements
• default
Parameter is set instead of {marker} into indicator when a draggable element is positioned over
all the rest of page elements
Note:
The <rich:dragIndicator> component has no skin parameters and special style classes , as
it consists of one element generated with a your method on the server. To define some style
properties such as an indent or a border, it's possible to use "style" and "styleClass" attributes
on the component.
Here [http://livedemo.exadel.com/richfaces-demo/richfaces/dragSupport.jsf?c=dragIndicator]
you can see the example of <rich:dragIndicator> usage and sources for the given example.
6.44.1. Description
This component defines a subtree of the component tree as draggable for drag-and-drop
operations. Within such a "drag zone," you can click the mouse button on an item and drag it
to any component that supports drop operations (a "drop zone"). It encodes all the necessary
JavaScript for supporting drag-and-drop operations.
336
Key Features
• Can be used within any component type that provides the required properties for drag operations
337
Chapter 6. The RichFaces Comp...
338
Key Features
339
Chapter 6. The RichFaces Comp...
Name Value
component-type org.richfaces.DragSupport
component-class org.richfaces.component.html.HtmlDragSupport
component-family org.richfaces.DragSupport
renderer-type org.richfaces.DragSupportRenderer
tag-class org.richfaces.taglib.DragSupportTag
Example:
...
<h:panelGrid id="drag1">
<rich:dragSupport dragType="item"/>
<!--Some content to be dragged-->
</h:panelGrid>
...
import org.richfaces.component.html.HtmlDragSupport;
...
HtmlDragSupport myDragZone = new HtmlDragSupport();
340
Details of Usage
...
The dragSupport tag inside a component completely specifies the events and JavaScript required
to use the component and it's children for dragging as part of a drag-and-drop operation. In order
to work, though, dragSupport must be placed inside a wrapper component that outputs child
components and that has the right events defined on it. Thus, this example won't work, because
the <h:column> tag doesn't provide the necessary properties for redefining events on the client:
Example:
...
<h:column>
<rich:dragSupport dragIndicator=":form:iii" dragType="text">
<a4j:actionParam value="#{caps.name}" name="name"/>
</rich:dragSupport>
<h:outputText value="#{caps.name}"/>
</h:column>
...
However, using a4j:outputPanel as a wrapper inside <h:column> , the following code could be
used successfully:
Example:
...
<h:column>
<a4j:outputPanel>
<rich:dragSupport dragIndicator=":form:iii" dragType="text">
<a4j:actionParam value="#{caps.name}" name="name"/>
</rich:dragSupport>
<h:outputText value="#{caps.name}"/>
</a4j:outputPanel>
</h:column>
...
One of the main attributes for dragSupport is "dragType" , which associates a name with the
drag zone. Only drop zones with this name as an acceptable type can be used in drag-and-drop
operations. Here is an example:
341
Chapter 6. The RichFaces Comp...
Example:
...
<h:panelGrid id="drag1">
<rich:dragSupport dragType="singleItems" .../>
<!--Some content to be dragged-->
</h:panelGrid>
...
<h:panelGrid id="drag2">
<rich:dragSupport dragType="groups" .../>
<!--Some content to be dragged-->
</h:panelGrid>
...
<h:panelGrid id="drop1">
<rich:dropSupport acceptedTypes="singleItems" .../>
<!--Drop zone content-->
</h:panelGrid>
...
In this example, the drop1 panel grid is a drop zone that invokes drag-and-drop for drops of
items from the first drag1 panel grid, but not the second drag2 panel grid. In the section about
dropSupport , you will find an example that shows more detailed information about moving data
between tables with drag and drop.
The dragSupport component also has a "value" attribute for passing data into the processing
after a drop event.
One more important attribute for <rich:dragSupport> is the "dragIndicator" attribute that point
to the component id of the <rich:dragIndicator> component to be used for dragged items from
this drag zone. If it isn't defined, a default indicator for drag operations is used.
Finally, the component has the following extra attributes for event processing on the client:
• "ondragstart"
• "ondragend"
You can use your own custom JavaScript functions to handle these events.
Note:
If you define width for a outputPanel, in Internet Explorer 6 you can perform a drag
and drop operation, placing the mouse cursor on the text in the outputPanel only.
Information about the "process" attribute usage you can find here .
342
Look-and-Feel Customization
• Can be used within any component type that provides the required properties for drop operations
343
Chapter 6. The RichFaces Comp...
344
Key Features
345
Chapter 6. The RichFaces Comp...
Name Value
component-type org.richfaces.DropSupport
component-class org.richfaces.component.html.HtmlDropSupport
component-family org.richfaces.DropSupport
renderer-type org.richfaces.DropSupportRenderer
tag-class org.richfaces.taglib.DropSupportTag
346
Creating the Component with a Page Tag
This simple example shows how to make a panel component a potential drop target for drag-and-
drop operations using "text" elements as the dragged items.
Example:
...
<rich:panel>
<rich:dropSupport acceptedTypes="text"/>
</rich:panel>
...
Example:
import org.richfaces.component.html.HtmlDropSupport;
...
HtmlDropSupport myDragZone = new HtmlDropSupport();
...
As shown in the example, the key attribute for <rich:dropSupport> is "acceptedTypes" . This
attribute defines the types of draggable items that can be dropped onto the designated drop zone.
Example:
...
<rich:dropSupport acceptedTypes="[iconsDragged, textDragged]"
typeMapping="{iconsDragged: DropIcon}">
<rich:dndParam name="DropIcon">
<h:graphicImage value="/images/drop-icon.png"/>
</rich:dndParam>
...
347
Chapter 6. The RichFaces Comp...
In this example, dropping a draggable item of an "iconsDragged" type will trigger the use a
parameter named "DropIcon" in the event processing after a drop event. (Also, an Ajax request
is sent, and the action and dropListener defined for the component are called.)
Here is an example of moving records between tables. The example describes all the pieces
for drag-and-drop. (To get extra information on these components, read the sections for these
components.)
As draggable items, this table contains a list of such items designated as being of type "text" :
Example:
...
<rich:dataTable value="#{capitalsBean.capitals}" var="caps">
<f:facet name="caption">Capitals List</f:facet>
<h:column>
<a4j:outputPanel>
<rich:dragSupport dragIndicator=":form:ind" dragType="text">
<a4j:actionParam value="#{caps.name}" name="name"/>
</rich:dragSupport>
<h:outputText value="#{caps.name}"/>
</a4j:outputPanel>
</h:column>
</rich:dataTable>
...
As a drop zone, this panel will accept draggable items of type text and then rerender an element
with the ID of box :
Example:
...
<rich:panel style="width:100px;height:100px;">
<f:facet name="header">Drop Zone</f:facet>
<rich:dropSupport acceptedTypes="text" reRender="box"
dropListener="#{capitalsBean.addCapital2}"/>
</rich:panel>
...
As a part of the page that can be updated in a partial page update, this table has an ID of box :
Example:
348
Details of Usage
...
<rich:dataTable value="#{capitalsBean.capitals2}" var="cap2" id="box">
<f:facet name="caption">Capitals chosen</f:facet>
<h:column>
<h:outputText value="#{cap2.name}"/>
</h:column>
</rich:dataTable>
...
And finally, as a listener, this listener will implement the dropped element:
Example:
...
public void addCapital2(DropEvent event) {
FacesContext context = FacesContext.getCurrentInstance();
Capital cap = new Capital();
cap.setName(context.getExternalContext().getRequestParameterMap().get("name").toString());
capitals2.add(cap);
}
...
Here is the result after a few drops of items from the first table:
349
Chapter 6. The RichFaces Comp...
In this example, items are dragged element-by-element from the rendered list in the first table and
dropped on a panel in the middle. After each drop, a drop event is generated and a common Ajax
request is performed that renders results in the third table.
As with every Ajax action component, <rich:dropSupport> has all the common attributes (
"timeout" , "limitToList" , "reRender" , etc.) for Ajax request customization.
Finally, the component has the following extra attributes for event processing on the client:
• "ondragenter"
• "ondragexit"
• "ondrop"
• "ondropend"
Developers can use their own custom JavaScript functions to handle these events.
Information about the "process" attribute usage you can find here .
• Allows to define some drag listeners for the components with "Drag and Drop" support
350
Creating the Component with a Page Tag
Name Value
listener-class org.richfaces.event.DragListener
event-class org.richfaces.event.DragEvent
tag-class org.richfaces.taglib.DragListenerTag
Example:
...
<rich:dragListener type="demo.Bean"/>
...
package demo;
import demo.ImplBean;
...
ImplBean myDragListener = new ImplBean();
...
Attribute "type" defines the fully qualified Java class name for a listener. This class should
implement org.richfaces.event.DropListener interface [http://labs.jboss.com/file-access/
default/members/jbossrichfaces/freezone/docs/apidoc_framework/index.html] .
351
Chapter 6. The RichFaces Comp...
...
<h:panelGrid id="dragPanel">
<rich:dragSupport dragType="item">
<rich:dragListener type="demo.ListenerBean"/>
</rich:dragSupport>
<!--Some content to be dragged-->
</h:panelGrid>
...
package demo;
import org.richfaces.event.DragEvent;
<rich:dragListener> has no skin parameters and custom style classes , as the component isn't
visual.
6.47.1. Description
The <rich:dropListener> represents an action listener method that is notified after a drop
operation.
• Allows to define some drop listeners for the components with "Drag and Drop" support
352
Creating the Component with a Page Tag
Name Value
listener-class org.richfaces.event.DropListener
event-class org.richfaces.event.DropEvent
tag-class org.richfaces.taglib.DropListenerTag
Example:
...
<rich:dropListener type="demo.Bean"/>
...
Example:
package demo;
import demo.ImplBean;
...
ImplBean myListener = new ImplBean();
...
353
Chapter 6. The RichFaces Comp...
Attribute "type" defines the fully qualified Java class name for the listener. This class should
implement org.richfaces.event.DropListener interface [http://labs.jboss.com/file-access/
default/members/jbossrichfaces/freezone/docs/apidoc_framework/index.html] .
...
<rich:panel style="width:100px;height:100px;">
<f:facet name="header">Drop Zone</f:facet>
<rich:dropSupport acceptedTypes="text">
<rich:dropListener type="demo.ListenerBean"/>
</rich:dropSupport>
</rich:panel>
...
package demo;
import org.richfaces.event.DropEvent;
<rich:dropListener> has no skin parameters and custom style classes , as the component isn't
visual.
354
< rich:dropDownMenu >
355
Chapter 6. The RichFaces Comp...
356
Creating the Component with a Page Tag
Name Value
component-type org.richfaces.DropDownMenu
component-class org.richfaces.component.html.HtmlDropDownMenu
component-family org.richfaces.DropDownMenu
renderer-type org.richfaces.DropDownMenuRenderer
tag-class org.richfaces.taglib.DropDownMenuTag
Example:
...
<rich:dropDownMenu value="Item1">
357
Chapter 6. The RichFaces Comp...
import org.richfaces.component.html.HtmlDropDownMenu;
...
HtmlDropDownMenu myDropDownMenu = new HtmlDropDownMenu();
...
Here is an example:
Example:
...
<f:facet name="label">
<h:graphicImage value="/images/img1.png"/>
</f:facet>
...
Use the "event" attribute to define an event for the represented element that triggers a menu
appearance. An example of a menu appearance on a click can be seen below.
Example:
...
<rich:dropDownMenu event="onclick" value="Item1">
<!--Nested menu components-->
</rich:dropDownMenu>
...
• Server (default)
358
Details of Usage
• Ajax
• None
The "action" and "actionListener" item's attributes are ignored. Menu items don't fire any submits
themselves. The behavior is fully defined by the components nested into items.
Note:
As the <rich:dropDownMenu> component doesn't provide its own form, use it
between <h:form> and </h:form> tags.
The "direction" and "jointPoint" attributes are used for defining aspects of menu appearance.
Here is an example:
Example:
...
359
Chapter 6. The RichFaces Comp...
You can correct an offset of the pop-up list relative to the label using the following attributes:
"horizontalOffset" and "verticalOffset" .
Here is an example:
Example:
...
<rich:dropDownMenu value="File" direction="bottom-right" jointPoint="tr" horizontalOffset="-
15" verticalOffset="0">
<rich:menuItem submitMode="ajax" value="New" action="#{ddmenu.doNew}"/>
<rich:menuItem submitMode="ajax" value="Open" action="#{ddmenu.doOpen}"/>
<rich:menuGroup value="Save As...">
<rich:menuItem submitMode="ajax" value="Text File" action="#{ddmenu.doSaveText}"/>
<rich:menuItem submitMode="ajax" value="PDF File" action="#{ddmenu.doSavePDF}"/>
</rich:menuGroup>
<rich:menuItem submitMode="ajax" value="Close" action="#{ddmenu.doClose}"/>
<rich:menuSeparator id="menuSeparator11"/>
<rich:menuItem submitMode="ajax" value="Exit" action="#{ddmenu.doExit}"/>
360
Look-and-Feel Customization
</rich:dropDownMenu>
...
The "disabled" attribute is used for disabling whole <rich:dropDownMenu> component. In this
case it is necessary to define "disabled" attribute as "true". An example is placed below.
Example:
...
<rich:dropDownMenu value="File" disabled="true">
...
</rich:dropDownMenu>
...
There are two ways to redefine the appearance of all <rich:dropDownMenu> components at
once:
361
Chapter 6. The RichFaces Comp...
362
Definition of Custom Style Classes
On the screenshot there are classes names that define styles for component elements.
In order to redefine styles for all <rich:dropDownMenu> components on a page using CSS,
it's enough to create classes with the same names (possible classes could be found in the table
above) and define necessary properties in them. An example is placed below:
Example:
...
.rich-ddmenu-label-select{
background-color: #fae6b0;
border-color: #e5973e;
}
...
363
Chapter 6. The RichFaces Comp...
This is a result:
In the example a label select background color and border color were changed.
Also it's possible to change styles of particular <rich:dropDownMenu> component. In this case
you should create own style classes and use them in corresponding <rich:dropDownMenu>
styleClass attributes. An example is placed below:
Example:
...
.myClass{
font-style: italic;
}
...
The "itemClass" attribute for <rich:dropDownMenu> is defined as it's shown in the example
below:
Example:
This is a result:
Figure 6.99. Redefinition styles with own classes and styleClass attributes
As it could be seen on the picture above, the font style for items was changed.
364
Relevant Resources Links
Note:
The component is in a preview state for 3.2.2 release because it was not fully tested
and reviewed by the RF team.
• Possibility to add an attribute to set the kind of selection (none, single line or multiple lines)
• Possibility to change the sequence of the displayed columns by dragging the column-header
to another position
• Possibility to save the current settings (visible columns, column width, sequence of the columns)
to be reused the next time the page will be shown
365
Chapter 6. The RichFaces Comp...
366
Key Features
367
Chapter 6. The RichFaces Comp...
368
Key Features
369
Chapter 6. The RichFaces Comp...
Name Value
component-type org.richfaces.ExtendedDataTable
component-class org.richfaces.component.html.HtmlExtendedDataTable
component-family org.richfaces.ExtendedDataTable
renderer-type org.richfaces.ExtendedDataTableRenderer
tag-class org.richfaces.taglib.ExtendedDataTableTag
Example:
...
<rich:extendedDataTable value="#{extendedDT.dataModel}" var="edt">
<rich:column>
...
</rich:column>
</rich:extendedDataTable>
...
Example:
370
Details of Usage
import org.richfaces.component.html.HtmlExtendedDataTable;
...
HtmlExtendedDataTable myTable = new HtmlExtendedDataTable();
...
Here is an example:
Example:
...
<rich:extendedDataTable id="edt" value="#{extendedDT.dataModel}" var="edt"
width="500px" height="500px" selectedClass="dataTableSelectedRow" sortMode="single"
selectionMode="multi" selection="#{extendedDT.selection}" rowKeyVar="rkvar"
tableState="#{extendedDT.tableState}">
<rich:column id="id" headerClass="dataTableHeader" width="50"
label="Id" sortable="true" sortBy="#{edt.id}" sortIconAscending="dataTableAscIcon"
sortIconDescending="dataTableDescIcon">
<f:facet name="header">
<h:outputText value="Id" />
</f:facet>
<h:outputText value="#{edt.id}" />
</rich:column>
<rich:column id="name" width="300" headerClass="dataTableHeader"
label="Name" sortable="true" sortBy="#{edt.name}" sortIconAscending="dataTableAscIcon"
sortIconDescending="dataTableDescIcon" filterBy="#{edt.name}" filterEvent="onkeyup"
visible="false">
<f:facet name="header">
<h:outputText value="Name" />
</f:facet>
<h:outputText value="#{edt.name}" />
</rich:column>
<rich:column id="date" width="100" headerClass="dataTableHeader"
label="Date" sortable="true" comparator="#{extendedDT.dateComparator}"
sortIconAscending="dataTableAscIcon" sortIconDescending="dataTableDescIcon">
<f:facet name="header">
<h:outputText value="Date" />
</f:facet>
371
Chapter 6. The RichFaces Comp...
Note:
Attribute "height" is mandatory. The default value is "500px" .
Menu on the right side of the column header is used to perform action: sorting, grouping, hiding
columns.
This is an example:
372
Details of Usage
After selecting a "Group by this column" option, you can see the data grouped. You can collapse
and expand groups by clicking on a group header.
This is an example:
The "label" attribute in <rich:column> sets the name of the column, which is used when
dragging columns (in drag window) and in context menu, in "Columns" submenu.
Example:
...
<rich:column id="name" label="#{msg['name']}"
...
373
Chapter 6. The RichFaces Comp...
"tableState" attribute can be used to bind state of the table (column width, column position, visible,
sequence, grouping...) to a backing-bean string property, for a later used. This state can be for
example saved to a database, and it is different form standard JSF state saving mechanisms.
Example:
...
<rich:extendedDataTable tableState="#{extendedDT.tableState}">
374
Look-and-Feel Customization
...
There are two ways to redefine the appearance of all <rich:extendedDataTable> components
at once:
375
Chapter 6. The RichFaces Comp...
Table 6.185. Classes names that define header and footer elements
Class name Description
rich-extdt-header Defines styles for a table header row
rich-extdt-header-continue Defines styles for all header lines after the first
rich-extdt-subheader Defines styles for a column header
rich-extdt-footer Defines styles for a footer row
rich-extdt-footer-continue Defines styles for all footer lines after the first
376
< rich:menuGroup >
Table 6.186. Classes names that define rows and cells of a table
377
Chapter 6. The RichFaces Comp...
378
Creating the Component with a Page Tag
Name Value
component-type org.richfaces.MenuGroup
component-class org.richfaces.component.html.HtmlMenuGroup
component-family org.richfaces.DropDownMenu
renderer-type org.richfaces.MenuGroupRenderer
tag-class org.richfaces.taglib.MenuGroupTag
Example:
...
<rich:dropDownMenu value="Active">
...
<rich:menuGroup value="Active">
<!--Nested menu components-->
</rich:menuGroup>
...
</rich:dropDownMenu >
...
Example:
import org.richfaces.component.html.HtmlMenuGroup;
...
HtmlMenuGroup myMenuGroup = new HtmlMenuGroup();
379
Chapter 6. The RichFaces Comp...
...
The "icon" attribute defines an icon for the component. The "iconDisabled" attribute defines an
icon for when the group is disabled. Also you can use the "icon" and "iconDisabled" facets. If
the facets are defined, the corresponding "icon" and "iconDisabled" attributes are ignored and
the facets' contents are used as icons. This could be used for an item check box implementation.
Here is an example:
...
<f:facet name="icon">
<h:selectBooleanCheckbox value="#{bean.property}"/>
</f:facet>
...
The "iconFolder" and "iconFolderDisabled" attributes are defined for using icons as folder
icons. The "iconFolder" and "iconFolderDisabled" facets use their contents as folder icon
representations in place of the attribute values.
The "direction" attribute is used to define which way to display the menu as shown in the example
below:
• "left - down" - a submenu is attached to the left side of the menu and is dropping down
• "left - up" - a submenu is attached to the left side of the menu and is dropping up
• "right - down" - a submenu is attached to the right side of the menu and is dropping down
• "right - up" - a submenu is attached to the right side of the menu and is dropping up
Here is an example:
...
<rich:menuGroup value="Save As..." direction="left-down">
<rich:menuItem submitMode="ajax" value="Text File"
action="#{ddmenu.doSaveText}"/>
380
Look-and-Feel Customization
Note:
The <rich:menuGroup> component was designed to be used only for pop-up
menu list creation.
There are two ways to redefine the appearance of all <rich:menuGroup> components at once:
381
Chapter 6. The RichFaces Comp...
In order to redefine styles for all <rich:menuGroup> 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.
382
Definition of Custom Style Classes
Example:
...
.rich-menu-item-label-disabled{
font-style: italic;
}
...
This is a result:
Also it's possible to change styles of particular <rich:menuGroup> component. In this case you
should create own style classes and use them in corresponding <rich:menuGroup> styleClass
attributes. An example is placed below:
Example:
...
.myClass{
background-color: #acbece;
border: none;
}
...
The "selectClass" attribute for <rich:menuGroup> is defined as it's shown in the example below:
Example:
383
Chapter 6. The RichFaces Comp...
This is a result:
Figure 6.111. Redefinition styles with own classes and styleClass attributes
As it could be seen on the picture above, the background color for selected class was changed.
Also selected class has no border.
384
Key Features
385
Chapter 6. The RichFaces Comp...
386
Key Features
Name Value
component-type org.richfaces.MenuItem
component-class org.richfaces.component.html.HtmlMenuItem
387
Chapter 6. The RichFaces Comp...
Name Value
component-family org.richfaces.DropDownMenu
renderer-type org.richfaces.MenuItemRenderer
tag-class org.richfaces.taglib.MenuItemTag
Example:
...
<rich:dropDownMenu>
...
<rich:menuItem value="Active"/>
...
<rich:dropDownMenu>
...
import org.richfaces.component.html.HtmlMenuItem;
...
HtmlMenuItem myMenuItem = new HtmlMenuItem();
...
There are two icon-related attributes. The "icon" attribute defines an icon. The "iconDisabled"
attribute defines an icon for a disabled item. Also you can use the "icon" and "iconDisabled"
facets. If the facets are defined, the corresponding "icon" and "iconDisabled" attributes are
ignored and the facets content is shown as an icon. It could be used for an item check box
implementation.
Here is an example:
...
<f:facet name="icon">
388
Details of Usage
<h:selectBooleanCheckbox value="#{bean.property}"/>
</f:facet>
...
• Server (default)
• Ajax
• None
The "action" and "actionListener" item's attributes are ignored. Menu items don' fire any submits
themselves. The behavior is fully defined by the components nested into items.
For example, you can put any content into an item, but, in this case, you should set the "mode"
attribute as "none" .
Here is an example:
...
<rich:dropDownMenu>
...
<rich:menuItem submitMode="none">
<h:outputLink value="www.jboss.org"/>
</rich:menuItem>
...
<rich:dropDownMenu>
...
You can use the "disabled" attribute to set the item state.
Here is an example:
...
<rich:dropDownMenu>
<rich:menuItem value="Disable" disabled="true"/>
<rich:dropDownMenu>
389
Chapter 6. The RichFaces Comp...
...
Note:
The <rich:menuItem> component was designed to be used only for pop-up menu
list creation.
Information about the "process" attribute usage you can find here.
There are two ways to redefine the appearance of all <rich:menuItem> components at once:
390
Definition of Custom Style Classes
In order to redefine styles for all <rich:menuItem> 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.
391
Chapter 6. The RichFaces Comp...
Example:
...
.rich-menu-item-disabled{
font-style: italic;
}
...
This is a result:
Also it's possible to change styles of particular <rich:menuItem> component. In this case you
should create own style classes and use them in corresponding <rich:menuItem> styleClass
attributes. An example is placed below:
Example:
...
.myClass{
border-color: #bed6f8;
background-color: #ffffff;
}
...
The "styleClass" attribute for <rich:menuItem> is defined as it's shown in the example below:
Example:
392
Relevant Resources Links
This is a result:
Figure 6.115. Redefinition styles with own classes and styleClass attributes
As it could be seen on the picture above, the background color and border color for selected item
were changed.
6.52.1. Description
The <rich:menuSeparator> component is used for the definition of a horizontal separator that
can be placed between groups or items.
393
Chapter 6. The RichFaces Comp...
Name Value
component-type org.richfaces.MenuSeparator
component-class org.richfaces.component.html.HtmlMenuSeparator
component-family org.richfaces.DropDownMenu
renderer-type org.richfaces.MenuSeparatorRenderer
tag-class org.richfaces.taglib.MenuSeparatorTag
Example:
...
<rich:dropDownMenu/>
...
<rich:menuSeparator/>
...
<rich:dropDownMenu/>
...
import org.richfaces.component.html.HtmlMenuSeparator;
...
HtmlMenuSeparator myMenuSeparator = new HtmlMenuSeparator();
...
394
Skin Parameters Redefinition
There are two ways to redefine the appearance of all <rich:menuSeparator> components at
once:
In order to redefine styles for all <rich:menuSeparator> 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-menu-separator{
border-color: #acbece;
}
395
Chapter 6. The RichFaces Comp...
...
This is a result:
396
Creating the Component with a Page Tag
Example:
...
<rich:effect for="componentId" type="Appear"/>
...
397
Chapter 6. The RichFaces Comp...
import org.richfaces.component.html.HtmlRichEffect;
...
HtmlRichEffect myEffect = new HtmlRichEffect();
...
• attached to the JSF components or html tags and triggered by a particular event. Wiring effect
with JSF components might occur on the server or client. Wiring with html tag is possible only
on the client side
• invoking from the JavaScript code by an effect name. During the rendering, <rich:effect>
generates the JavaScript function with defined name. When the function is called, the effect
is applied
...
<!-- attaching by event -->
<rich:panel>
<rich:effect event="onmouseout" type="Opacity" params="duration:0.8,from:1.0,to:0.3" />
.... panel content ....
</rich:panel>
...
<!-- attaching to window on load and applying on particular page element -->
<rich:effect for="window" event="onload" type="Appear"
params="targetId:'contentDiv',duration:0.8,from:0.3,to:1.0" />
...
398
Details of Usage
"name" attribute defines a name of the JavaScript function that is be generated on a page when the
component is rendered. You can invoke this function to activate the effect. The function accesses
one parameter. It is a set of effect options in JSON format.
"type" attribute defines the type of an effect. For example, "Fade", "Blind", "Opacity". Have a look
at scriptaculous documentation [http://script.aculo.us] for set of available effect.
"for" attribute defines the id of the component or html tag, the effect is attached to. RichFaces
converts the "for" attribute value to the client id of the component if such component is found.
If not, the value is left as is for possible wiring with on the DOM element's id on the client side.
By default, the target of the effect is the same element that effect pointed to. However, the target
element is might be overridden with "targetId" option passed with "params" attribute of with
function paramenter.
"params" attribute allows to define the set of options possible for particurar effect. For example,
'duration', 'delay', 'from', 'to'. Additionally to the options used by the effect itself, there are two
option that might override the <rich:effect> attribute. Those are:
• "targetId" allows to re-define the target of effect. The option is override the value of "for"
attribute.
• "type" defines the effect type. The option is override the value of "type" attribute.
You can use a set of effects directly without defining the <rich:effect> component on a page if
it's convenient for you. For that, load the scriptaculous library to the page with the following code:
Example:
...
<a4j:loadScript src="resource://scriptaculous/effect.js" />
...
If you do use the <rich:effect> component, there is no need to include this library because it's
already here.
399
Chapter 6. The RichFaces Comp...
How to save <rich:effect> status see on the RichFaces Users Forum [http://www.jboss.com/
index.html?module=bb&op=viewtopic&t=118833].
400
Key Features
• Automatic uploads
• Disablement support
401
Chapter 6. The RichFaces Comp...
402
Key Features
403
Chapter 6. The RichFaces Comp...
404
Creating the Component with a Page Tag
Example:
...
<rich:fileUpload />
...
import org.richfaces.component.html.HtmlFileUpload;
...
HtmlFileUpload myFileUpload = new HtmlFileUpload();
...
• List of files which contains the list of currently chosen files to upload with possibility to manage
every file
405
Chapter 6. The RichFaces Comp...
• Component controls - the bar with controls for managing the whole component
• In the temporary folder (depends on OS) if the value of the createTempFile parameter in
Ajax4jsf Filter section is "true" (by Default)
...
<init-param>
<param-name>createTempFiles</param-name>
<param-value>true</param-value>
</init-param>
...
• In the RAM if the value of the createTempFile parameter in Ajax4jsf Filter section is "false".
This is a better way for storing small-sized files.
The "uploadData" attribute defines the collection of files uploaded. See the example below.
Example:
...
<rich:fileUpload uploadData="#{bean.data}"/>
...
The "fileUploadedListener" is called at server side after every file uploaded and used for the
saving files from temporary folder or RAM.
Example:
...
<rich:fileUpload uploadData="#{bean.data}" fileUploadListener="#{bean.listener}"/>
...
• getUploadItems(). It returns the list of the uploaded files. If one file was uploaded, the
getUploadItems() method will return the list consisting of one file
406
Details of Usage
• getUploadItem(). It returns the whole list in case of uploading one file only. If several files were
uploaded, the getUploadItem() method will return the first element of the uploaded files list.
Example:
...
<rich:fileUpload uploadData="#{bean.data}" fileUploadListener="#{bean.listener}"
immediateUpload="true"/>
...
The "autoclear" attribute is used to remove automatically files from the list after upload completed.
See the simple example below.
Example:
...
<rich:fileUpload uploadData="#{bean.data}" autoclear="true"/>
...
• On file types, use "acceptedTypes" attribute to define file types accepted by component. In
the example below only files with "html" and "jpg" extensions are accepted to upload.
Example:
...
<rich:fileUpload acceptedTypes="html, jpg"/>
...
• On file size, use the maxRequestSize parameter(value in bytes) inside Ajax4jsf Filter section
in web.xml:
...
<init-param>
<param-name>maxRequestSize</param-name>
407
Chapter 6. The RichFaces Comp...
<param-value>1000000</param-value>
</init-param>
...
• On max files quantity, use the "maxFilesQuantity" attribute to define max number of files
allowed to be uploaded. After a number of files in the list equals to the value of this attribute
"Add" button is disabled and nothing could be uploaded even if you clear the whole list. In order
to upload files again you should rerender the component. As it could be seen in the example
below, only 2 files are accepted for uploading.
Example:
...
<rich:fileUpload maxFilesQuantity="2"/>
...
• The "onupload" which gives you a possibility to cancel the upload at client side
• The "onuploadcomplete" which is called after all files from the list are uploaded
• The "onuploadcanceled" which is called after upload has been canceled via cancel control
• The "onerror" which is called if the file upload was interrupted according to any errors
The <rich:fileUpload> component has an embedded Flash module that adds extra functionality
to the component. The module is enabled with "allowFlash" attribute set to "true".
408
Details of Usage
These are the additional features that the Flash module provides:
• Permitted file types are specified in the "Open File" dialog window;
• A number of additional entry object properties are also available, which can be found here.
Apart from uploading files to the sever without using AJAX, the Flash module provides a number
of useful API functions that can be used to obtain information about the uploaded file.
There are 2 ways to obtain the data stored in the FileUploadEntry object.
• By means of JavaScript on the client side. Use the following syntax for that
entries[i].propertyName. For example entries[0].state will return the state of the file the
is being processed or has just been processed.
The given bellow code sample demonstrates how the properties can be used. Please study it
carefully.
...
<head>
<script>
function _onaddHandler (e) {
var i = 0;
for (; i < e.memo.entries.lenght; i++) {
alert(e.memo.entries[i].creator); //Shows creators of the added files
}
}
function _onerrorhandle(e) {
alert(e.memo.entry.fileName + "file was not uploaded due transfer error");
}
</script>
</head>
...
Moreover, embedded Flash module provides a smoother representation of progress bar during
the uploading process: the polling is performed is not by AJAX, but my means of the flash module.
409
Chapter 6. The RichFaces Comp...
However, the Flash module doens't perform any visual representation of the component.
In order to customize the information regarding the ongoing process you could use "label" facet
with the following macrosubstitution:
• {B}, {KB}, {MB} contains the size of file uploaded in bytes, kilobytes, megabytes respectively
• {_B}, {_KB}, {_MB} contains the remain file size to upload in bytes, kilobytes, megabytes
respectively
• {ss}, {mm}, {hh} contains elapsed time in seconds, minutes and hours respectively
Example:
...
<rich:fileUpload uploadData="#{bean.data}" fileUploadListener="#{bean.listener}">
<f:facet name="label">
<h:outputText value="{_KB}KB from {KB}KB uploaded --- {mm}:{ss}" />
</f:facet>
</rich:fileUpload>
...
You could define labels of the component controls with the help of "addControlLabel" ,
"clearAllControlLabel" , "clearControlLabel" , "stopEntryControlLabel" , "uploadControlLabel"
attributes. See the following example.
410
Details of Usage
Example:
...
<rich:fileUpload addControlLabel="Add file..." clearAllControlLabel="Clear all"
clearControlLabel="Clear"
stopEntryControlLabel="Stop process" uploadControlLabel="Upload file"/>
...
In order to disable the whole component you could use the "disabled" attribute. See the following
example.
Example:
...
<rich:fileUpload disabled="true"/>
...
411
Chapter 6. The RichFaces Comp...
It's possible to handle events for fileUpload using JavaScript code. A simplest example of usage
JavaScript API is placed below:
Example:
...
<rich:fileUpload id="upload" disabled="false"/>
<h:commandButton onclick="${rich:component('upload')}.disable();" value="Disable" />
...
...
<rich:fileUpload fileUploadListener="#{fileUploadBean.listener}"
maxFilesQuantity="#{fileUploadBean.uploadsAvailable}"
reRender="table" id="upload"
immediateUpload="#{fileUploadBean.autoUpload}"
acceptedTypes="jpg, gif, png, bmp">
<a4j:support event="onuploadcomplete" reRender="info" />
</rich:fileUpload>
<h:commandButton onclick="if($('j_id232:upload').component.entries[0].state ==
FileUploadEntry.UPLOAD_SUCCESS) alert ('DONE');" value="Check file state"/>
...
412
JavaScript API
RICH_FILE_UPLOAD_TRANSFER_ERROR_LABLE, RICH_FILE_UPLOAD_ENTRY_STOP_LABEL,
RICH_FILE_UPLOAD_ENTRY_CLEAR_LABEL, RICH_FILE_UPLOAD_ENTRY_CANCEL_LABEL there.
Function Description
enable() Enables the component
disable() Disables the component
stop() Stops the uploading process
clear() Removes all files from the list. The function
can also get the $('id').component.entries[i] as
a parameter to remove a particular file.
submitForm() Submits form to server. All added files will be
put to model and event.
beforeSubmit() Sets up necessary request parameters for
file uploading and submits form to server by
command button. This method should be used
together with commands
Property Description
entries Returns a array of all files in the list
entries.length Returns the number of files in the list
entries[i].fileName Returns the file name, that is retrieved by the
array index
entries[i].state Returns the file state. Possible states are
413
Chapter 6. The RichFaces Comp...
Property Description
• "ready" - uploading is in process,
corresponds to FileUploadEntry.READY
constant The file will be uploaded on queue
order.
Table 6.212. Client side object properties available with specific event
attributes [408]
Property Description
entry.state Returns the file state. Possible states are
414
JavaScript API
Property Description
• "initialized" - the file is added, corresponds to
FileUploadEntry.INITIALIZED constant
415
Chapter 6. The RichFaces Comp...
Property Description
entry.modificationDate Returns the date of the last file modification.
Available in flash enabled version only
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:fileUpload> components at once:
416
Definition of Custom Style Classes
Table 6.223. Skin parameters redefinition for a disabled "Start" button icon
Table 6.224. Skin parameters redefinition for a disabled "Clear" button icon
417
Chapter 6. The RichFaces Comp...
418
Definition of Custom Style Classes
Table 6.227. Classes names that define the representation of the buttons'
icons
In order to redefine styles for all <rich:fileUpload> 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-fileupload-anc{
font-weight:bold;
text-decoration:none;
}
...
419
Chapter 6. The RichFaces Comp...
In the example above the font weight and text decoration for "Cancel" and "Clear" links are
changed.
Also it's possible to change styles of particular <rich:fileUpload> component. In this case you
should create own style classes and use them in the corresponding <rich:fileUpload> styleClass
attributes. An example is placed below:
Example:
...
.myClass{
font-weight:bold;
}
...
The "addButtonClass" attribute for <rich:fileUpload> is defined as it's shown in the example
below:
Example:
Figure 6.130. Redefinition styles with own classes and styleClass attributes
420
Relevant Resources Links
As it could be seen on the picture above, the font style for "Add" button is changed.
6.55.1. Description
421
Chapter 6. The RichFaces Comp...
422
Key Features
Name Value
component-type org.richfaces.Gmap
component-class org.richfaces.component.html.HtmlGmap
component-family org.richfaces.Gmap
423
Chapter 6. The RichFaces Comp...
Name Value
renderer-type org.richfaces.GmapRenderer
tag-class org.richfaces.taglib.GmapTag
Example:
...
<rich:gmap gmapKey="..."/>
...
Example:
import org.richfaces.component.html.HtmlGmap;
...
HtmlGmap myMap = new HtmlGmap();
...
To use Google Map in your application, generate a key on Google Map official resource [http:/
/google.com/apis/maps] . One key could be used for one directory on the server.
Here are the main settings of initial rendering performed with a component map that are accessible
with the following attributes:
• "lat" specifies an initial latitude coordinate in degrees, as a number between -90 and +90
• "lng" specifies an initial longitude coordinate in degrees, as a number between -180 and +180
For example, the city of Paris is shown after rendering with the following initial settings: lat =
"48.44" , lng = "2.24" and zoom = "5" .
424
Details of Usage
It's also possible to set accessible controls on the map with the help of the attributes:
• "showGMapTypeControl" determines whether the controls for a map type definition are
switched on
• "showGLargeMapControl" determines whether the control for map scale rendering is rendered
425
Chapter 6. The RichFaces Comp...
To set all these parameters and perform some activity (Zoom In/Out etc.) is possible with your
JavaScript, i.e. declare a name of an object on a map in the "gmapVar" attribute and then call
the object directly with API Google Map .
For example, to approximate a map for gmapVar = "map" declared inside the component, call
map.zoomIn() on an event.
Moreover, to add e.g. some JavaScript effects, events defined on it are used.
• "onmouseover"
• "onclick"
• "onmouseout"
• etc.
Note
Google Map does not support XHTML format of the page. Thus, if you use Facelets
and JSF 1.2, do not forget to put the following tags somewhere on the page:
426
Look-and-Feel Customization
...
<f:view contentType="text/html">...</f:view>
...
<rich:gmap> component isn't tied to skin parameters, as there is no additional elements on it,
except the ones provided with Google Map .
In order to redefine styles for all <rich:gmap> 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-gmap{
font-style:italic;
}
...
This is a result:
427
Chapter 6. The RichFaces Comp...
Also it's possible to change styles of particular <rich:gmap> component. In this case you should
create own style classes and use them in corresponding <rich:gmap> styleClass attributes. An
example is placed below:
Example:
...
.myClass{
font-weight:bold;
}
...
428
Relevant Resources Links
The "styleClass" attribute for <rich:gmap> is defined as it's shown in the example below:
Example:
This is a result:
As it could be seen on the picture above, the font weight for buttons was changed.
429
Chapter 6. The RichFaces Comp...
430
Key Features
431
Chapter 6. The RichFaces Comp...
Name Value
component-type org.richfaces.VirtualEarth
component-class org.richfaces.component.html.HtmlVirtualEarth
component-family org.richfaces.VirtualEarth
renderer-type org.richfaces.VirtualEarthRenderer
tag-class org.richfaces.taglib.VirtualEarthTag
Example:
...
<rich:virtualEarth lat="..." lng="..."/>
...
import org.richfaces.component.html.HtmlVirtualEarth;
...
HtmlVirtualEarth myMap = new HtmlVirtualEarth();
...
• "lat" specifies an initial latitude coordinate in degrees, as a number between -90 and +90
• "lng" specifies an initial longitude coordinate in degrees, as a number between -180 and +180
For example, the city of Paris is shown after rendering with the following initial settings: lat =
"48.833" , lng = "2.40" and zoom = "11" .
432
Details of Usage
Example:
...
<rich:virtualEarth style="width:800px;" id="vm" lat="48.833" lng="2.40"
dashboardSize="Normal" zoom="11" mapStyle="Hybrid" var="map" />
...
To set all these parameters and perform some activity (Zoom In/Out etc.) is possible with your
JavaScript, i.e. declare a name of an object on a map in the "var" attribute and then call the
object directly with API Microsoft Virtual Earth map .
For example, to approximate a map for var = "map" declared inside the component, call
map.ZoomIn() on an event.
Moreover, to add e.g. some JavaScript effects, events defined on it are used.
• "onmouseover"
• "onclick"
• "onmouseout"
• etc.
Note
Virtual Earth does not support XHTML format of the page. Thus, if you use Facelets
and JSF 1.2, do not forget to put the following tags somewhere on the page:
433
Chapter 6. The RichFaces Comp...
...
<f:view contentType="text/html">...</f:view>
...
In order to redefine styles for all <rich:virtualEarth> components on a page using CSS, it's
enough to create class with the same name and define necessary properties in it.
To change styles of particular <rich:virtualEarth> components, define your own style class in
the corresponding <rich:virtualEarth> attribute.
434
Key Features
Name Value
component-type org.richfaces.HotKey
component-class org.richfaces.component.html.HtmlHotKey
component-family org.richfaces.HotKey
renderer-type org.richfaces.HotKeyRenderer
435
Chapter 6. The RichFaces Comp...
Example:
...
<rich:hotKey key="alt+a" handler="alert('alt+A is pressed')" />
...
import org.richfaces.component.html.HtmlHotKey;
...
HtmlHotKey myHotKey = new HtmlHotKey();
...
• just place it anywhere on the page. In this case the <rich:hotKey> component is attached to
the whole page (html[0] element). This is default scenario.
• attach it with "selector" attribute to all the elements defined using this selector. This attribute
uses defined by w3c consortium [http://www.w3.org] syntax for CSS rule selector with some
jQuery extensions.
The "key" attribute defines the hot key itself which is processed by the component.
After the hot key has been registered and defined you could set the "handler" attribute which
determines a JavaScript function to be called every time when corresponding keys are pressed.
Example:
...
<rich:listShuttle var="cap" sourceValue="#{capitalsBean.capitals}" id="ls">
<rich:column>
<f:facet name="header">
<h:outputText value="State flag"/>
</f:facet>
<h:graphicImage value="#{cap.stateFlag}"/>
436
Details of Usage
</rich:column>
<rich:column>
<f:facet name="header">
<h:outputText value="State name"/>
</f:facet>
<h:outputText value="#{cap.name}"/>
</rich:column>
</rich:listShuttle>
<rich:hotKey selector="#ls" key="right" handler="#{rich:component('ls')}.copy()"/>
<rich:hotKey selector="#ls" key="left" handler="#{rich:component('ls')}.remove()"/>
<rich:hotKey selector="#ls" key="end" handler="#{rich:component('ls')}.copyAll()"/>
<rich:hotKey selector="#ls" key="home" handler="#{rich:component('ls')}.removeAll()"/>
...
In the example above the "selector" attribute is used. So the keys work only if <rich:listShuttle>
component is focused.
You could press Right or Left keys in order to move some selected items between lists. You could
press Home or End buttons in order to move all items between lists.
With the help of the "timing" attribute you could manage <rich:hotKey> registration timing.
There are three possible values of this attribute:
• "onregistercall" - the component is rendered only after JavaScript API for the key registration
is used.
The "type" attribute defines the type of keyboard event. Possible values are: "onkeyup",
"onkeypress" and "onkeydown".
The "checkParent" attribute defines the hotkey handling of events generated by child components
nested into the parent component to which the <rich:hotKey> is attached.
The <rich:hotKey> component also provides a number of JavaScript API functions. There is
an example below.
Example:
...
<h:form id="myForm">
<rich:hotKey id="myKey" key="ctrl+g" handler="alert('Ctrl+G is pressed')" />
437
Chapter 6. The RichFaces Comp...
In the example above the Ctrl+G is registered as a global hotkey, so if you press this key
combination the alert window with the "Ctrl+G is pressed" text appears. With the help of enable(),
disable() JavaScript API fucntions you could enable or disable registered hotkey.
438
Key Features
• Edit mode activation when the component gets focus with the "Tab"
• Controls customization
439
Chapter 6. The RichFaces Comp...
440
Key Features
441
Chapter 6. The RichFaces Comp...
Name Value
component-type org.richfaces.inplaceInput
component-class org.richfaces.component.html.HtmlInplaceInput
component-family org.richfaces.inplaceInput
renderer-type org.richfaces.renderkit.inplaceInputRenderer
tag-class org.richfaces.taglib.inplaceInputTag
Example:
442
Creating the Component Dynamically Using
Java
...
<rich:inplaceInput value="#{bean.value}"/>
...
import org.richfaces.component.html.inplaceInput;
...
HtmlInpaceInput myInplaceInput = new InplaceInput();
...
The "value" attribute is a value-binding expression for the current value of the component.
• View state displays default label with the value taken from "value" or "defaultLabel" attributes.
If the initial value of the "value" attribute is "null" or empty string the "defaultLabel" attribute
is used to define default label.
Example:
...
<rich:inplaceInput value="#{bean.value}" defaultLabel="click to edit"/>
...
In the example above the "value" attribute is not initialized therefore "click to edit" text,
that "defaultLabel" , contains is displayed.
443
Chapter 6. The RichFaces Comp...
The "editEvent" attribute provides an option to assign a JavaScript action to initiate the change
of the state from view/changed to edit. The default value is "onclick".
Example:
...
<rich:inplaceInput value="#{bean.value}" editEvent="ondblclick"/>
...
Example:
...
<rich:inplaceInput value="#{bean.value}" oneditactivation="if (!confirm('Are you sure you want
to change the value?')){return false;}" />
...
The given code illustrates how "oneditactivation" attribute works, namely when the state is being
changed from view to edit, a confirmation window with a message "Are you sure you want
to change value?" comes up.
444
Details of Usage
Using the boolean "selectOnEdit" attribute set to true, the text in the input field will be selected
when the change from view/changed state to edit occurs.
If the <rich:inplaceInput> loses focus, input data is saved automatically and the component
displays a new value. Additionally, the data is saved when "Enter" is pressed. Nevertheless, you
can use the "showControls" attribute, which makes "Save" and "Cancel" buttons appear next
to the input field. If the controls are used, data is not saved automatically when the form loses
focus: user has to confirm that he/she wants to save/discard the data explicitly. In both cases(with
controls or without them) the input data can be discarded by pressing "Esc" key.
Example:
...
<rich:inplaceInput value="#{bean.value}" showControls="true"/>
...
You can also position the controls relatively to the input field, by means of
• The "controlsVerticalPosition " attribute with "bottom", "center" and "top" definitions
Example:
...
<rich:inplaceInput value="#{bean.value}" showControls="true"
controlsVerticalPosition="bottom" controlsHorizontalPosition="left"/>
...
445
Chapter 6. The RichFaces Comp...
It is also possible to use "controls" facet in order to replace the default controls with facets content.
See the example below.
Example:
...
<rich:inplaceInput defaultLabel="Click here to edit" showControls="true"
controlsHorizontalPosition="left" controlsVerticalPosition="bottom" id="inplaceInput">
<f:facet name="controls">
<button onclick="#{rich:component('inplaceInput')}.save();" type="button">Save</button>
<button onclick="#{rich:component('inplaceInput')}.cancel();" type="button">Cancel</
button>
</f:facet>
</rich:inplaceInput>
...
Note:
The "controls" facet also implies using "showControls" attribute and it has to be
defined as "true".
Redefinition of the "save" and "cancel" icons can be performed using "saveControlIcon" and
"cancelControlIcon" attributes. You need to define the path to where your images are located.
Example:
...
446
JavaScript API
Function Description
edit() Changes the state to edit
cancel() Changes its state to the previous one before
editing (changed or view)
save() Changes its state to changed with a new value
getValue() Gets the current value
447
Chapter 6. The RichFaces Comp...
Function Description
setValue(newValue) Sets the current value (to be implemented)
There are two ways to redefine the appearance of all <rich:inplaceInput> components at once:
Table 6.242. Skin parameters redefinition for "save" and "cancel" controls
Table 6.245. Classes names that define input field look and feel in edit state
448
Definition of Custom Style Classes
Table 6.247. Class name for the input field in edit state
Table 6.249. Classes names "save" and "cancel" controls in Edit state
449
Chapter 6. The RichFaces Comp...
In order to redefine styles for all <rich:inplaceInput> 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-inplace-field {
font-style: italic;
}
...
It's aslo possible to change styles of a particular <rich:inplaceInput> component. In this case you
should create own style classes and use them in corresponding <rich:inplaceInput> styleClass
attributes. An example is placed below:
Example:
...
.myClass {
color: #008cca;
}
450
Relevant Resources Links
...
The "viewClass" attribute for the <rich:inplaceInput> is defined as it's shown in the example
below:
Example:
This is a result:
Figure 6.149. Modificaton of a look and feel with own classes and styleClass
attributes
As it could be seen on the picture above, the font color of the text on the component was changed.
451
Chapter 6. The RichFaces Comp...
• Edit mode activation when the component got focus with the "Tab"
452
Key Features
453
Chapter 6. The RichFaces Comp...
454
Key Features
Name Value
component-type org.richfaces.InplaceSelect
component-class org.richfaces.component.html.HtmlInplaceSelect
455
Chapter 6. The RichFaces Comp...
Name Value
component-family org.richfaces.InplaceSelect
renderer-type org.richfaces.renderkit.InplaceSelectRenderer
tag-class org.richfaces.taglib.InplaceSelectTag
Example:
...
<rich:inplaceSelect value="#{bean.inputValue}">
<f:selectItem itemValue="1" itemLabel="factory"/>
</rich:inplaceSelect>
...
import org.richfaces.component.html.inplaceSelect;
...
HtmlInpaceSelect myInplaceSelect = new InplaceSelect();
...
• View state displays default label with the value taken from "value" or "defaultLabel" attributes.
If the initial value of the "value" attribute is "null" or empty string the "defaultLabel" attribute
is used to define default label.
Example:
...
<rich:inplaceSelect value="#{bean.value}" defaultLabel="click to edit">
<f:selectItems value="#{bean.selectItems}" />
456
Details of Usage
</rich:inplaceSelect>
...
In the example above the "value" attribute is not initialized therefore "click to edit" text,
that "defaultLabel" , contains is displayed.
You can form the list of the options using <f:selectItem/> and <f:selectItems/> facets.
Example:
...
<rich:inplaceSelect value="#{bean.inputValue}" defaultLabel="click to edit">
<f:selectItems value="#{bean.selectItems}"/>
457
Chapter 6. The RichFaces Comp...
In the example above the value of the selected item is available via "value" attribute.
The "editEvent" attribute provides an option to assign an JavaScript action that initiates the
change of the state from view to edit. The default value is "onclick".
Example:
...
<rich:inplaceSelect value="#{bean.inputValue}" defaultLabel="Double Click to edit"
editEvent="ondblclick">
<f:selectItems value="#{demo.selectItems}" />
</rich:inplaceSelect>
...
Example:
...
<rich:inplaceSelect value="#{bean.inputValue}" oneditactivation="if (!confirm('Are you sure you
want to change the value?')){return false;}">
<f:selectItems value="#{demo.selectItems}" />
</rich:inplaceSelect>
...
The given code illustrates how "oneditactivation" attribute works, namely when the state is being
changed from view to edit, a confirmation window with a message "Are you sure you want
to change value?" comes up.
To prevent opening the drop-down list by default, once edit state is activated, set the "openOnEdit"
attribute to "false". The default value is "true".
458
Details of Usage
Example:
...
<rich:inplaceSelect value="#{bean.inputValue}" showControls="true" openOnEdit="false">
<f:selectItems value="#{bean.selectItems}"/>
</rich:inplaceSelect>
...
Nowever, if you want to confirm the data saving explicitly you can use the "showControls"
attribute, which makes "Save" and "Cancel" buttons (displayed as icons) appear next to the input
field. Edit state can be deactivated by pressing "Esc" key. An option in the drop-drown list can be
also selected by pressing "Enter".
Example:
...
<rich:inplaceSelect value="#{bean.inputValue}" showControls="true">
<f:selectItems value="#{bean.selectItems}"/>
</rich:inplaceSelect>
...
You can also position the controls relatively to the input field, by means of
Example:
459
Chapter 6. The RichFaces Comp...
...
<rich:inplaceSelect value="#{bean.inputValue}" controlsHorizontalPosition="left"
controlsVerticalPosition="center" showControls="true">
<f:selectItems value="#{bean.selectItems}"/>
</rich:inplaceSelect>
...
It is also possible to use "controls" facet in order to replace the default controls with facets content.
See the example below.
Example:
...
<rich:inplaceSelect value="#{bean.inputValue}" showControls="true">
<f:facet name="controls">
<button onclick="#{rich:component('inplaceSelect')}.save();" type="button">Save</button>
<button onclick="#{rich:component('inplaceSelect')}.cancel();" type="button">Cancel</
button>
</f:facet>
<f:selectItems value="#{bean.selectItems}"/>
</rich:inplaceSelect>
...
460
JavaScript API
Note:
The "controls" facet also implies using "showControls" attribute and it has to be
defined as "true".
In order to specify the height and width parameters for the list items of the component, you can
use "listHeight" and " listWidth" attributes.
Function Description
edit() Changes the state to edit
cancel() Changes its state to the previous one before
editing (changed or view)
save() Changes its state to changed with a new value
getValue() Gets the current value
setValue(newValue) Sets the current value (to be implemented)
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:inplaceSelect> components at once:
461
Chapter 6. The RichFaces Comp...
Table 6.254. Skin parameters redefinition for input field in edit state
462
Definition of Custom Style Classes
Table 6.260. Class name for the input field in edit state
463
Chapter 6. The RichFaces Comp...
In order to redefine styles for all <rich:inplaceSelect> 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-inplace-select-list-decoration{
background-color: #ecf4fe;
}
...
Example:
...
.myClass {
background-color:#bed6f8;
font-style:italic;}
464
Relevant Resources Links
...
The "viewClass" attribute for <rich:inplaceSelect> is defined as it's shown in the example
below:
Example:
This is a result:
Figure 6.160. Modificaton of a look and feel with own classes and styleClass
attributes
As it could be seen on the picture above, the font style and background color in view state is
changed.
465
Chapter 6. The RichFaces Comp...
466
Key Features
467
Chapter 6. The RichFaces Comp...
468
Key Features
469
Chapter 6. The RichFaces Comp...
Name Value
tag-class org.richfaces.taglib.InputNumberSliderTag
Example:
...
<rich:inputNumberSlider minValue="0" maxValue="100" step="1"/>
...
import org.richfaces.component.html.HtmlInputNumberSlider;
...
HtmlInputNumberSlider mySlider = new HtmlInputNumberSlider();
...
Here is the simplest variant of a slider definition with "minValue" , "maxValue" and "step" (on
default is "1") attributes, which define the beginning and the end of a numerical area and a slider
property step.
Example:
<rich:inputNumberSlider></rich:inputNumberSlider>
It generates on a page:
Using "showInput" (default is "true") and "enableManualInput" (default value is "true") attributes,
it's possible to output the input area near the slider, and make it read-only or editable.
470
Look-and-Feel Customization
Example:
It's also possible to switch off displaying of "boundary values" and a toolTip showing on a
handle drawing. This could be performed with the help of the component defined attributes:
"showBoundaryValues" which is responsible for "boundary values" displaying (default is true) and
"showToolTip" which is responsible for tooltTip displaying (default is "true").
Moreover, to add e.g. some JavaScript effects, events defined on it are used.
• "onchange"
• "onmouseover"
• "onclick"
• "onfocus"
• "onmouseout"
• etc.
The "label" attribute is a generic attribute. The "label" attribute provides an association between
a component, and the message that the component (indirectly) produced. This attribute defines
the parameters of localized error and informational messages that occur as a result of conversion,
validation, or other application actions during the request processing lifecycle. With the help of
this attribute you can replace the last parameter substitution token shown in the messages. For
example, {1} for "DoubleRangeValidator.MAXIMUM" , {2} for "ShortConverter.SHORT" .
There are two ways to redefine the appearance of all <rich:inputNumberSlider> components
at once:
471
Chapter 6. The RichFaces Comp...
472
Definition of Custom Style Classes
In order to redefine styles for all <rich:inputNumberSlider> components on a page using CSS,
it's enough to create classes with the same names (possible classes could be found in the table
above ) and define necessary properties in them. An example is placed below:
Example:
...
.rich-inslider-tip{
background-color: #FFDAB9;
font-family: Arial Black;
}
...
This is a result:
473
Chapter 6. The RichFaces Comp...
In the example a tip background color and font family was changed.
Example:
...
.myClass{
font-style: italic;
font-weight:bold;
font-size:12px;
}
...
The "inputClass" attribute for <rich:inputNumberSlider> is defined as it's shown in the example
below:
Example:
This is a result:
As it could be seen on the picture above, the font style for input text was changed.
474
Key Features
isn't locked by the "manualInput" attribute. When arrow controls are pressed, the cursor can be
moved in any way without losing a dragged state.
475
Chapter 6. The RichFaces Comp...
476
Key Features
477
Chapter 6. The RichFaces Comp...
Name Value
component-type org.richfaces.inputNumberSpinner
component-class org.richfaces.component.html.HtmlInputNumberSpinner
component-family org.richfaces.inputNumberSpinner
renderer-type org.richfaces.InputNumberSpinnerRenderer
tag-class org.richfaces.taglib.InputNumberSpinnerTag
Example:
478
Creating the Component Dynamically Using
Java
...
<rich:inputNumberSpinner minValue="0" maxValue="100" step="1"/>
...
Example:
import org.richfaces.component.html.HtmlInputNumberSpinner;
...
HtmlInputNumberSpinner mySpinner = new HtmlInputNumberSpinner ();
...
Here is the simplest variant of spinner definition with "minValue" , "maxValue" and "step" (on
default is "1") attributes, which define the beginning and the end of numerical area and a spinner
step.
Example:
...
<rich:inputNumberSpinner minValue="1" maxValue="100"/>
...
It generates on a page:
• "cycled" if the attribute is "true" after the current value reaches the border value it's be reversed
to another border value after next increasing/decreasing. In other case possibilities of next
increasing/decreasing are locked
479
Chapter 6. The RichFaces Comp...
Moreover, to add e.g. some JavaScript effects, events defined on it are used
• "onchange"
• "onmouseover"
• "onclick"
• "onfocus"
• "onmouseout"
• etc.
The "label" attribute is a generic attribute. The "label" attribute provides an association between
a component, and the message that the component (indirectly) produced. This attribute defines
the parameters of localized error and informational messages that occur as a result of conversion,
validation, or other application actions during the request processing lifecycle. With the help of
this attribute you can replace the last parameter substitution token shown in the messages. For
example, {1} for "DoubleRangeValidator.MAXIMUM" , {2} for "ShortConverter.SHORT" .
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:inputNumberSpinner> components
at once:
480
Definition of Custom Style Classes
Example:
...
.rich-spinner-input{
font-style:italic;
}
481
Chapter 6. The RichFaces Comp...
...
This is a result:
Example:
...
.myClass{
font-family: Arial Black;
}
...
Example:
This is a result:
As it could be seen on the picture above, the font family for input text was changed.
482
< rich:insert >
6.62.1. Description
The <rich:insert> component is used for highlighting, source code inserting and, optionally,
format the file from the application context into the page.
Name Value
component-type org.richfaces.ui.Insert
component-class org.richfaces.ui.component.html.HtmlInsert
component-family org.richfaces.ui.Insert
483
Chapter 6. The RichFaces Comp...
Name Value
renderer-type org.richfaces.ui.InsertRenderer
tag-class org.richfaces.ui.taglib.InsertTag
Example:
...
<rich:insert src="/pages/sourcePage.xhtml" highlight="xhtml"/>
...
Example:
import org.richfaces.ui.component.html.HtmlInsert;
...
HtmlInsert myInsert = new HtmlInsert();
...
The are two basic attributes. The "src" attribute defines the path to the file with source code. The
"highlight" attribute defines the type of a syntax highlighting.
Example:
...
<rich:insert src="/pages/sourcePage.xhtml" highlight="xhtml"/>
...
484
Look-and-Feel Customization
6.63.1. Description
The <rich:jQuery> allows to apply styles and behaviour to DOM objects.
485
Chapter 6. The RichFaces Comp...
Name Value
component-type org.richfaces.JQuery
component-class org.richfaces.component.html.HtmlJQuery
component-family org.richfaces.JQuery
renderer-type org.richfaces.JQueryRenderer
tag-class org.richfaces.taglib.JQueryTag
Example:
486
Creating the Component Dynamically Using
Java
...
<rich:jQuery selector="#customList tr:odd" timing="onload" query="addClass(odd)" />
...
import org.richfaces.component.html.HtmlJQuery;
...
HtmlJQuery myJQuery = new HtmlJQuery();
...
The mode is chosen with "timing" attribute that has the following options:
• onJScall - applying a query by invoked JavaScript function defined with the "name" attribute
Definition of the "name" attribute is mandatory when the value of "timing" attribute is "onJScall".
If the "name" attribute is defined when "timing" value equals to "immediate" or "onload", the query
is applied according to this value, but you still have an opportunity to invoke it by a function name.
The "selector" attribute defines an object or a list of objects. The query is defined with the "query"
attribute.
Example:
...
<style>
.odd {
background-color: #FFC;
}
487
Chapter 6. The RichFaces Comp...
</style>
...
...
<rich:table id="customList" ...>
...
</rich:table>
...
<rich:jQuery selector="#customList tr:odd" timing="onload" query="addClass(odd)" />
...
The "selector" attribute uses defined by w3c consortium syntax for CSS rule selector [http://
www.w3.org/TR/REC-CSS2/selector.html] with some jQuery extensions
Selector Comment
"p[a]" In a document all "p" tags with "a" tag inside
are selected
"ul/li" All "li" elements of unordered "ul" lists are
selected
"p.foo[a]" All "p" tags with "foo" class and inserted "a" tag
are selected
"input[@name=bar]" All "input" tags with "name" attribute which
value is "bar" are selected
"input[@type=radio][@checked]" All "input" tags with attribute "type"="radio" and
attribute value = "chekced" are selected
"p,span,td" All tag elements "p" or"span" or "td" are
selected
"p#secret" "p" paragraph element with "id" identification =
"secret" is selected
"p span" "span" tag is a (direct or non-direct) child of "p"
tag. If it's necessary, use "p > span" or "p/span"
is selected
"p[@foo^=bar]" "p" tag containing "foo" attribute with textual
value beginning with "bar" word is selected
"p[@foo$=bar] " "p" tag containing "foo" attribute with textual
value ending with "bar" word is selected
488
Details of Usage
Selector Comment
"p[@foo*=bar] " "p" tag with "foo" attribute containing substring
"bar" in any place is selected
"p//span " "span" tag that is a (direct or non-direct) child
of "p" tag is selected
"p/../span " "span" tag that is a grandchild of "p" tag is
selected
In addition, RichFaces allows using either a component id or client id if you apply the query to a
JSF component. When you define a selector, RichFaces examines its content and tries to replace
the defined in the selector id with a component id if it's found.
...
<h:form id="form">
...
<h:panelGrid id="menu">
<h:graphicImage ... />
<h:graphicImage ... />
...
</h:panelGrid>
</h:form>
...
The actual id of the <h:panelGrid> table in the browser DOM is "form:menu". However, you
still can reference to images inside this table using the following selector:
...
<rich:jQuery selector="#menu img" query="..." />
...
You can define the exact id in the selector if you want. The following code reference to the same
set of a DOM object:
...
<rich:jQuery selector="#form\\:menu img" query="..." />
...
489
Chapter 6. The RichFaces Comp...
In case when the "name" attribute is defined, <rich:jQuery> generates a JavaScript function
that might be used from any place of JavaScript code on a page.
There is an example of how to enlarge the picture smoothly on a mouse over event and return
back to the normal size on mouse out:
...
<h:graphicImage onmouseover="enlargePic(this)" width="50" value="/images/price.png"
onmouseover="enlargePic(this, {pwidth:'60px'})" onmouseover="releasePic(this)" />
<h:graphicImage onmouseover="enlargePic(this)" width="50" value="/images/discount.png"
onmouseover="enlargePic(this, {pwidth:'100px'})" onmouseover="releasePic(this)" />
...
<rich:jQuery name="enlargePic" timing="onJScall" query="animate({width:param.pwidth})" />
<rich:jQuery name="releasePic" timing="onJScall" query="animate({width:'50px'})"/>
...
The JavaScript could use two parameters. The first parameter is a replacement for the selector
attribute. Thus, you can share the same query, applying it to the different DOM objects. You can
use a literal value or a direct reference for an existing DOM object. The second parameter can
be used to path the specific value inside the query. The JSON syntax is used for the second
parameter. The "param." namespace is used for referencing data inside the parameter value.
<rich:jQuery> adds styles and behavior to the DOM object dynamically. This means if you replace
something on a page during an Ajax response, the applied artifacts is overwritten. But you are
allowed to apply them again after the Ajax response is complete.
Usually, it could be done with reRendering the <rich:jQuery> components in the same Ajax
interaction with the components these queries are applied to. Note, that queries with "timing"
attribute set to "onload" are not invoked even if the query is reRendered, because a DOM
document is not fully reloaded during the Ajax interaction. If you need to re-applies query with
"onload" value of "timing" attribute, define the "name" attribute and invoke the query by name
in the "oncomplete" attribute of the Ajax component.
RichFaces includes jQuery JavaScript framework. You can use the futures of jQuery directly
without defining the <rich:jQuery> component on a page if it is convenient for you. To start using
the jQuery feature on the page, include the library into a page with the following code:
...
<a4j:loadScript src="resource://jquery.js"/>
...
Refer to the jQuery documentation [http://docs.jquery.com/] for the right syntax. Remember to use
jQuery() function instead of $(), as soon as jQuery works without conflicts with prototype.js.
490
Look-and-Feel Customization
• Keyboard support
491
Chapter 6. The RichFaces Comp...
492
Key Features
493
Chapter 6. The RichFaces Comp...
494
Creating the Component with a Page Tag
Example:
...
<rich:listShuttle var="item" sourceValue="#{bean.source}" targetValue="#{bean.target}"
converter="listShuttleconverter">
<h:column>
<f:facet name="header">
<h:outputText value="Cars" />
</f:facet>
<h:outputText value="#{item.name}" />
</h:column>
</rich:listShuttle>
...
import org.richfaces.component.html.HtmlListShuttle;
...
HtmlListShuttle myListShuttle = new HtmlListShuttle();
...
495
Chapter 6. The RichFaces Comp...
• two item lists (source and target). List consists of items. Each item has three different
representations: common, selected, active
• move controls set is a set of controls, which performs moving items between lists
The "sourceValue" attribute defines a List or Array of items to be shown in the source list.
The "targetValue" attribute defines a List or Array of items to be shown in the target list.
The "var" attribute could be shared between both Lists or Arrays to define lists on the page.
The "sourceRequired" and "targetRequired" attributes define the case when source and target
values are being validated. If the value of both attributes is "true" there should be at least one item
in source and target lists. Otherwise validation fails.
Example:
...
<h:form id="myForm">
<rich:messages>
<f:facet name="errorMarker">
<h:graphicImage value="/images/ajax/error.gif" />
</f:facet>
</rich:messages>
<rich:listShuttle id="myListShuttle" sourceValue="#{toolBar.freeItems}"
targetValue="#{toolBar.items}"
sourceRequired = "true" targetRequired = "true" var="items"
converter="listShuttleconverter"
sourceCaptionLabel="Source List" targetCaptionLabel="Target List">
<rich:column>
<h:graphicImage value="#{items.iconURI}" />
</rich:column>
<rich:column>
<h:outputText value="#{items.label}" />
</rich:column>
</rich:listShuttle>
<a4j:commandButton value="Submit" />
</h:form>
...
In the example above the source list is empty. If you submit the form validation fails and error
message appears on a page.
496
Details of Usage
The "converter" attribute is used to convert component data to a particular component's value.
For example, when you select items in a list, a converter is used to format a set of objects to a
strings to be displayed.
Note
The "sourceSelection" attribute stores the collection of items selected by you in the source list.
The "targetSelection" attribute stores the collection of items selected by you in the target list.
Captions could be added to a list only after it was defined as a "sourceCaption" and
"targetCaption" named facets inside the component or defined with the "sourceCaptionLabel"
and "targetCaptionLabel" attribute.
...
<rich:listShuttle var="item" sourceValue="#{bean.source}" targetValue="#{bean.target}"
sourceSelection="#{bean.sourceSelection}"
targetSelection="#{bean.targetSelection}" converter="listShuttleconverter">
<f:facet name="sourceCaption">
<h:outputText value="Cars Store #1" />
</f:facet>
<f:facet name="targetCaption">
<h:outputText value="Cars Store #2" />
</f:facet>
<rich:column>
497
Chapter 6. The RichFaces Comp...
The <rich:listShuttle> component provides the possibility to use ordering controls set, which
performs reordering in the target item list. Every control has possibility to be disabled.
Example:
...
<rich:listShuttle var="item" sourceValue="#{bean.source}" targetValue="#{bean.target}"
converter="listShuttleconverter">
...
<f:facet name="topControl">
<h:outputText value="Move to top" />
</f:facet>
<f:facet name="upControl">
<h:outputText value="Move up" />
</f:facet>
<f:facet name="downControl">
<h:outputText value="Move down" />
</f:facet>
<f:facet name="bottomControl">
<h:outputText value="Move to bottom" />
</f:facet>
</rich:listShuttle>
...
The <rich:listShuttle> component also provides 4 predefined controls in move controls set for
moving items between source and target lists. Every control has possibility to be disabled.
498
Details of Usage
...
<rich:listShuttle var="item" sourceValue="#{bean.source}" targetValue="#{bean.target}"
converter="listShuttleconverter"
copyControlLabel="Copy" removeControlLabel="Remove"
copyAllControlLabel="Copy all" removeAllControlLabel="Remove all">
<h:column>
<f:facet name="header">
<h:outputText value="Cars" />
</f:facet>
<h:outputText value="#{item.name}" />
</h:column>
</rich:listShuttle>
...
Controls rendering is based on the "controlsType" attribute. Possible types are button and none.
Note
Currently the button controls type is based on <div> element.
You could also pack org.richfaces.renderkit.listShuttle resource bundle with your JARs
defining the same properties.
499
Chapter 6. The RichFaces Comp...
There are two ways to redefine the appearance of all <rich:listShuttle> components at once:
500
Skin Parameters Redefinition
Table 6.286. Skin parameters redefinition for items in the source and target
lists
Skin parameters CSS properties
generalBackgroundColor background-color
tableBorderColor border-color
tableBorderWidth border-width
Table 6.287. Skin parameters redefinition for caption in the source and
target lists
Skin parameters CSS properties
headerFamilyFont font-family
headerSizeFont font-size
headerWeightFont font-weight
Table 6.288. Skin parameters redefinition for a selected rows in the source
and target lists
Skin parameters CSS properties
additionalBackgroundColor background-color
501
Chapter 6. The RichFaces Comp...
502
Definition of Custom Style Classes
On the screenshot there are classes names that define styles for component elements.
503
Chapter 6. The RichFaces Comp...
504
Definition of Custom Style Classes
Table 6.304. Classes names that define a cells representations in a target list
Class name Description
rich-shuttle-target-cell Defines styles for a cell in a target list
rich-shuttle-target-cell-selected Defines styles for a selected cell in a target list
rich-shuttle-target-cell-active Defines styles for an active cell in a target list
505
Chapter 6. The RichFaces Comp...
In order to redefine styles for all <rich:listShuttle> 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-shuttle-source-row-active{
background-color:#FFE4B5;
}
...
This is a result:
In the example an active row background color in the source list was changed.
Also it's possible to change styles of particular <rich:listShuttle> component. In this case you
should create own style classes and use them in corresponding <rich:listShuttle> styleClass
attributes. An example is placed below:
Example:
...
.myClass{
font-style:italic;
506
Relevant Resources Links
}
...
The "rowClasses" attribute for <rich:listShuttle> is defined as it's shown in the example below:
Example:
This is a result:
Figure 6.177. Redefinition styles with own classes and styleClass attributes
As it could be seen on the picture above, font style for row items was changed.
507
Chapter 6. The RichFaces Comp...
508
Key Features
509
Chapter 6. The RichFaces Comp...
Example:
...
<rich:message for="id"/>
...
import org.richfaces.component.html.HtmlRichMessage;
...
HtmlRichMessage myMessage = new HtmlRichMessage();
...
• It's ajaxRendered. It means that the component is reRendered after Ajax request automatically
without outputPanel usage
• The component optionally provides "passed" state which will be shown if no message is
displayed
• Provides possibility to add some marker to message. By default a marker element isn't shown
• "passedMarker" . This facet is provided to allow setting a marker to display if there is no message
510
Look-and-Feel Customization
• "errorMarker" . This facet is provided to allow setting a marker to display if there is a message
with a severity class of "ERROR"
• "fatalMarker" . This facet is provided to allow setting a marker to display if there is a message
with a severity class of "FATAL"
• "infoMarker" . This facet is provided to allow setting a marker to display if there is a message
with a severity class of "INFO"
• "warnMarker" . This facet is provided to allow setting a marker to display if there is a message
with a severity class of "WARN"
The following example shows different variants for component customization. The attribute
"passedLabel" is used for definition of the label to display when no message appears. But the
message component doesn't appear before the form submission even when state is defined
as passed (on initial rendering). Boolean attribute "showSummary" defines possibility to display
summary portion of displayed messages. The facets "errorMarker" and "passedMarker" set
corresponding images for markers.
Example:
...
<rich:message for="id" passedLabel="No errors' showSummary="true">
<f:facet name="errorMarker">
<h:graphicImage url="/image/error.png"/>
</f:facet>
<f:facet name="passedMarker">
<h:graphicImage url="/image/passed.png"/>
</f:facet>
</rich:message>
...
For skinnability implementation, the components use a style class redefinition method.
There are no skin parameters and default predefined values. To redefine the appearance of all
<rich:message> components at once, you should only add to your style sheets style classes
used by a <rich:message> component.
On the screenshot there are classes names that define styles for component elements.
511
Chapter 6. The RichFaces Comp...
In order to redefine styles for all <rich:message> 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-message-label{
font-style:italic
}
...
This is a result:
512
Definition of Custom Style Classes
Also it's possible to change styles of particular <rich:message> component. In this case you
should create own style classes and use them in corresponding <rich:message> styleClass
attributes. An example is placed below:
Example:
...
.myClass{
font-weight:bold;
}
...
The "styleClass" attribute for <rich:message> is defined as it's shown in the example below:
Example:
This is a result:
513
Chapter 6. The RichFaces Comp...
Figure 6.181. Redefinition styles with own classes and styleClass attributes
As it could be seen on the picture above, the font weight for message was changed.
6.66.1. Description
• Additionally provides of three parts to be optionally defined: marker, label and header
514
Key Features
515
Chapter 6. The RichFaces Comp...
516
Creating the Component with a Page Tag
Name Value
component-type org.richfaces.component.RichMessages
component-class org.richfaces.component.html.HtmlRichMessages
component-family org.richfaces.component.RichMessages
renderer-type org.richfaces.renderkit.html.HtmlRichMessagesRendere
tag-class org.richfaces.taglib.RichMessagesTag
Example:
...
<rich:messages/>
...
import org.richfaces.component.html.HtmlRichMessages;
...
HtmlRichMessages myMessages = new HtmlRichMessages();
...
• It's ajaxRendered. It means that the component is reRendered after Ajax request automatically
without outputPanel usage.
517
Chapter 6. The RichFaces Comp...
• The component optionally provides "passed" state which will be shown if no message to be
displayed.
• Provides possibility to add some marker to message. By default, a marker element isn't shown.
The component provides two parts to be optionally defined: marker and informational label before
the marker for every message.
Example:
...
<rich:messages layout="table" tooltip="true" showDetail="false" showSummary="true"
passedLabel="No Errors" var="messages">
<f:facet name="errorMarker">
<h:graphicImage url="/image/error.png"/>
</f:facet>
<f:facet name="infoMarker">
<h:graphicImage url="/image/info.png"/>
</f:facet>
<f:facet name="passedMarker">
<h:graphicImage url="/image/passed.png"/>
</f:facet>
</rich:messages>
...
518
Definition of Custom Style Classes
There are no skin parameters and default predefined values. To redefine the appearance of all
<rich:messages> components at once, you should only add to your style sheets style classes
used by a <rich:messages> component.
On the screenshot there are classes names that define styles for component elements.
In order to redefine styles for all <rich:messages> 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-messages-label{
font-style:italic;
}
...
This is a result:
519
Chapter 6. The RichFaces Comp...
Also it's possible to change styles of particular <rich:messages> component. In this case you
should create own style classes and use them in corresponding <rich:messages> styleClass
attributes. An example is placed below:
Example:
...
.myClass{
color:red;
}
...
The "errorClass" attribute for <rich:messages> is defined as it's shown in the example below:
Example:
This is a result:
520
Relevant Resources Links
Figure 6.185. Redefinition styles with own classes and styleClass attributes
6.67.1. Description
The component implements a modal dialog window. All operations in the main application window
are locked out while this window is active. Opening and closing the window is done through client
JavaScript code.
521
Chapter 6. The RichFaces Comp...
• Possibility to restore of the previous component state on a page (including position on the
screen) after submitting and reloading
522
Key Features
523
Chapter 6. The RichFaces Comp...
524
Creating the Component with a Page Tag
Name Value
component-type org.richfaces.ModalPanel
component-class org.richfaces.component.html.HtmlModalPanel
component-family org.richfaces.ModalPanel
renderer-type org.richfaces.ModalPanelRenderer
tag-class org.richfaces.taglib.ModalPanelTag
Example:
...
<rich:modalPanel id="panel">
<f:facet name="header">
<h:outputText value="header" />
</f:facet>
...
<!--Any Content inside-->
...
<a onclick="Richfaces.hideModalPanel('modalPanelID');" href="#">Hide</a>
</rich:modalPanel>
<a onclick="Richfaces.showModalPanel('modalPanelID');" href="#">Show</a>
...
import org.richfaces.component.html.HtmlModalPanel;
...
HtmlModalPanel myPanel = new HtmlModalPanel();
...
525
Chapter 6. The RichFaces Comp...
Function Description
RichFaces.showModalPanel (client Id) Opens a window with a specified client Id
RichFaces.hideModalPanel (client Id) Closes a window with a specified client Id
Important:
In order to avoid a bug in IE, the root node of the dialog is moved on the top of
a DOM tree. However, you should have a separate form inside the modal panel
if you want to perform submits from this panel (so, no form should be around the
modal panel in this case).
It's possible to add a "header" facet to the component to set the content for the header.
Example:
...
<rich:modalPanel id="panel" width="400" height="300">
<f:facet name="header">
<h:outputText value="Modal Panel"/>
</f:facet>
<h:graphicImage value="/pages/california_large.png"/>
<a href="javascript:Richfaces.hideModalPanel('form:panel')">Close</a>
</rich:modalPanel>
<a href="javascript:Richfaces.showModalPanel('form:panel');">Open</a>
...
This defines a window with a particular size and ID. It includes one "Open" link. Clicking on this
link makes the modal window content appear.
526
Details of Usage
A facet named "controls" can be added to the component to place control elements on a header.
Example:
...
<rich:modalPanel id="mp">
<f:facet name="header">
<h:outputText value="Modal Panel"/>
</f:facet>
<f:facet name="controls">
<h:graphicImage value="/pages/close.png" style="cursor:pointer"
onclick="Richfaces.hideModalPanel('mp')" />
</f:facet>
<h:graphicImage value="/pages/california_large.png"/>
</rich:modalPanel>
...
527
Chapter 6. The RichFaces Comp...
To manage the placement of inserted windows, use the "zindex" attribute that is similar to the
standard HTML attribute and can specify window placement relative to the content.
To manage window placement relative to the component, there are "left" and "top" attributes
defining a window shifting relative to the top-left corner of the window.
Modal windows can also support resize and move operations on the client side. To allow or
disallow these operations, set the "resizeable" and "moveable" attributes to "true" or "false"
values. Window resizing is also limited by "minWidth" and "minHeight" attributes specifying the
minimal window sizes.
You can pass your parameters during modalPanel opening or closing. This passing could be
performed in the following way:
Example:
Thus, except the standard modalPanel parameters you can pass any of your own parameters.
Also modalPanel allows to handle its own opening and closing events on the client side. The
"onshow" and "onclose" attributes are used in this case.
The following example shows how on the client side to define opening and closing event handling
in such a way that your own parameters could also be obtained:
Example:
528
Details of Usage
onshow="alert(event.parameters.param1)"
More information about this problem could be found on the RichFaces Development Forum [http:/
/www.jboss.com/index.html?module=bb&op=viewtopic&t=111804].
There is a possibility to restore of the previous component state on a page (including position
on the screen) after submitting and reloading. The modalPanel has some special attributes like
"showWhenRendered" and "keepVisualState" .
Example:
...
<a href="javascript:Richfaces.showModalPanel('_panel', {top:'10px', left:'10px',
height:'400'});">Show</a>
...
Here, if you open modal dialog window using current link and after submits data then modalPanel
destination and height on new loaded page is restored.
if you need the content of the modalPanel to be submitted - you need to remember two important
rules:
• modalPanel must have its own form if it has form elements (input or/and command components)
inside (as it was shown in the example above)
• modalPanel must not be included into the form (on any level up) if it has the form inside.
Example:
...
<rich:modalPanel>
<f:facet name="header">
529
Chapter 6. The RichFaces Comp...
See also discussion about this problem on the RichFaces Users Forum [http://www.jboss.com/
index.html?module=bb&op=viewtopic&p=4064191].
The "label" attribute is a generic attribute. The "label" attribute provides an association between
a component, and the message that the component (indirectly) produced. This attribute defines
the parameters of localized error and informational messages that occur as a result of conversion,
validation, or other application actions during the request processing lifecycle. With the help of
this attribute you can replace the last parameter substitution token shown in the messages. For
example, {1} for "DoubleRangeValidator.MAXIMUM", {2} for "ShortConverter.SHORT".
Function Description
show() Opens the corresponding modalPanel
hide() Closes the corresponding modalPanel
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:modalPanel> components at once:
530
Skin Parameters Redefinition
531
Chapter 6. The RichFaces Comp...
The screenshot shows the classes names for defining different elements.
532
Definition of Custom Style Classes
In order to redefine styles for all <rich:modalPanel> 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-mpnl-mask-div{
background-color:#fae6b0;
}
...
This is a result:
Also it's possible to change styles of particular <rich:modalPanel> component. In this case you
should create own style classes and use them in corresponding <rich:modalPanel> styleClass
attributes. An example is placed below:
Example:
...
533
Chapter 6. The RichFaces Comp...
.myClass{
font-style:italic;
}
...
The "headerClass" attribute for <rich:modalPanel> is defined as it's shown in the example
below:
Example:
This is a result:
Figure 6.191. Redefinition styles with own classes and styleClass attributes
As it could be seen on the picture above,the font style for header was changed.
534
< rich:orderingList >
• Keyboard support
535
Chapter 6. The RichFaces Comp...
536
Key Features
537
Chapter 6. The RichFaces Comp...
Name Value
component-type org.richfaces.OrderingList
component-class org.richfaces.component.html.HtmlOrderingList
component-family org.richfaces.OrderingList
renderer-type org.richfaces.OrderingListRenderer
Example:
...
<rich:orderingList value="#{bean.list}" var="list">
<rich:column>
<f:facet name="header">
<h:outputText value="Name" />
</f:facet>
<h:inputText value="#{list.name}" />
</rich:column>
<rich:orderingList>
...
Example:
import org.richfaces.component.html.HtmlOrderingList;
...
HtmlOrderingList myOrderingList = new HtmlOrderingList();
...
538
Details of Usage
• Item list element that displays a list of items. It has three different representations for a single
element: common, selected, active. Combination of these states is possible.
The "value" and "var" attributes are used to access the values of a list.
Controls rendering is based on the "controlsType" attribute. Possible types are button or none.
Note
The "selection" attribute stores the collection of items selected by you. In the example below
after submitting the form the current collection is placed in the object's property and then
<rich:dataTable> with selected items is shown.
Example:
...
<h:form>
<rich:orderingList value="#{bean.simpleItems}" var="item" selection="#{bean.selection}"
controlsType="button">
<rich:column>
<f:facet name="header">
<h:outputText value="Cars" />
</f:facet>
<h:outputText value="#{item}" />
</rich:column>
</rich:orderingList>
<rich:dataTable id="infoPanelID" value="#{bean.info}" var="info" rendered="true">
<rich:column>
<h:outputText value="#{info}" />
</rich:column>
</rich:dataTable>
<a4j:commandButton value="reRender" reRender="infoPanelID" />
</h:form>
...
539
Chapter 6. The RichFaces Comp...
The <rich:orderingList> component allows to use "caption" facet. A caption could be also
defined with "captionLabel" attribute.
Example:
...
<rich:orderingList value="#{bean.simpleItems}" var="item" controlsType="button"
selection="#{bean.selection}">
<f:facet name="caption">
<h:outputText value="Caption Facet" />
</f:facet>
<rich:column>
<f:facet name="header">
<h:outputText value="Cars" />
</f:facet>
<h:outputText value="#{item.name}" />
</rich:column>
<rich:column>
<f:facet name="header">
<h:outputText value="Price" />
</f:facet>
<h:outputText value="#{item.price}" />
</rich:column>
</rich:orderingList>
...
The <rich:orderingList> component provides the possibility to use ordering controls set, which
performs reordering. Every control has possibility to be disabled.
Example:
...
<rich:orderingList value="#{bean.simpleItems}" var="item" controlsType="button"
selection="#{bean.selection}">
<f:facet name="topControl">
540
Details of Usage
The <rich:orderingList> component has a possibility to hide any of the controls by pairs using
following attributes:
• "orderControlsVisible" attribute has two values: "true" or "false". If false Up and Down controls
are not displayed.
• "fastOrderControlsVisible" attribute has two values: "true" or "false". If false Top and Bottom
controls are not displayed.
541
Chapter 6. The RichFaces Comp...
You could also pack org.richfaces.renderkit.orderingList resource bundle with your JARs
defining the same properties.
Function Description
hide() Hides ordering control (to be implemented)
show() Shows ordering control (to be implemented)
isShown() Checks if current control is shown (to be
implemented)
enable() Enables ordering control (to be implemented)
disable() Disables ordering control (to be implemented)
isEnabled() Checks if current control is enabled (to be
implemented)
Up() Moves up selected item in the list
Down() Moves down selected item in the list
Top() Moves top selected item in the list
Bottom() Moves bottom selected item in the list
542
Look-and-Feel Customization
Function Description
getSelection() Returns currently selected item
getItems() Returns the collection of all items
There are two ways to redefine the appearance of all <rich:orderingList> components at once:
543
Chapter 6. The RichFaces Comp...
544
Skin Parameters Redefinition
Table 6.341. Skin parameters redefinition for top, bottom, up, down controls
and for controls in disabled state
545
Chapter 6. The RichFaces Comp...
546
Definition of Custom Style Classes
547
Chapter 6. The RichFaces Comp...
In order to redefine styles for all <rich:orderingList> 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-ordering-list-table-header-cell{
font-weight:bold;
}
...
This is a result:
In the example the font weight for header text was changed.
Also it's possible to change styles of particular <rich:orderingList> component. In this case you
should create own style classes and use them in corresponding <rich:orderingList> styleClass
attributes. An example is placed below:
Example:
...
.myClass{
font-style:italic;
}
548
Relevant Resources Links
...
The "rowClasses" attribute for <rich:orderingList> is defined as it's shown in the example
below:
Example:
This is a result:
Figure 6.195. Redefinition styles with own classes and styleClass attributes
As it could be seen on the picture above, the font style for rows was changed.
549
Chapter 6. The RichFaces Comp...
• Fully supports "JPEG" (24-bit, default), "GIF" (8-bit with transparency), and "PNG" (32-bit
with transparency) formats for sending generated images
550
Key Features
551
Chapter 6. The RichFaces Comp...
Name Value
component-type org.richfaces.Paint2D
component-class org.richfaces.component.html.HtmlPaint2D
component-family javax.faces.Output
renderer-type org.richfaces.Paint2DRenderer
tag-class org.richfaces.taglib.Paint2DTag
Example:
...
<rich:paint2D paint="#{paint2D.paint}" data="#{paint2DModel}"/>
...
Here "paint" specifies the method performing drawing and "data" specifies Managed Bean
property keeping the data used by the method.
import org.richfaces.component.html.HtmlPaint2D;
...
HtmlPaint2D myImage = new HtmlPaint2D();
...
552
Details of Usage
• "paint"
Specify a method receiving an object specified in data as a parameter and sending graphical
information into the stream
• "data"
Note:
The "format" attribute of the component defines a format of visual data passing to the server.
Generated data can be used as a cacheable or non-cacheable resource. It's defined with
"cacheable" attribute. If cache support is turned on, a key is created in URI with a mix of size
(width/height), "paint" method, "format" and "data" attributes.
Example:
paintBean.java:
dataBean.java:
page.xhtml:
...
<rich:paint2D paint="#{paint2D.paint}" data="#{paint2DModel.data}"/>
553
Chapter 6. The RichFaces Comp...
...
To define some style properties such as an indent or a border, it's possible to use "style" and
"styleClass" attributes on the component.
554
Creating the Component with a Page Tag
555
Chapter 6. The RichFaces Comp...
Example:
...
<rich:panel header="Panel Header">
...
<!--Any Content inside-->
...
</rich:panel>
...
Example:
import org.richfaces.component.html.HtmlPanel;
...
HtmlPanel myPanel = new HtmlPanel();
...
The "header" attribute defines text to be represented. If you can use the "header" facet, you
can even not use the "header" attribute.
Example:
...
<rich:panel>
<f:facet name="header">
<h:graphicImage value="/images/img1.png"/>
</f:facet>
...
<!--Any Content inside-->
...
</rich:panel>
...
<rich:panel> components are used to group page content pieces on similarly formatted
rectangular panels.
Example:
556
Details of Usage
...
<rich:panel>
...
</rich:panel>
...
The example shows that similar rectangular areas are formed with a particular style.
When creating a panel with a header element, one more <div> element is added with content
defined for a header.
Example:
...
<rich:panel>
<f:facet name="header">
<h:outputText value="Olympus EVOLT E-500 "/>
</f:facet>
...
</rich:panel>
...
557
Chapter 6. The RichFaces Comp...
As it has been mentioned above, the component is mostly used for a page style definition, hence
the main attributes are style ones.
• "styleClass"
• "headerClass"
• "bodyClass"
Moreover, to add e.g. some JavaScript effects, events defined on it are used.
• "onmouseover"
• "onclick"
• "onmouseout"
• etc.
There are two ways to redefine the appearance of all <rich:panel> components at once:
558
Definition of Custom Style Classes
On the screenshot there are classes names that define styles for component elements.
In order to redefine styles for all <rich:panel> components on a page using CSS, it's enough
to create classes with the same names (possible classes could be found in the table above) and
define necessary properties in them. An example is placed below:
Example:
...
.rich-panel-body{
background-color: #ebf3fd;
}
559
Chapter 6. The RichFaces Comp...
...
This is a result:
Also it's possible to change styles of particular <rich:panel> component. In this case you should
create own style classes and use them in corresponding <rich:panel> styleClass attributes.
An example is placed below:
Example:
...
.myClass{
text-align: justify;
}
...
The "bodyClass" attribute for <rich:panel> is defined as it's shown in the example below:
Example:
<h:panel... bodyClass="myClass"/>
This is a result:
Figure 6.202. Redefinition styles with own classes and styleClass attributes
As it could be seen on the picture above, text align of body was changed.
560
Relevant Resources Links
561
Chapter 6. The RichFaces Comp...
562
Creating the Component with a Page Tag
Name Value
component-type org.richfaces.PanelBar
component-class org.richfaces.component.html.HtmlPanelBar
component-family org.richfaces.PanelBar
renderer-type org.richfaces.PanelBarRenderer
tag-class org.richfaces.taglib.PanelBarTag
Example:
...
<rich:panelBar>
<!--//... -->
<rich:panelBarItem label="Canon">
...
</rich:panelBarItem>
<rich:panelBarItem label="Nikon">
...
</rich:panelBarItem>
</rich:panelBar>
...
563
Chapter 6. The RichFaces Comp...
import org.richfaces.component.html.HtmlPanelBar;
...
HtmlPanelBar myBar = new HtmlPanelBar();
...
"width" and "height" (both are 100% on default) attributes stand apart.
panelBar could contain any number of child panelBarItem components inside, which content is
uploaded onto the client and headers are controls to open the corresponding child element.
The "label" attribute is a generic attribute. The "label" attribute provides an association between
a component, and the message that the component (indirectly) produced. This attribute defines
the parameters of localized error and informational messages that occur as a result of conversion,
validation, or other application actions during the request processing lifecycle. With the help of
this attribute you can replace the last parameter substitution token shown in the messages. For
example, {1} for "DoubleRangeValidator.MAXIMUM", {2} for "ShortConverter.SHORT".
There are two ways to redefine the appearance of all <rich:panelBar> components at once:
564
Definition of Custom Style Classes
Other classes responsible for elements rendering are described for child <rich:panelBarItem>
elements and could be found in the components chapters.
In order to redefine styles for all <rich:panelBar> 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:
...
565
Chapter 6. The RichFaces Comp...
.rich-panelbar{
font-style: italic;
}
...
This is a result:
Also it's possible to change styles of particular <rich:panelBar> component. In this case you
should create own style classes and use them in corresponding <rich:panelBar> styleClass
attributes. An example is placed below:
Example:
...
.myClass{
font-family: Tahoma;
}
...
The "contentClass" attribute for <rich:panelBar> is defined as it's shown in the example below:
Example:
This is a result:
566
Relevant Resources Links
Figure 6.206. Redefinition styles with own classes and styleClass attributes
As it could be seen on the picture above, the font family for content were changed.
567
Chapter 6. The RichFaces Comp...
Example:
...
<rich:panelBar>
568
Creating the Component Dynamically Using
Java
<rich:panelBarItem label="Canon">
...
</rich:panelBarItem>
<rich:panelBarItem label="Nikon">
...
</rich:panelBarItem>
</rich:panelBar>
...
Example:
import org.richfaces.component.html.HtmlPanelBarItem;
...
HtmlPanelBarItem myBarItem = new HtmlPanelBarItem();
...
The "label" attribute defines text to be represented. If you can use the "label" facet, you can
even not use the "label" attribute.
Example:
...
<rich:panelBarItem...>
<f:facet name="label">
<h:graphicImage value="/images/img1.png"/>
</f:facet>
...
<!--Any Content inside-->
...
</rich:panelBarItem>
...
As it was mentioned above, panelBarItem is used for grouping any content inside within one
panelBar, thus its customization deals only with specification of sizes and styles for rendering.
panelBar could contain any number of child panelBarItem components inside, which content is
uploaded onto the client and headers are controls to open the corresponding child element.
569
Chapter 6. The RichFaces Comp...
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:panelBarItem> components at once:
On the screenshot there are classes names that define styles for component elements.
570
Definition of Custom Style Classes
In order to redefine styles for all <rich:panelBarItem> 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:
...
571
Chapter 6. The RichFaces Comp...
.rich-panelbar-content{
background-color: #ecf4fe;
}
...
This is a result:
Also it's possible to change styles of particular <rich:panelBarItem> component. In this case you
should create own style classes and use them in corresponding <rich:panelBarItem> styleClass
attributes. An example is placed below:
Example:
...
.myClass{
font-family: monospace;
}
...
The "headerClass" attribute for <rich:panelBarItem> is defined as it's shown in the example
below:
Example:
This is a result:
572
< rich:panelMenu >
Figure 6.210. Redefinition styles with own classes and styleClass attributes
As it could be seen on the picture above, the font family for header of active item was changed.
• Disablement support
573
Chapter 6. The RichFaces Comp...
574
Key Features
575
Chapter 6. The RichFaces Comp...
576
Key Features
577
Chapter 6. The RichFaces Comp...
578
Creating the Component with a Page Tag
Name Value
component-type org.richfaces.PanelMenu
component-class org.richfaces.component.html.HtmlPanelMenu
component-family org.richfaces.PanelMenu
renderer-type org.richfaces.PanelMenuRenderer
tag-class org.richfaces.taglib.PanelMenuTag
Example:
...
<rich:panelMenu event="onmouseover">
<!--Nested panelMenu components-->
</rich:panelMenu>
...
Example:
import org.richfaces.component.html.HtmlPanelMenu;
579
Chapter 6. The RichFaces Comp...
...
HtmlPanelMenu myPanelMenu = new HtmlPanelMenu();
...
Use "event" attribute to define an event for appearance of collapsing/expanding sublevels. Default
value is "onclick". An example could be seen below.
Example:
...
<rich:panelMenu event="onmouseover">
<!--Nested panelMenu components-->
</rich:panelMenu>
...
Switching mode could be chosen with the "mode" attribute for all panelMenu items except ones
where this attribute was redefined. By default all items send traditional request.
The "expandMode" attribute defines the submission modes for all collapsing/expanding
panelMenu groups except ones where this attribute was redefined.
The "mode" and "expandMode" attributes could be used with three possible parameters. The
"mode" attribute defines parameters for all included <rich:panelMenuItem> elements.
• Server (default)
The common submission of the form is performed and a page is completely refreshed.
Example:
...
<rich:panelMenu mode="server">
<rich:panelMenuGroup label="test Group" action="#{bean.action}">
<rich:panelMenuItem label="test" action="#{capitalsBean.action}">
<f:param value="test value" name="test"/>
</rich:panelMenuItem>
</rich:panelMenuGroup>
</rich:panelMenu>
...
580
Details of Usage
• Ajax
An Ajax form submission is performed, and additionally specified elements in the "reRender"
attribute are reRendered.
Example:
...
<rich:panelMenu mode="ajax">
<rich:panelMenuGroup label="test Group" action="#{bean.action}">
<rich:panelMenuItem label="test" reRender="test" action="#{capitalsBean.action}">
<f:param value="test value" name="test"/>
</rich:panelMenuItem>
</rich:panelMenuGroup>
</rich:panelMenu>
...
• None
"Action" and "ActionListener" item's attributes are ignored. Items don't fire any submits itself.
Behavior is fully defined by the components nested into items.
Example:
...
<rich:panelMenu event="onclick" submitMode="none">
<rich:panelMenuItem label="Link to external page">
<h:outputLink ... >
<rich:panelMenuItem>
</rich:panelMenu>
...
Note:
The "expandSingle" attribute is defined for expanding more than one submenu on the same
level. The default value is "false" . If it's true the previously opened group on the top level closes
before opening another one. See the picture below.
581
Chapter 6. The RichFaces Comp...
The "selectedChild" attribute is used for defining the name of the selected group or item. An
example for group is placed below:
Here is an example:
Example:
...
<rich:panelMenu selectedChild="thisChild">
<rich:panelMenuGroup label="Group1" name="thisChild">
<!--Nested panelMenu components-->
</rich:panelMenuGroup>
</rich:panelMenu>
...
The "label" attribute is a generic attribute. The "label" attribute provides an association between
a component, and the message that the component (indirectly) produced. This attribute defines
the parameters of localized error and informational messages that occur as a result of conversion,
validation, or other application actions during the request processing lifecycle. With the help of
this attribute you can replace the last parameter substitution token shown in the messages. For
example, {1} for "DoubleRangeValidator.MAXIMUM", {2} for "ShortConverter.SHORT".
In Java Script code for expanding/collapsing group element creation it's necessary to use
expand()/collapse() function.
582
Look-and-Feel Customization
Function Description
expand() Expands group element
collapse() Collapses group element
For skinnability implementation, the components use a style class redefinition method.
There are no skin parameters. To redefine the appearance of all <rich:panelMenu> components
at once, you should add to your style sheets the style class used by a <rich:panelMenu>
component.
In order to redefine styles for all <rich:panelMenu> 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-pmenu{
font-style:italic;
}
...
This is a result:
583
Chapter 6. The RichFaces Comp...
Also it's possible to change styles of particular <rich:panelMenu> component. In this case you
should create own style classes and use them in corresponding <rich:panelMenu> styleClass
attributes. An example is placed below:
Example:
...
.myClass{
background-color: #ecf4fe;
}
...
The "hoveredItemClass" attribute for <rich:panelMenu> is defined as it's shown in the example
below:
Example:
This is a result:
584
Relevant Resources Links
As it could be seen on the picture above,background color for hovered item was changed.
585
Chapter 6. The RichFaces Comp...
586
Key Features
587
Chapter 6. The RichFaces Comp...
588
Key Features
589
Chapter 6. The RichFaces Comp...
590
Creating the Component with a Page Tag
Name Value
component-type org.richfaces.PanelMenuGroup
component-class org.richfaces.component.html.HtmlPanelMenuGroup
component-family org.richfaces.PanelMenuGroup
renderer-type org.richfaces.PanelMenuGroupRenderer
tag-class org.richfaces.taglib.PanelMenuGroupTag
Example:
...
<rich:panelMenu>
<rich:panelMenuGroup label="Group1">
<!--Nested panelMenu components-->
</rich:panelMenuGroup>
</rich:panelMenu>
...
591
Chapter 6. The RichFaces Comp...
import org.richfaces.component.html.HtmlPanelMenuGroup;
...
HtmlPanelMenuGroup myPanelMenuGroup = new HtmlPanelMenuGroup();
...
All attributes except "label" are optional. The "label" attribute defines text to be represented.
Switching mode could be chosen with the "expandMode" attribute for the concrete panelMenu
group.
• ServerM (default)
• Ajax
• None
"Action" and "actionListener" attributes are ignored. Items don't fire any submits itself. Behavior
is fully defined by the components nested into items.
There are three icon-related attributes. The "iconExpanded" attribute defines an icon for an
expanded state. The "iconCollapsed" attribute defines an icon for a collapsed state. The
"iconDisabled" attribute defines an icon for a disabled state.
Here is an example:
592
Details of Usage
Example:
...
<rich:panelMenu>
<rich:panelMenuGroup label="Group1" iconExpanded="disc" iconCollapsed="chevron">
<!--Nested panelMenu components-->
</rich:panelMenuGroup>
</rich:panelMenu>
...
As the result the pictures are shown below. The first one represents the collapsed state, the
second one - expanded state:
It's also possible to define a path to the icon. Simple code is placed below.
...
<rich:panelMenu>
<rich:panelMenuGroup label="Group1" iconExpanded="\images\img1.png"
iconCollapsed="\images\img2.png">
<!--Nested menu components-->
</rich:panelMenuGroup>
</rich:panelMenu>
...
Information about the "process" attribute usage you can find here.
593
Chapter 6. The RichFaces Comp...
There are two ways to redefine the appearance of all <rich:panelMenuGroup> components
at once:
Table 6.374. Skin parameters redefinition for a table element of the first level
group
Skin parameters CSS properties
headerWeightFont font-weight
generalFamilyFont font-family
headerSizeFont font-size
headerTextColor color
headerBackgroundColor background-color
Table 6.375. Skin parameters redefinition for a table element of second and
next level groups
Skin parameters CSS properties
headerWeightFont font-weight
headerFamilyFont font-family
headerSizeFont font-size
generalTextColor color
tableBorderColor border-top-color
594
Definition of Custom Style Classes
Table 6.376. Skin parameters redefinition for wrapper div element of the first
level group
595
Chapter 6. The RichFaces Comp...
Table 6.380. Classes names that define a second and lower level groups
In order to redefine styles for all <rich:panelMenuGroup> 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-pmenu-disabled-element{
color: #87b9ff;
}
...
This is a result:
596
Relevant resources links
In the example a disabled element font style and color were changed.
Also it's possible to change styles of particular <rich:panelMenuGroup> component. In this case
you should create own style classes and use them in corresponding <rich:panelMenuGroup>
styleClass attributes. An example is placed below:
Example:
...
.myClass{
background-color: #ecf4fe;
}
...
The "hoverClass" attribute for <rich:panelMenuGroup> is defined as it's shown in the example
below:
Example:
This is a result:
Figure 6.222. Redefinition styles with own classes and styleClass attributes
As it could be seen on the picture above, the background color for hovered item was changed.
Some additional information about usage of component can be found here [http://
livedemo.exadel.com/richfaces-demo/richfaces/panelMenu.jsf?c=panelMenuGroup].
597
Chapter 6. The RichFaces Comp...
598
Key Features
599
Chapter 6. The RichFaces Comp...
600
Key Features
601
Chapter 6. The RichFaces Comp...
Name Value
component-type org.richfaces.PanelMenuItem
component-class org.richfaces.component.html.HtmlPanelMenuItem
component-family org.richfaces.PanelMenuItem
renderer-type org.richfaces.PanelMenuItemRenderer
tag-class org.richfaces.taglib.PanelMenuItemTag
Example:
...
<rich:panelMenu>
...
<rich:panelMenuItem value="Item1"/>
...
</rich:panelMenu>
...
import org.richfaces.component.html.HtmlPanelMenuItem;
...
HtmlPanelMenuItem myPanelMenuItem = new HtmlPanelMenuItem();
...
602
Details of Usage
• Server (default)
• Ajax
• None
"Action" and "actionListener" attributes are ignored. Items don't fire any submits itself. Behavior
is fully defined by the components nested into items.
Example:
...
<rich:panelMenu>
...
<rich:panelMenuItem submitMode="none" onclick="document.location.href='http://
labs.jboss.com/jbossrichfaces/">
<h:outputLink value="http://labs.jboss.com/jbossrichfaces/">
<h:outputText value="RichFaces Home Page"></h:outputText>
</h:outputLink>
</rich:panelMenuItem>
...
</rich:panelMenu>
...
There are two icon-related attributes. The "icon" attribute defines an icon. The "iconDisabled"
attribute defines an icon for a disabled item.
603
Chapter 6. The RichFaces Comp...
Here is an example:
Example:
...
<rich:panelMenu>
...
<rich:panelMenuItem ="Item 1.1" icon="chevronUp" />
...
</rich:panelMenu>
...
It's also possible to define a path to the icon. Simple code is placed below.
...
<rich:panelMenu>
...
<rich:panelMenuItem ="Item 1.1" icon="\images\img1.png" />
...
</rich:panelMenu>
...
Information about the "process" attribute usage you can find here.
There are two ways to redefine the appearance of all <rich:panelMenuItem> components at
once:
604
Skin Parameters Redefinition
Table 6.384. Skin parameters redefinition for a table element of the first level
item
On the screenshot there are classes names that define styles for component elements.
605
Chapter 6. The RichFaces Comp...
Table 6.386. Classes names that define the first level items
Table 6.387. Classes names that define the second and lower level items
In order to redefine styles for all <rich:panelMenuItem> 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-pmenu-hovered-element {
background-color: #ff7800;
606
Definition of Custom Style Classes
}
...
This is a result:
Also it's possible to change styles of particular <rich:panelMenuItem> component. In this case
you should create own style classes and use them in corresponding <rich:panelMenuItem>
styleClass attributes. An example is placed below:
Example:
...
.myClass {
color: #a0a0a0;
}
...
The "disabledClass" attribute for <rich:panelMenuItem> is defined as it's shown in the example
below:
Example:
607
Chapter 6. The RichFaces Comp...
This is a result:
Figure 6.229. Redefinition styles with own classes and styleClass attributes
As it could be seen on the picture above, the text color for disabled item was changed.
Some additional information about usage of component can be found here [http://
livedemo.exadel.com/richfaces-demo/richfaces/panelMenu.jsf?c=panelMenuItem].
6.76.1. Description
The <rich:pickList> component is used for moving selected item(s) from one list into another.
• Keyboard support
608
Key Features
609
Chapter 6. The RichFaces Comp...
610
Creating the Component with a Page Tag
Name Value
component-type org.richfaces.PickList
component-class org.richfaces.component.html.HtmlPickList
component-family org.richfaces.PickList
renderer-type org.richfaces.PickListRenderer
tag-class org.richfaces.taglib.PickListTag
Example:
...
<rich:pickList value="#{pickBean.targetValues}">
<f:selectItem itemValue="Bentley" itemLabel="Bentley"/>
<f:selectItems value="#{pickBean.sourceValues}"/>
</rich:pickList>
...
import org.richfaces.component.html.HtmlPickList;
...
HtmlPickList myPickList = new HtmlPickList();
611
Chapter 6. The RichFaces Comp...
...
• 2 item lists. Every item has three different representations: common, selected, active.
Combination of these states is possible.
• Move controls set is a set of controls, which performs moving items between lists.
The <f:selectItem /> or <f:selectItems /> facets are used to define the values of a source list.
Example:
...
<rich:pickList value="#{pickBean.listValues}">
<f:selectItem itemValue="Bentley" itemLabel="Bentley"/>
<f:selectItem itemValue="Audi" itemLabel="Audi"/>
<f:selectItems value="#{pickBean.sourceList}"/>
</rich:pickList>
...
The "switchByClick" attribute provides an option to copy and remove items between lists by one
click. Default value of this attribute is "false", so you need a double click to copy, remove items
from one list to another.
Example:
...
<rich:pickList copyAllControlLabel = "#{pickBean.copyAllLabel}" copyControlLabel =
"#{pickBean.copyLabel}" removeControlLabel = "#{pickBean.removeLabel}"
removeAllControlLabel ="#{pickBean.removeAllLabel}" value="#{pickBean.listValues}">
<f:selectItem itemValue="Bentley" itemLabel="Bentley"/>
<f:selectItem itemValue="Audi" itemLabel="Audi"/>
<f:selectItems value="#{pickBean.sourceList}"/>
</rich:pickList>
...
612
Details of Usage
If you don't want to display labels on the buttons you need to set "showButtonsLabel" to "false".
With the help of "moveControlsVerticalAlign" attribute you can align move controls vertically.
The possible value for "moveControlsVerticalAlign" are "top", "bottom" and "center" (default
value).
The <rich:pickList> component provides resizing of lists by using such attributes as:
Example:
...
<rich:pickList listsHeight="#{pickBean.listsHeight}"
targetListWidth="#{pickBean.targetListWidth}" value="#{pickBean.listValues}">
<f:selectItem itemValue="Bentley" itemLabel="Bentley"/>
<f:selectItem itemValue="Audi" itemLabel="Audi"/>
<f:selectItems value="#{pickBean.sourceList}"/>
</rich:pickList>
...
613
Chapter 6. The RichFaces Comp...
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:pickList> components at once:
614
Skin Parameters Redefinition
Table 6.399. Skin parameters redefinition for a source and target items
615
Chapter 6. The RichFaces Comp...
Table 6.400. Skin parameters redefinition for a source and target cell
Table 6.401. Skin parameters redefinition for a selected source and target
cell
Table 6.402. Skin parameters redefinition for an active source and target cell
Table 6.403. Skin parameters redefinition for a selected source and target
row
The following pictures illustrate how CSS classes define styles for component elements.
616
Definition of Custom Style Classes
Table 6.406. Classes names that define a source and target items
representation
Class name Description
rich-picklist-source-items Defines styles for an item in a source list
rich-picklist-target-items Defines styles for an item in a target list
617
Chapter 6. The RichFaces Comp...
Table 6.409. Classes names that define a selected source and target rows
representation
In order to redefine styles for all <rich:pickList> 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.
618
Definition of Custom Style Classes
Example:
...
.rich-picklist-list{
background-color:#ecf4fe;
}
...
This is a result:
Also it's possible to change styles of particular <rich:pickList> component. In this case you
should create own style classes and use them in the corresponding <rich:pickList> styleClass
attributes. An example is placed below:
Example:
...
.myClass{
font-weight:bold;
}
...
The "styleClass" attribute for <rich:pickList> is defined as it's shown in the example below:
Example:
This is a result:
619
Chapter 6. The RichFaces Comp...
Figure 6.235. Redefinition styles with own classes and styleClass attributes
As it could be seen on the picture above, the font style for buttons is changed.
620
Key Features
621
Chapter 6. The RichFaces Comp...
622
Key Features
Name Value
component-type org.richfaces.ProgressBar
component-class org.richfaces.component.html.HtmlProgressBar
component-family org.richfaces.ProgressBar
623
Chapter 6. The RichFaces Comp...
Name Value
renderer-type org.richfaces.renderkit.ProgressBarRenderer
tag-class org.richfaces.taglib.ProgressBarTag
Example:
...
<rich:progressBar value="#{bean.incValue1}"/>
...
import org.richfaces.component.html.progressBar;
...
HtmlProgressBar myProgressBar = new progressBar();
...
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
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.
Example:
624
Details of Usage
...
<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.
Example:
...
<rich:progressBar value="#{bean.incValue}" minValue="50" maxValue="400"/>
...
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:
625
Chapter 6. The RichFaces Comp...
...
<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> .
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>
...
626
Details of Usage
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>
...
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>
...
627
Chapter 6. The RichFaces Comp...
Information about the "process" attribute usage you can find here.
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
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:
Table 6.415. Skin parameters redefinition for the progressBar without a label
Table 6.416. Skin parameters redefinition for the completed progress area
of the progressBar without a label
Table 6.417. Skin parameters redefinition for the progressBar with a label
628
Definition of Custom Style Classes
Table 6.418. Skin parameters redefinition for the label of the progressBar
Table 6.419. Skin parameters redefinition for the completed progress area
of the progressBar with a label
Table 6.420. Skin parameters redefinition for the remained progress area of
the progressBar with a label
On the screenshot there are classes names that define styles for component elements.
629
Chapter 6. The RichFaces Comp...
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;
}
...
630
Relevant Resources Links
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:
Figure 6.242. 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.78.1. Description
The <rich:scrollableDataTable> component is used for the table-like component creation.
The component just adds the set of additional features described below in comparison with the
standard table.
631
Chapter 6. The RichFaces Comp...
• Dynamically fetching the rows from the server when the table is scrolled up and down
632
Key Features
633
Chapter 6. The RichFaces Comp...
634
Key Features
635
Chapter 6. The RichFaces Comp...
Name Value
component-type org.richfaces.component.ScrollableDataTable
component-class org.richfaces.component.html.HtmlScrollableDataTable
component-family org.richfaces.component.ScrollableDataTable
renderer-type org.richfaces.renderkit.html.ScrollableDataTableRenderer
tag-class org.richfaces.taglib.ScrollableDataTableTag
Example:
...
<rich:scrollableDataTable value="#{dataTableScrollerBean.allCars}" var="category">
<!--...//Set of columns and header/footer facets-->
</rich:scrollableDataTable>
...
636
Details of Usage
import org.richfaces.component.html.HtmlScrollableDataTable;
...
HtmlScrollableDataTable myScrollableDataTable = new HtmlScrollableDataTable();
...
It's possible to select the whole row with onclick on the row or some set of rows. Selection is
optional and availability of such feature is defined on the component. There are two ways to select
a few rows:
• Clicking some row with the SHIFT button hold. In this case all the rows starting from last selected
up to clicked should be selected.
The columns provides the possibility of expanding/collapsing on the client side through the next
JS API:
• collapse(columnId) - Performs the collapse action for the column with the corresponding id
It's possible to sort the table content after clicks on the header. The feature is optional. Every
column should be pointed to the comparator method that is used for sorting the table. In case the
<rich:scrollableDataTable> is already sorted by some column and the header of this column
has been clicked again - the sorting is reversed.
...
<rich:scrollableDataTable value="#{modelBuilder.model}" var="issues"
frozenColCount="1"
first="0"
637
Chapter 6. The RichFaces Comp...
rows="40"
width="300px"
height="396px">
<rich:column width="100px">
<f:facet name="header" >
<h:outputText value="State"/>
</f:facet>
<h:outputText value="#{issues.cell1}"/>
<f:facet name="footer">
<h:outputText value="State"/>
</f:facet>
</rich:column>
<!--...//Set of columns and header/footer facets-->
</rich:scrollableDataTable>
...
The "selection" attribute allows to get the row data when using one and multi-selection rows
mode.
In the following example when you submit the form, current collection of the selected objects is
placed in the object's property. Then on complete action the <rich:modalPanel> with selected
data is shown.
Example:
...
<h:form>
<rich:spacer height="30" />
<rich:scrollableDataTable rowKeyVar="rkv" frozenColCount="1" height="200px"
width="300px" id="carList" rows="40" columnClasses="col"
value="#{dataTableScrollerBean.allCars}" var="category" sortMode="single"
selection="#{dataTableScrollerBean.selection}">
<rich:column id="make">
<f:facet name="header"><h:outputText styleClass="headerText" value="Make"
/></f:facet>
<h:outputText value="#{category.make}" />
</rich:column>
<rich:column id="model">
<f:facet name="header"><h:outputText styleClass="headerText" value="Model"
/></f:facet>
638
Details of Usage
This is a result:
639
Chapter 6. The RichFaces Comp...
The <rich:scrollableDataTable> component has the following extra attributes for event
processing on the client:
• "onselectionchange"
• "oncomplete"
• "onRowClick"
• "onRowDblClick"
• "onRowMouseUp"
• "onRowMouseDown"
Information about the "process" attribute usage you can find here.
640
Skin Parameters Redefinition
There are two ways to redefine the appearance of all <rich:scrollableDataTable> components
at once:
641
Chapter 6. The RichFaces Comp...
642
Definition of Custom Style Classes
Table 6.433. Classes names that define footer and header elements
In order to redefine styles for all <rich:scrollableDataTable> 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-sdt-header-cell{
font-style:italic;
}
...
This is a result:
643
Chapter 6. The RichFaces Comp...
In the example the font style for header cell was changed.
Example:
...
.myClass{
background-color:#ffead9;
}
...
644
Definition of Custom Style Classes
Example:
This is a result:
Figure 6.247. Redefinition styles with own classes and styleClass attributes
As it could be seen on the picture above, background color for selected item was changed.
645
Chapter 6. The RichFaces Comp...
646
Creating the Component with a Page Tag
Name Value
component-type org.richfaces.separator
component-class org.richfaces.component.html.HtmlSeparator
component-family org.richfaces.separator
renderer-type org.richfaces.SeparatorRenderer
tag-class org.richfaces.taglib.SeparatorTag
647
Chapter 6. The RichFaces Comp...
Example:
...
<rich:separator/>
...
import org.richfaces.component.html.HtmlSeparator;
...
HtmlSeparator mySeparator = new HtmlSeparator();
...
The line type can be customized with the "lineType" parameter. For example, different
line types are shown after rendering with the following initial settings lineType="double"and
lineType="solid".
648
Look-and-Feel Customization
• "onmouseover"
• "onclick"
• "onmouseout"
• etc.
For skinnability implementation, the components use a style class redefinition method.
To redefine the appearance of all <rich:separator> components at once, you should add to your
style sheets the style class used by a <rich:separator> component.
In order to redefine styles for all <rich:separator> 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-separator{
background-color:#ff7700;
}
...
This is a result:
649
Chapter 6. The RichFaces Comp...
Also it's possible to change styles of particular <rich:separator> component. In this case you
should create own style classes and use them in corresponding <rich:separator> styleClass
attributes. An example is placed below:
Example:
...
.myClass{
background-color:#ffead9;
}
...
The "styleClass" attribute for <rich:separator> is defined as it's shown in the example below:
Example:
This is a result:
Figure 6.251. Redefinition styles with own classes and styleClass attributes
As it could be seen on the picture above,background color for separator was changed.
6.80.1. Description
650
Key Features
• Server
• Client
• Ajax
651
Chapter 6. The RichFaces Comp...
652
Key Features
653
Chapter 6. The RichFaces Comp...
Name Value
component-type org.richfaces.SimpleTogglePanel
component-class org.richfaces.component.html.HtmlSimpleTogglePanel
component-family org.richfaces.SimpleTogglePanel
renderer-type org.richfaces.SimpleTogglePanelRenderer
tag-class org.richfaces.taglib.SimpleTogglePanelTag
Example:
654
Creating the Component Dynamically Using
Java
...
<rich:simpleTogglePanel>
...
</rich:simpleTogglePanel>
...
import org.richfaces.component.html.HtmlSimpleTogglePanel;
...
HtmlSimpleTogglePanel myPanel = new HtmlSimpleTogglePanel();
...
Switching mode could be defined with the "switchType" attribute with three possible parameters.
• Server (DEFAULT)
• Ajax
AJAX form submission is performed around the panel, content of the called panel is uploaded
on Ajax request and additionally specified elements in the "reRender" attribute are rendered.
Only one at a time panel is uploaded on the client side.
• Client
All panels are uploaded on the client side. Switching from the active to the hidden panel is
performed with client JavaScript.
• "onmouseover "
655
Chapter 6. The RichFaces Comp...
• "onclick "
• "onmouseout "
• etc.
Information about the "process" attribute usage you can find here.
There are two ways to redefine the appearance of all <rich:simpleTooglePanel> components
at once:
656
Definition of Custom Style Classes
On the screenshot there are classes names that define styles for component elements.
657
Chapter 6. The RichFaces Comp...
In order to redefine styles for all <rich:simpleTogglePanel> 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-stglpanel-header{
font-style:italic;
}
...
This is a result:
658
Relevant Resources Links
Example:
...
.myClass{
background-color:#ffead9;
}
...
The "bodyClass" attribute for <rich:simpleTogglePanel> is defined as it's shown in the example
below:
Example:
This is a result:
Figure 6.256. Redefinition styles with own classes and styleClass attributes
As it could be seen on the picture above,background color for body was changed.
Here [http://livedemo.exadel.com/richfaces-demo/richfaces/
simpleTogglePanel.jsf?c=simpleTogglePanel] you can see the example of
<rich:simpleTogglePanel> usage and sources for the given example.
6.81.1. Description
659
Chapter 6. The RichFaces Comp...
660
Creating the Component with a Page Tag
Name Value
component-type org.richfaces.spacer
component-class org.richfaces.component.html.HtmlSpacer
component-family org.richfaces.spacer
renderer-type org.richfaces.SpacerRenderer
tag-class org.richfaces.taglib.SpacerTag
Example:
...
<rich:spacer/>
...
import org.richfaces.component.html.HtmlSpacer;
661
Chapter 6. The RichFaces Comp...
...
HtmlSpacer mySpacer = new HtmlSpacer();
...
<rich:spacer> is a simple layout component which represents a transparent spacer. Thus, the
main attributes that define its style are "style" and "styleClass".
In addition, the attributes are responsible for the component size: "width" and "height".
Moreover, to add e.g. some JavaScript effects, events defined on it are used.
• "onmouseover "
• "onclick "
• "onmouseout "
• etc.
On the component generation, the framework presents a default rich-spacer class in "styleClass"
of a generated component, i.e. in order to redefine appearance of all spacers at once, it's
necessary to redefine this class in your own CSS (replacing in the result properties defined in a
skin with your own).
To define appearance of the particular spacer, it's possible to write your own CSS classes and
properties in the component style attributes ( "style", "styleClass" ) modifying component property.
6.82.1. Description
The component adds on-keypress suggestions capabilities to any input text component (like
<h:inputText> ). When a key is pressed in the field Ajax request is sent to the server. When the
suggestion action returns a list of possible values, it pop ups them inside the <div> element
bellow the input.
662
Key Features
• Performs suggestion via Ajax requests without any line of JavaScript code written by you
• Setting rules that appear between cells within a table of popup values
• "Event queue" and "request delay" attributes present to divide frequently requests
663
Chapter 6. The RichFaces Comp...
664
Key Features
665
Chapter 6. The RichFaces Comp...
666
Key Features
667
Chapter 6. The RichFaces Comp...
668
Creating the Component with a Page Tag
Name Value
component-type org.richfaces.SuggestionBox
component-class org.richfaces.component.html.HtmlSuggestionBox
component-family org.richfaces.SuggestionBox
renderer-type org.richfaces.SuggestionBoxRenderer
tag-class org.richfaces.taglib.SuggestionBoxTag
Example:
...
<h:inputText value="#{bean.property}" id="suggest"/>
<rich:suggestionbox for="suggest" suggestionAction="#{bean.autocomplete}"
var="suggest">
<h:column>
<h:outputText value="#{suggest.text}"/>
</h:column>
</rich:suggestionbBox>
...
Here is the bean.autocomplete method that returns the collection to pop up:
Example:
669
Chapter 6. The RichFaces Comp...
import org.richfaces.component.html.HtmlSuggestionBox;
...
HtmlSuggestionBox myList = new HtmlSuggestionBox();
...
• "for"
The attribute where there is an input component which activation causes a suggestion activation
• "suggestionAction"
• "var"
a collection name that provides access for inputting into a table in a popup
There are also two size attributes ( "width" and "height" ) that are obligatory for the suggestion
component. The attributes have initial Defaults but should be specified manually in order to be
changed.
The suggestionBox component, as it is shown on the screenshot, could get any collection for an
output and outputs it in a ToolTip window the same as a custom dataTable (in several columns)
...
<rich:suggestionbox for="test" suggestionAction="#{bean.autocomplete}" var="cit"
fetchValue="#{cit.text}">
<h:column>
<h:outputText value="#{cit.label}"/>
</h:column>
<h:column>
<h:outputText value="#{cit.text}"/>
</h:column>
</rich:suggestionbox>
...
670
Details of Usage
When some string is chosen input receives the corresponding value from the second column
containing #{cit.text}
There is also one more important attribute named "tokens" that specifies separators after which
a set of some characters sequence is defined as a new prefix beginning from this separator and
not from the string beginning.
Example:
...
<rich:suggestionbox for="test" suggestionAction="#{bean.autocomplete}" var="cit"
selfRendered="true" tokens=",">
<h:column>
<h:outputText value="#{cit.text}"/>
</h:column>
</rich:suggestionbox>
...
This example shows that when a city is chosen and a comma and first letter character are input,
Ajax request is called again, but it submits a value starting from the last token:
671
Chapter 6. The RichFaces Comp...
For a multiple definition use either ",.; " syntax as a value for tokens or link a parameter to some
bean property transmitting separators collection.
The component also encompasses "layout" and "style" attributes corresponding to dataTable
ones for a table appearing in popup (for additional information, read JSF Reference) and custom
attribute managing AJAX requests sending (for additional information, see Ajax4JSF Project [http:/
/www.jboss.org/projects/jbossajax4jsf]).
In addition to these attributes common for Ajax action components and limiting requests quantity
and frequency, suggestionBox has one more its own attribute limiting requests (the "minChars"
attribute). The attribute defines characters quantity inputted into a field after which Ajax requests
are called to perform suggestion.
There is possibility to define what be shown if the autocomplete returns empty list. Attribute
"nothingLabel" or facet with the same name could be used for it.
Example:
...
<rich:suggestionbox nothingLabel="Empty" for="test"
suggestionAction="#{bean.autocomplete}" var="cit">
<h:column>
<h:outputText value="#{cit.text}"/>
</h:column>
</rich:suggestionbox>
...
Example:
...
<rich:suggestionbox for="test" suggestionAction="#{bean.autocomplete}" var="cit">
<f:facet name="nothingLabel">
<h:outputText value="Empty"/>
</f:facet>
<h:column>
<h:outputText value="#{cit.text}"/>
</h:column>
</rich:suggestionbox>
...
672
JavaScript API
Example:
...
<rich:suggestionbox for="test" suggestionAction="#{bean.autocomplete}" var="cit"
usingSuggestObjects="true">
<h:column>
<h:outputText value="#{cit.text}"/>
</h:column>
</rich:suggestionbox>
...
Information about the "process" attribute usage you can find here.
Function Description
callSuggestion() Calls the suggestion. If the "ignoreMinChars"
value is "true" then the number of symbols
to send a query is no longer actual for
callSuggestion()
getSelectedItems() Returns the array of objects
673
Chapter 6. The RichFaces Comp...
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:suggestionBox> components at
once:
Table 6.451. Skin parameters redefinition for shadow element of the list
674
Definition of Custom Style Classes
In order to redefine styles for all <rich:suggestionBox> 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:
675
Chapter 6. The RichFaces Comp...
...
.rich-sb-int{
font-weight:bold;
}
...
This is a result:
Also it's possible to change styles of particular <rich:suggestionBox> component. In this case
you should create own style classes and use them in corresponding <rich:suggestionBox>
styleClass attributes. An example is placed below:
Example:
...
.myClass{
background-color:#f0ddcd;
}
...
The "selectedClass" attribute for <rich:suggestionBox> is defined as it's shown in the example
below:
Example:
This is a result:
676
Relevant Resources Links
Figure 6.264. Redefinition styles with own classes and styleClass attributes
As it could be seen on the picture above,background color for selected item was changed.
Here [http://livedemo.exadel.com/richfaces-demo/richfaces/suggestionBox.jsf?c=suggestionBox]
you can see the example of <rich:suggestionBox> usage and sources for the given example.
677
Chapter 6. The RichFaces Comp...
• Customizable headers
• Each tab has a unique name for direct access (e.g. for switching between tabs)
• Server
• Client
• AJAX
• Switch methods can be selected for the whole tab panel and for the each tab separately
678
Key Features
679
Chapter 6. The RichFaces Comp...
Name Value
component-type org.richfaces.tabPanel
component-class org.richfaces.component.html.HtmltabPanel
component-family org.richfaces.tabPanel
renderer-type org.richfaces.tabPanelRenderer
tag-class org.richfaces.taglib.tabPanelTag
Example:
680
Creating the Component Dynamically Using
Java
...
<rich:tabPanel>
<!--//Set of Tabs inside-->
<rich:tab>
...
</rich:tab>
</rich:tabPanel>
...
Example:
import org.richfaces.component.html.HtmltabPanel;
...
HtmltabPanel mytabPanel = new HtmltabPanel();
...
As it was mentioned above, tabPanel groups content on panels and performs switching from one
to another. Hence, modes of switching between panels are described first of all.
Note:
Switching mode could be chosen with the tabPanel attribute "mode" with three possible
parameters.
• Server (DEFAULT)
The common submission is performed around tabPanel and a page is completely rendered on
a called panel. Only one at a time tabPanel is uploaded onto the client side.
• Ajax
681
Chapter 6. The RichFaces Comp...
AJAX form submission is performed around the tabPanel, content of the called tabPanel is
uploaded on Ajax request and additionally specified elements in the "reRender" attribute are
rendered. Only one at a time tabPanel is uploaded on the client.
• Client
All tabPanels are uploaded on the client side. The switching from the active to the hidden panel
is performed with client JavaScript.
As a result, the tabPanel is switched to the second tab according to the action returning outcome
for moving onto another page and switching from the second to the first tab is performed.
There is also the "selectedTab" attribute. The attribute keeps an active tab name; therefore, an
active tabPanel could be changed with setting a name of the necessary tab to this attribute.
There is also the "headerAlignment" attribute responsible for rendering of tabPanel components.
The attribute has several values: "left" (Default), "right", "center", which specify Tabs components
location on the top of the tabPanel.
Example:
...
<rich:tabPanel width="40%" headerAlignment="right">
<rich:tab label="Canon">
...
</rich:tab>
<rich:tab label="Nikon">
...
</rich:tab>
<rich:tab label="Olympus">
...
</rich:tab>
</rich:tabPanel>
...
682
Look-and-Feel Customization
The "label" attribute is a generic attribute. The "label" attribute provides an association between
a component, and the message that the component (indirectly) produced. This attribute defines
the parameters of localized error and informational messages that occur as a result of conversion,
validation, or other application actions during the request processing lifecycle. With the help of
this attribute you can replace the last parameter substitution token shown in the messages. For
example, {1} for "DoubleRangeValidator.MAXIMUM", {2} for "ShortConverter.SHORT".
Except the specific attributes, the component has all necessary attributes for JavaScript events
definition.
• "onmouseover"
• "onmouseout"
• etc.
There are two ways to redefine the appearance of all <rich:tabPanel> components at once:
683
Chapter 6. The RichFaces Comp...
On the screenshot there are classes names that define styles for component elements.
684
Definition of Custom Style Classes
Table 6.460. Classes names that define different tab header states
(corresponds to rich-tabhdr-side-cell)
In order to redefine styles for all <rich:tabPanel> components on a page using CSS, it's enough
to create classes with the same names (possible classes could be found in the table above) and
define necessary properties in them. An example is placed below:
Example:
...
.rich-tabhdr-cell-active{
font-weight: bold;
}
...
This is a result:
685
Chapter 6. The RichFaces Comp...
In the example a tab active font weight and text color were changed.
Also it's possible to change styles of particular <rich:tabPanel> component. In this case you
should create own style classes and use them in corresponding <rich:tabPanel> styleClass
attributes. An example is placed below:
Example:
...
.myClass{
font-style: italic;
}
...
The "styleClass" attribute for <rich:tabPanel> is defined as it's shown in the example below:
Example:
This is a result:
686
Relevant Resources Links
Figure 6.269. Redefinition styles with own classes and styleClass attributes
As it could be seen on the picture above, font style on inactive tab was changed.
687
Chapter 6. The RichFaces Comp...
• Each tab has a unique name for a direct access (e.g. for switching between tabs)
• Switch methods can be easily customized for every tab separately with attribute to:
• Server
• Client
• AJAX
688
Key Features
689
Chapter 6. The RichFaces Comp...
690
Creating the Component with a Page Tag
Example:
691
Chapter 6. The RichFaces Comp...
...
<rich:tabPanel>
<!--Set of Tabs inside-->
<rich:tab>
...
</rich:tab>
</rich:tabPanel>
...
Example:
import org.richfaces.component.html.HtmlTab;
...
HtmlTab myTab = new HtmlTab();
...
The main component function is to define a content group that is rendered and processed when
the tab is active, i.e. click on a tab causes switching onto a tab containing content corresponded
to this tab.
The "label" attribute defines text to be represented. If you can use the "label" facet, you can
even not use the "label" attribute.
Example:
...
<rich:tab>
<f:facet name="label">
<h:graphicImage value="/images/img1.png"/>
</f:facet>
...
<!--Any Content inside-->
...
</rich:tab>
...
692
Details of Usage
A marker on a tab header defined with the "label" attribute. Moreover, each tab could be disabled
(switching on this tab is impossible) with the "disable" attribute.
Example:
...
<rich:tabPanel width="20%">
<tabs:tab label="Canon">
<h:outputText value="Canon EOS Digital Rebel XT" />
...
</tabs:tab>
<tabs:tab label="Nikon">
<h:outputText value="Nikon D70s" />
...
</tabs:tab>
<tabs:tab label="Olympus">
<h:outputText value="Olympus EVOLT E-500" />
...
</tabs:tab>
<tabs:tab disabled="true" name="disabled" label="Disabled"/>
</rich:tabPanel>
...
With this example it's possible to generate the tab panel with the last disabled and three active
tabs (see the picture).
693
Chapter 6. The RichFaces Comp...
Switching mode could be defined not only for the whole panel tab, but also for each particular tab,
i.e. switching onto one tab could be performed right on the client with the corresponding JavaScript
and onto another tab with an Ajax request on the server. Tab switching modes are the same as
tabPanel ones.
Each tab also has an attribute name (alias for "id" attribute). Using this attribute value it's possible
e.g. to set an active tab on a model level specifying this name in the corresponding attribute of
the whole tab.
Except the specific component attributes it has all necessary attributes for JavaScript event
definition.
• "onmouseover"
• "onmouseout"
• etc.
Some event could be performed on the tab which has been entered/left using "ontabenter" /
"ontableave" attributes. See the example below.
Example:
...
<rich:tabPanel>
<rich:tab label="Tab1" ontabenter="alert()">
694
Look-and-Feel Customization
...
</rich:tab>
...
</rich:tabPanel>
...
The following example shows how on the client side to get the names of entered/left tabs.
ontabenter="alert(leftTabName)"
Information about the "process" attribute usage you can find here.
Note:
A panel appearance and content is defined with a tab panel i.e. on the tab level it's
possible to define only an appearance of this tab header.
There are two ways to redefine the appearance of all <rich:tab> components at once:
695
Chapter 6. The RichFaces Comp...
696
Definition of Custom Style Classes
In order to redefine styles for all <rich:tab> 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-tab-header{
font-weight: bold;
}
...
This is a result:
697
Chapter 6. The RichFaces Comp...
Also it's possible to change styles of particular <rich:tab> component. In this case you should
create own style classes and use them in corresponding <rich:tab> styleClass attributes. An
example is placed below:
Example:
...
.myClass{
border-color: #5d9ffc;
}
...
The "styleClass" attribute for <rich:tab> is defined as it's shown in the example below:
Example:
This is a result:
698
< rich:togglePanel >
Figure 6.274. Redefinition styles with own classes and styleClass attributes
As it could be seen on the picture above, the border color was changed.
6.85.1. Description
A wrapper component with named facets, where every facet is shown after activation of the
corresponding toggleControl (the other is hidden).
699
Chapter 6. The RichFaces Comp...
• Server
• Client
• Ajax
700
Key Features
701
Chapter 6. The RichFaces Comp...
Example:
...
<rich:togglePanel>
<f:facet name="first">
...
</f:facet>
<f:facet name="second">
...
</f:facet>
...
</rich:togglePanel>
702
Creating the Component Dynamically Using
Java
...
<!--//Set of the toggleControls somewhere on a page.-->
...
import org.richfaces.component.html.HtmltogglePanel;
...
HtmltogglePanel myPanel = new HtmltogglePanel();
...
The initial component state is defined with "initialState" attribute, where a facet name that is
shown at first is defined.
Note:
It's also possible to define an "empty" facet to implement the functionality as
drop-down panels have and make the facet active when no content is required to
be rendered.
Switching mode could be defined with the "switchType" attribute with three possible parameters:
• Server (DEFAULT)
The common submission is performed around togglePanel and a page is completely rendered
on a called panel. Only one at a time the panel is uploaded onto the client side.
• Ajax
AJAX form submission is performed around the panel, content of the called panel is uploaded on
an Ajax request and additionally specified elements in the "reRender" attribute are rendered.
Only one at a time the panel is uploaded on the client side.
• Client
All panels are uploaded on the client side. The switching from the active to the hidden panel
is performed with client JavaScript.
703
Chapter 6. The RichFaces Comp...
Example:
...
<rich:togglePanel id="panel" initialState="panelB" switchType="client"
stateOrder="panelA,panelB,panelC">
<f:facet name="panelA">
...
</f:facet>
<f:facet name="panelB">
...
</f:facet>
<f:facet name="panelC">
...
</f:facet>
</rich:togglePanel>
<rich:toggleControl for="panel" value="Switch"/>
...
The example shows a togglePanel initial state when the second facet (panelB) is rendered and
successive switching from the first to the second happens.
The "label" attribute is a generic attribute. The "label" attribute provides an association between
a component, and the message that the component (indirectly) produced. This attribute defines
the parameters of localized error and informational messages that occur as a result of conversion,
validation, or other application actions during the request processing lifecycle. With the help of
this attribute you can replace the last parameter substitution token shown in the messages. For
example, {1} for "DoubleRangeValidator.MAXIMUM", {2} for "ShortConverter.SHORT".
704
Definition of Custom Style Classes
In order to redefine styles for all <rich:togglePanel> 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-toggle-panel{
font-style:italic;
}
...
This is a result:
In the example the font style for output text was changed.
Also it's possible to change styles of particular <rich:togglePanel> component. In this case you
should create own style classes and use them in corresponding <rich:togglePanel> styleClass
attributes. An example is placed below:
Example:
...
.myClass{
705
Chapter 6. The RichFaces Comp...
background-color:#bed6f8;
}
...
The "styleClass" attribute for <rich:togglePanel> is defined as it's shown in the example below:
Example:
This is a result:
As it could be seen on the picture above, background color for panel was changed.
6.86.1. Description
A link type control for switching between togglePanel facets. Target Panel is specified with
"for" attribute. It can be located inside or outside the togglePanel. As the result of switching
706
Key Features
between facets previous facet is hidden and another one (specified with "switchToState" or panel
"stateOrder" attributes) is shown.
• Server
• Client
• Ajax
707
Chapter 6. The RichFaces Comp...
708
Key Features
709
Chapter 6. The RichFaces Comp...
Name Value
component-type org.richfaces.ToggleControl
710
Creating the Component with a Page Tag
Name Value
component-class org.richfaces.component.html.HtmlToggleControl
component-family org.richfaces.ToggleControl
renderer-type org.richfaces.ToggleControlRenderer
tag-class org.richfaces.taglib.ToggleControlTag
Example:
...
<rich:toggleControl for="panel"/>
...
<rich:togglePanel id="panel" stateOrder="[facets order to be switched]">
<!--//Set of Facets-->
</rich:togglePanel>
...
import org.richfaces.component.html.HtmlToggleControl;
...
HtmlToggleControl myControl = new HtmlToggleControl();
...
The togglePanel could be also switched from the side of the control instead of being strictly defined
in "switchOrder" attribute of <rich:togglePanel>.
Example:
...
711
Chapter 6. The RichFaces Comp...
In this example the switching is performed on facets specified in the "switchToState" attribute.
Information about the "process" attribute usage you can find here.
To redefine the appearance of all <rich:toggleControl> components at once, you should add
to your style sheets style class used by a <rich:toggleControl> component.
In order to redefine styles for all <rich:toggleControl> 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.
712
Definition of Custom Style Classes
Example:
...
.rich-tglctrl {
font-family: monospace;
}
...
This is a result:
Also it's possible to change styles of particular <rich:toggleControl> component. In this case
you should create own style classes and use them in corresponding <rich:toggleControl>
styleClass attributes. An example is placed below:
Example:
...
.myClass {
font-style: italic;
}
...
The "styleClass" attribute for <rich:toggleControl> is defined as it's shown in the example
below:
Example:
This is a result:
Figure 6.280. Redefinition styles with own classes and styleClass attributes
As it could be seen on the picture above, the font style was changed.
713
Chapter 6. The RichFaces Comp...
• Standard top menu bar that can be used in accordance with a menu component
• Easily place content on any side of a menu bar using predefined group layout
714
Key Features
715
Chapter 6. The RichFaces Comp...
Name Value
component-type org.richfaces.ToolBar
component-class org.richfaces.component.html.HtmlToolBar
component-family org.richfaces.ToolBar
renderer-type org.richfaces.ToolBarRenderer
tag-class org.richfaces.taglib.ToolBarTag
Example:
...
<rich:toolBar>
<!--//...Set of action or other JSF components-->
</rich:toolBar>
...
Example:
import org.richfaces.component.html.HtmlToolBar;
...
HtmlToolBar myToolBar = new HtmlToolBar();
...
716
Details of Usage
Grouping and an input side definition is described for toolBarGroup that defines this functionality.
Separators are located between components with the help of the "itemSeparator" attribute with
four predefined values:
• "none"
• "line"
• "square"
• "disc"
For example, when setting a separator of a disc type, the following result is produced:
Moreover, for toolBar style "width" and "height" attributes are placed above all.
Example:
...
<f:facet name="itemSeparator">
<rich:separator width="2" height="14" />
</f:facet>
...
Custom separator can be also specified by URL to the separator image in the attribute
"itemSeparator" of the <rich:toolBar> .
717
Chapter 6. The RichFaces Comp...
Example:
...
<rich:toolBar id="toolBar" width="#{bean.width}" height="#{bean.height}" itemSeparator="/
images/separator_img.jpg"/>
...
This is a result:
As it could be seen in the picture above, the image for itemSeparator was changed.
There are two ways to redefine the appearance of all <rich:toolBar> components at once:
718
Definition of Custom Style Classes
In order to redefine styles for all <rich:toolBar> 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-toolbar-item{
font-weight:bold;
}
...
This is a result:
Also it's possible to change styles of particular <rich:toolBar> component. In this case you
should create own style classes and use them in corresponding <rich:toolBar> styleClass
attributes. An example is placed below:
Example:
...
.myClass{
font-style:italic;
719
Chapter 6. The RichFaces Comp...
font-weight:bold;
}
...
The "styleClass" attribute for <rich:toolBar> is defined as it's shown in the example below:
Example:
This is a result:
Figure 6.286. Redefinition styles with own classes and styleClass attributes
As it could be seen on the picture above,the font style and the font weight for items was changed.
The component also has the standard attributes "style" and "styleClass" that could redefine an
appearance of a particular component variants.
720
Key Features
• Easily place content on either side of tool bar using a predefined group layout
721
Chapter 6. The RichFaces Comp...
Name Value
component-type org.richfaces.ToolBarGroup
component-class org.richfaces.component.html.HtmlToolBarGroup
component-family org.richfaces.ToolBarGroup
renderer-type org.richfaces.ToolBarGroupRenderer
tag-class org.richfaces.taglib.ToolBarGroupTag
Example:
722
Creating the Component Dynamically Using
Java
...
<rich:toolBar>
...
<rich:toolBarGroup>
<!--...Set of action or other JSF components-->
</rich:toolBarGroup>
<rich:toolBarGroup>
<!--...Set of action or other JSF components-->
</rich:toolBarGroup>
...
</rich:toolBar>
...
import org.richfaces.component.html.HtmlToolBarGroup;
...
HtmlToolBarGroup myToolBarGroup = new HtmlToolBarGroup();
...
Separators are located between components with the help of the "itemSeparator" attribute with
four predefined values:
• "none"
• "line"
• "square"
• "disc"
To control the group location inside, use the "location" attribute with "left" (DEFAULT) and "right"
values.
Example:
723
Chapter 6. The RichFaces Comp...
...
<rich:toolBar itemSeparator="disc" width="500">
<rich:toolBarGroup itemSeparator="line">
<h:commandLink value="Command 1.1"/>
<h:commandLink value="Command 2.1"/>
</rich:toolBarGroup>
<rich:toolBarGroup itemSeparator="line" location="right">
<h:commandLink value="Command 1.2"/>
<h:commandLink value="Command 2.2"/>
</rich:toolBarGroup>
</rich:toolBar>
...
There are two ways to redefine the appearance of all <rich:toolBarGroup> components at once:
Example:
...
.myClass{
font-style: italic;
}
724
Relevant resources links
...
The "styleClass" attribute for <rich:toolBarGroup> is defined as it's shown in the example
below:
Example:
This is a result:
As it could be seen on the picture above,font style for first toolBarGroup was changed.
• Disablement support
725
Chapter 6. The RichFaces Comp...
726
Key Features
727
Chapter 6. The RichFaces Comp...
Name Value
component-type org.richfaces.component.toolTip
component-class org.richfaces.component.html.HtmltoolTip
component-family org.richfaces.component.toolTip
renderer-type org.richfaces.renderkit.html.toolTipRenderer
tag-class org.richfaces.taglib.HtmltoolTipTag
To create the simplest variant of <rich:toolTip> component on a page, use the following syntax:
Example:
...
<rich:panel>
<rich:toolTip value="toolTip content"/>
</rich:panel>
...
728
Creating the Component Dynamically Using
Java
6.89.4. Creating the Component Dynamically Using Java
Example:
import org.richfaces.component.html.HtmltoolTip;
...
HtmltoolTip mytoolTip = new HtmltoolTip();
...
There are three ways to attach a <rich:toolTip> to a page element. One of them uses nesting
(this way is shown on example above). In such cases <rich:toolTip> is attached to the parent
component by default.
Note:
Note:
<rich:toolTip> may be attached to a page element by the use of "for" attribute. In this case a
<rich:toolTip> may be defined separately from a page element it is applied to. "id" for page
element is necessary (see the example below).
Example:
...
<rich:panel id="panelId">
...
</rich:panel>
<rich:toolTip value="This is a tooltip content" for="panelId"/>
729
Chapter 6. The RichFaces Comp...
...
Because HTML elements are not presented in components tree built by facelets, use the attribute
"for" with HTML elements as shown in example below.
Example:
...
<div id="elementId">
<rich:toolTip for="elementId">Using a toolTip</rich:toolTip>
<p>The first simple example</p>
</div>
...
<div id="elementId">
<p>The second simple example</p>
</div>
<rich:toolTip for="elementId">Using a toolTip</rich:toolTip>
...
<rich:toolTip> may also be invoked by JS API function. List of JS API functions available
for <rich:toolTip> is listed below. JS API functions are defined for a page element, the
<rich:toolTip> is applied to. Thus, <rich:toolTip> can be defined separately from that page
element. It is necessary to specify "ids" for both and set <rich:toolTip> "attached" attribute's
value to "false" (see the example below).
...
<rich:panel id="paneld" onclick="#{rich:component("tooltipId")}.show();">
...
</rich:panel>
<rich:toolTip id="tooltipId" attached="false" value="This is a tooltip content"/>
...
The "mode" attribute is provided you to control the way of data loading to <rich:toolTip> . The
component works properly in client and Ajax modes. In client mode <rich:toolTip> content is
rendered once on the server and could be rerendered only via external submit. In Ajax mode
<rich:toolTip> content is requested from server for every activation. For Ajax mode there is
possibility to define a facet "defaultContent" , which provides default <rich:toolTip> content to
be displayed, while main content is loading into the <rich:toolTip> (see the example below).
Example:
730
Details of Usage
...
<h:commandLink value="Simple Link" id="link">
<rich:toolTip followMouse="true" direction="top-right" mode="ajax"
value="#{bean.toolTipContent}" horizontalOffset="5"
verticalOffset="5" layout="block">
<f:facet name="defaultContent">
<f:verbatim>DEFAULT TOOLTIP CONTENT</f:verbatim>
</f:facet>
</rich:toolTip>
</h:commandLink>
...
<rich:toolTip> appears attached to the corner dependent on the "direction" attribute. By default
it is positioned bottom-right. <rich:toolTip> activation occurs after an event, defined on the
parent component, takes into consideration the "delay" attribute or after calling JS API function
show(). "hideEvent" attribute defines the way how <rich:toolTip> disappears. It default value
is "none", so the <rich:toolTip> does not disappears. Deactivation may be set for example on
mouseout event on the parent component (excepting the situation when the mouse is hovered
onto the <rich:toolTip> itself) or after calling JS API function hide().
By default, <rich:toolTip> appears smart positioned. But as you can see from the previous
example, you can define an appearance direction via the corresponding attribute "direction" . And
also it's possible to define vertical and horizontal offsets relatively to a mouse position.
Disabled <rich:toolTip> is rendered to a page as usual but JS that responds for its activation
is disabled until enable() is called.
Moreover, to add some JavaScript effects, client events defined on it are used:
731
Chapter 6. The RichFaces Comp...
Standart:
• "onclick"
• "ondblclick"
• "onmouseout"
• "onmousemove"
• "onmouseover"
Special:
• "onshow" - Called after the tooltip is called (some element hovered) but before its request
Function Description
show() Shows the corresponding toolTip
hide() Hides the corresponding toolTip
enable() Enables the corresponding toolTip
disable() Disables the corresponding toolTip
There are two ways to redefine the appearance of all <rich:toolTip> components at once:
732
Definition of Custom Style Classes
In order to redefine styles for all <rich:toolTipl> components on a page using CSS, it's enough
to create classes with the same names (possible classes could be found in the table above) and
define necessary properties in them. An example is placed below:
Example:
...
.rich-tool-tip{
background-color: #eef2f8;
border-color: #7196c8;
}
...
This is a result:
In the example a tool tip background color, border color and font style were changed.
Also it's possible to change styles of particular <rich:toolTipl> component. In this case you
should create own style classes and use them in corresponding <rich:toolTip> styleClass
attributes. An example is placed below:
733
Chapter 6. The RichFaces Comp...
Example:
...
.myClass{
font-style: italic;
}
...
The "styleClass" attribute for <rich:toolTip> is defined as it's shown in the example below:
Example:
This is a result:
Figure 6.294. Redefinition styles with own classes and styleClass attributes
As it could be seen on the picture above, background color and border color of tool tip were
changed.
6.90.1. Description
The component is designed for hierarchical data presentation and is applied for building a tree
structure with a drag-and-drop capability.
734
Key Features
• Built-in drag and drop capability, than enable relocating tree nodes within the tree
735
Chapter 6. The RichFaces Comp...
736
Key Features
737
Chapter 6. The RichFaces Comp...
738
Key Features
739
Chapter 6. The RichFaces Comp...
Name Value
component-type org.richfaces.Tree
component-class org.richfaces.component.html.HtmlTree
740
Creating the Component with a Page Tag
Name Value
component-family org.richfaces.Tree
renderer-type org.richfaces.TreeRenderer
tag-class org.richfaces.taglib.TreeTag
Example:
...
<rich:tree>
<rich:recursiveTreeNodesAdaptor roots="#{fileSystemBean.sourceRoots}" var="item"
nodes="#{item.nodes}" />
</rich:tree>
...
The second way requires defining some attributes, as it's shown in the example:
Example:
...
<rich:tree value="#{library.data}" var="item" >
<rich:treeNode icon="/images/tree/singer.png" >
<h:outputText value="#{item.name}" />
</rich:treeNode>
...
</rich:tree>
...
import org.richfaces.component.html.HtmlTree;
...
HtmlTree myTree = new HtmlTree();
...
741
Chapter 6. The RichFaces Comp...
You can develop and use your own pattern of the "TreeNode" interface or use
a default implementation, which is defined with a default class "TreeNodeImpl"
(org.richfaces.model.TreeNodeImpl [http://labs.jboss.com/file-access/default/members/
jbossrichfaces/freezone/docs/apidoc_framework/org/richfaces/model/TreeNodeImpl.html]).
It's possible to define a visual representation of a node data model (to define a node icon) and
its behavior in correspondence with the data contained in this node (with a value of the "var"
attribute). The node behavior is defined by the components nested into the <rich:treeNode>
(e.g. links or buttons). For these purposes you should use "nodeFace" attribute. For each tree
node a value of "nodeFace" attribute is evaluated and <rich:treeNode> with a value of "type"
attribute equal to a value of "nodeFace" is used for node representation. See an example below.
Example:
...
<h:form>
<rich:tree style="width:300px" value="#{library.data}" var="item" nodeFace="#{item.type}">
<rich:treeNode type="artist" iconLeaf="/images/tree/singer.png" icon="/images/tree/
singer.png">
<h:outputText value="#{item.name}" />
</rich:treeNode>
742
Details of Usage
This is a result:
In the example above, when each node of data model is processed, data contained in the "data"
property of "TreeNode" interface is assigned to a request scope variable, which name is defined
with "var" attribute. The value of the "nodeFace" attribute is evaluated in correspondence with
the data assigned to the "var" attribute. The corresponding <rich:treeNode> component (with
a value of "type" attribute equal to a value of "nodeFace" ) is used for the node representation.
For example, during data model processing, an object with a name "Chris Rea" was inserted in
the "var" attribute. Then the value of "nodeFace" attribute was evaluated as "artist". Thus,
for the node representation the <rich:treeNode> with "type" equal to "artist" was used.
You can also assign an EL-expression as value of the "nodeFace" attribute. See an example
below:
Example:
743
Chapter 6. The RichFaces Comp...
There are some essential points in a "nodeFace" attribute usage: you need to define notions for
typeless and a default nodes.
The typeless node is the first <rich:treeNode> component (from all children nodes nested to the
<rich:tree> component) with not defined "type" attribute and defined "rendered" attribute. The
typeless node is used for representation when "nodeFace" attribute is null.
Example:
...
<h:outputText value="#{varAttributeName}">
...
• "nodeFace" attribute is defined, but its value isn't equal to any "type" attribute value from all
children nodes;
• "nodeFace" attribute is defined and its value is equal to a value of some "type" attribute from
all children nodes, but the value of "rendered" attribute for this node is "false".
There is also one thing that has to be remembered using "type" and "rendered" attributes: it's
possible to define several <rich:treeNode> components with equal values of "type" attribute and
different values of "rendered" attribute. It provides a possibility to define different representation
styles for the same node types. In the example with artists and their albums (see above [742])
it's possible to represent albums that are available for sale and albums that are not available.
Please study the example below:
Example:
...
<h:form>
<rich:tree style="width:300px" value="#{library.data}" var="item" nodeFace="#{item.type}">
...
<rich:treeNode type="album" iconLeaf="/images/tree/album.gif" icon="/images/tree/
album.gif"
rendered="#{item.exist}">
<h:outputText value="#{item.name}" />
</rich:treeNode>
<rich:treeNode type="album" iconLeaf="/images/tree/album_absent.gif" icon="/images/tree/
album_absent.gif"
744
Details of Usage
rendered="#{not item.exist}">
<h:outputText value="#{item.name}" />
</rich:treeNode>
...
</rich:tree>
</h:form>
...
In the example the <rich:treeNode> components has equal values of the "type" attribute.
Depending on value of the "rendered" attribute the corresponding <rich:treeNode> component
is selected for node representation. If an album is available for sale the value of the "rendered"
for the first <rich:treeNode> component is "true", for the second one is "false". Thus, the first
<rich:treeNode> is selected for node representation.
Tree node can be run in tree modes. Modes can be specified with "switchType" attribute for
<rich:tree> component.
• Ajax (default value) - Ajax submission is used performing the functionality. Note, that for
collapse/expand operations an Ajax request is sent to the server and it can cause a short delay.
• Client – all operations are performed totally on the client; no interaction with a server is
involved. Full page content is reloaded after every action.
The "icon" , "iconCollapsed" , "iconExpanded" , "iconLeaf" attributes set the icons' images for
the component. You can also define icons using facets with the same names. If the facets are
defined, the corresponding attributes are ignored and facets' content is used as icons. By default
the width of a rendered facet area is 16px.
745
Chapter 6. The RichFaces Comp...
Example:
...
<rich:tree value="#{library.data}" var="item">
...
<f:facet name="icon">
<h:graphicImage value="/images/tree/singer.png "/>
</f:facet>
<f:facet name="iconCollapsed">
<h:graphicImage value="/images/tree/singer.png" />
</f:facet>
<f:facet name="iconExpanded">
<h:graphicImage value="/images/tree/singer.png" />
</f:facet>
<f:facet name="iconLeaf">
<h:graphicImage value="/images/tree/song.png" />
</f:facet>
...
</rich:tree>
...
The <rich: tree> component can be used together with <rich: treeNodeAdaptor> . In this
case there is no need to specify the attributes "value" and "var" . Besides, visual representation
shouldn't be defined right in the tree. In this case a <rich: tree> tag is applied mainly for defining
common attributes such as "ajaxSubmitSelection" etc.
Information about the "process" attribute usage you can find here.
Tip:
"rowKeyConverter" support for the <rich:tree> is pending!
746
Built-In Drag and Drop
Consider drag-and-drop inside a tree. All zones, which are assumed to be dragged, must be
marked. In terms of <rich:tree> these zones completely correspond to tree nodes. So, all
dragging nodes should be marked with "dragType" attribute. Then, to mark zone(-s), where
the dragging node could be dropped, pass the type of dragging node to the "acceptedTypes"
attribute of the drop zone. It would be good to itemize, that each tree node in the <rich:tree>
component’s structure has its own key. Depending on how the component is used, these keys
can be generated by the component itself or can be taken from the component’s data model. Keys
help to identify each node in a tree; key is what exactly being passing from one node to another in
drag-and-drop operations. Finally, the method binding, that will process drag-and-drop operation,
should be pointed via "dropListener" attribute of the <rich:tree> .
Chapters "6.40 <dragIndicator>" and "6.39 <dndParam>" describes how to apply visual element,
that show some additional information (e.g. dragging item name) while operating with drag-and-
drop.
Page code, that describes a tree with built in drag-and-drop in the way it is considered, is shown
below.
Example:
...
<h:form>
<rich:tree style="width:300px" value="#{libraryAjaxTree.data}"
nodeFace="#{item.type}" var="item" dragIndicator=":treeDragIndicator"
dropListener="#{libraryAjaxTree.processDrop}">
747
Chapter 6. The RichFaces Comp...
• nodeSelectListener is called during request sending on a node selecting event (if request
sending on this event is defined)
Listener methods can be defined using the following attributes or using nested tags.
748
Look-and-Feel Customization
• "ondragexit" is a script expression to invoke when an element passing out from a tree zone
Standart HTML event attributes like "onclick" , "onmousedown" , "onmouseover" etc. can be also
used. Event handlers of a <rich:tree> component capture events occured on any tree part. But
event handlers of treeNode capture events occured on treeNode only, except for children events.
There are two ways to redefine the appearance of all <rich:tree> components at once:
In order to redefine styles for all <rich:tree> components on a page using CSS, it's enough to
create classes with the same names (possible classes could be found in the table above) and
define necessary properties in them. An example is placed below:
749
Chapter 6. The RichFaces Comp...
Example:
...
.rich-tree{
font-weight:bold;
}
...
This is a result:
Also it's possible to change styles of a particular <rich:tree> component. In this case you should
create own style classes and use them in corresponding <rich:tree> styleClass attributes. An
example is placed below:
Example:
...
.myClass{
font-weight:bold;
}
...
The "highlightedClass" attribute for <rich:tree> is defined as it's shown in the example below:
Example:
This is a result:
750
Relevant Resources Links
Figure 6.300. Redefinition styles with own classes and styleClass attributes
As it's shown on the picture above, font weight of highlighted text node of a tree was changed
to bold.
751
Chapter 6. The RichFaces Comp...
• Possibility to assign different icon images for each node within a tree
• Look-and-Feel customization
752
Key Features
753
Chapter 6. The RichFaces Comp...
754
Key Features
755
Chapter 6. The RichFaces Comp...
Example:
...
<rich:tree ... faceNode="simpleNode">
<rich:treeNode type="simpleNode">
<!--Tree node data displaying template-->
</rich:treeNode>
</rich:tree>
...
756
Details of Usage
import org.richfaces.component.html.HtmlTreeNode;
...
HtmlTreeNode myPanel = new HtmlTreeNode();
...
The "icon" , "iconCollapsed" , "iconExpanded" , "iconLeaf" attributes define icons for the
component. Also you can define icons using facets with the same names. If the facets are defined,
the corresponding attributes are ignored and facets contents are used as icons. The width of a
rendered facet area is 16px.
...
<rich:tree ...>
...
<rich:treeNode ...>
<f:facet name="icon">
<outputText value="A"/>
</f:facet>
<f:facet name="iconCollapsed">
<outputText value="B"/>
</f:facet>
<f:facet name="iconExpanded">
<outputText value="C"/>
</f:facet>
<f:facet name="iconLeaf">
<outputText value="D"/>
</f:facet>
</rich:treeNode>
...
</rich:tree>
...
As it has been mentioned above, <rich:treeNode> defines a template for nodes rendering in a
tree. Thus, during XML document rendering (a web.xml application) as a tree, the following nodes
output (passed via var="data" on a tree) happens:
Example:
...
<rich:tree ... faceNode="simpleNode" ... value="#{bean.data}" var="data">
757
Chapter 6. The RichFaces Comp...
<rich:treeNode type="simpleNode">
<h:outputText value="context-param:"/>
<h:inputText value="#{data.name}"/>
</rich:treeNode>
</rich:tree >
...
Hence, <h:outputText /> tag outputs the "context-param" string and then the <h:inputText
/> outputs the data.name element of this node.
Different nodes for rendering could be defined depending on some conditions on the tree
level. Each condition represents some rendering template. To get more information on various
treeNodesAdaptorAdaptor definition for nodes, see the tree component chapter.
Switching between expanded/collapsed modes is also managed on the tree level and defined in
the corresponding section.
Default nodes of the tree level as well as the ones defined with the treeNodesAdaptorAdaptor
component could send Ajax requests when selected with the mouse, it's managed with the
"ajaxSubmitSelection" attribute (true/false).
Information about the "process" attribute usage you can find here.
758
Skin Parameters Redefinition
There are two ways to redefine the appearance of all <rich:treeNode> components at once:
On the screenshot there are classes names that define styles for component elements.
759
Chapter 6. The RichFaces Comp...
Table 6.499. Classes names that define states for a node element
760
Relevant Resources Links
In order to redefine the style for all <rich:treeNode> components on a page using CSS, it's
enough to create classes with the same names and define the necessary properties in them.
To change the style of particular <rich:treeNode> components define your own style classes in
the corresponding <rich:treeNode> attributes.
It is also possible to change look and feel of specific <rich:treeNode> with the help of defining
for them "selectedClass" and "highlightedClass" attributes by their specific classes.
Name Value
listener-class org.richfaces.event.NodeExpandedListener
event-class org.richfaces.event.NodeExpandedEvent
tag-class org.richfaces.taglib.ChangeExpandListenerTag
761
Chapter 6. The RichFaces Comp...
Example:
...
<rich:changeExpandListener type="demo.Bean"/>
...
package demo;
public class ImplBean implements org.richfaces.event.NodeExpandedListener{
...
}
import demo.ImplBean;
...
ImplBean myListener = new ImplBean();
...
Attribute "type" defines the fully qualified Java class name for the listener. This class should
implement org.richfaces.event.NodeExpandedListener interface [http://labs.jboss.com/file-
access/default/members/jbossrichfaces/freezone/docs/apidoc_framework/index.html].
...
<rich:tree switchType="server" value="#{project.data}" var="item" nodeFace="#{item.type}">
<rich:changeExpandListener type="demo.ListenerBean"/>
...
<!-- Tree nodes -->
...
762
Look-and-Feel Customization
</rich:tree>
...
package demo;
import org.richfaces.event.NodeExpandedEvent;
public class ListenerBean implements org.richfaces.event.NodeExpandedListener{
...
public void processExpansion(NodeExpandedEvent arg0){
//Custom Developer Code
}
...
}
...
Name Value
listener-class org.richfaces.event.NodeSelectedListener
event-class org.richfaces.event.NodeSelectedEvent
763
Chapter 6. The RichFaces Comp...
Name Value
tag-class org.richfaces.taglib.NodeSelectListenerTag
Example:
...
<rich:nodeSelectListener type="demo.Bean"/>
...
package demo;
public class ImplBean implements org.richfaces.event.NodeSelectListener{
...
}
import demo.ImplBean;
...
ImplBean myListener = new ImplBean();
...
Attribute "type" defines the fully qualified Java class name for listener. This class should
implement org.richfaces.event.NodeSelectedListener interface [http://labs.jboss.com/file-
access/default/members/jbossrichfaces/freezone/docs/apidoc_framework/index.html].
...
<rich:tree switchType="server" value="#{project.data}" var="item" nodeFace="#{item.type}">
764
Look-and-Feel Customization
<rich:nodeSelectListener type="demo.ListenerBean"/>
...
<!-- Tree nodes -->
...
</rich:tree>
...
package demo;
import org.richfaces.event.NodeSelectedEvent;
public class ListenerBean implements org.richfaces.event.NodeSelectedListener{
...
public void processSelection(NodeSelectedEvent arg0){
//Custom Developer Code
}
...
}
765
Chapter 6. The RichFaces Comp...
766
Creating the Component Dynamically Using
Java
...
<rich:tree switchType="ajax" stateAdvisor="#{treeDemoStateAdvisor}">
<rich:recursiveTreeNodesAdaptor roots="#{fileSystemBean.sourceRoots}" var="item"
nodes="#{item.nodes}" />
</rich:tree>
...
Example:
import org.richfaces.component.html.HtmlRecursiveTreeNodesAdaptor;
...
HtmlRecursiveTreeNodesAdaptor myRecursiveTreeNodesAdaptor = new
HtmlRecursiveTreeNodesAdaptor();
...
Example:
...
<rich:tree adviseNodeOpened="#{treeModelBean.adviseNodeOpened}" switchType="client">
<rich:treeNodesAdaptor id="project" nodes="#{loaderBean.projects}" var="project">
<rich:treeNode>
<h:commandLink action="#{project.click}" value="Project: #{project.name}" />
</rich:treeNode>
<rich:recursiveTreeNodesAdaptor id="dir" var="dir" root="#{project.dirs}"
nodes="#{dir.directories}">
<rich:treeNode>
<h:commandLink action="#{dir.click}" value="Directory: #{dir.name}" />
</rich:treeNode>
767
Chapter 6. The RichFaces Comp...
Here [http://livedemo.exadel.com/richfaces-demo/richfaces/
treeNodesAdaptor.jsf?c=recursiveTreeNodesAdaptor] you can see the example of
<rich:recursiveTreeNodesAdaptor> usage.
6.95.1. Description
The <rich:treeNodesAdaptor> provides the possibility to define data models and create
representations for them.
768
Key Features
Name Value
component-type org.richfaces.TreeNodesAdaptor
component-class org.richfaces.component.html.HtmlTreeNodesAdaptor
component-family org.richfaces.TreeNodesAdaptor
769
Chapter 6. The RichFaces Comp...
Name Value
tag-class org.richfaces.taglib.TreeNodesAdaptorTag
...
<rich:treeNodesAdaptor var="issue" nodes="#{model.issues}">
<rich:treeNode>
<h:commandLink action="#{project.click}" value="Project: #{project.name}" />
</rich:treeNode>
...
<!-- Others nodes -->
...
</rich:treeNodesAdaptor>
...
import org.richfaces.component.html.HtmlTreeNodesAdaptor;
...
HtmlTreeNodesAdaptor myTreeNodesAdaptor = new HtmlTreeNodesAdaptor();
...
Collections are allowed to include lists, arrays, maps, XML NodeList and NamedNodeMap either
as a single object.
The <rich:treeNodesAdaptor> component can be nested without any limitations. See the
following example.
Example:
...
770
Relevant Resources Links
771
772
Chapter 7.
IDE Support
RichFaces support is implemented in JBoss Developer Studio 1.0.0 GA [http://www.redhat.com/
developers/rhds/index.html] and in Jboss Tools [http://www.jboss.org/tools/index.html]. JBoss
Developer Studio is a fully packaged IDE that provides full support for Java Server Faces,
RichFaces, Facelets, Struts and other Web technologies. In addition to this, it seamlessly
combines visual and source-oriented development approaches. One of the special support feature
for RichFaces is that it is available as project "capabilitiy" which can be added to any existing JSF
project by adding libraries and modifying configuration files as required."
773
774
Chapter 8.
Resources Links
JBoss RichFaces JBoss RichFaces [http://labs.jboss.com/portal/
jbossrichfaces/]
JBoss Forum JBoss Forums [http://jboss.com/
index.html?module=bb&op=main&c=27]
RichFaces Wiki RichFaces Wiki [http://labs.jboss.com/wiki/
RichFaces]
RichFaces Blog RichFaces Blog [http://jroller.com/page/a4j]
775
776