Showtime! An XPage Dynamic Table Managed Bean
description
Transcript of Showtime! An XPage Dynamic Table Managed Bean
![Page 1: Showtime! An XPage Dynamic Table Managed Bean](https://reader035.fdocuments.net/reader035/viewer/2022081512/56816176550346895dd1023e/html5/thumbnails/1.jpg)
AusLUG2011
Meet.Share.Learn
29th & 30th August, Sydney, Australia
Russell Maher | President | RGM Consultingrgmconsulting.comXPageTips.com
Showtime! An XPage Dynamic Table Managed Bean
![Page 2: Showtime! An XPage Dynamic Table Managed Bean](https://reader035.fdocuments.net/reader035/viewer/2022081512/56816176550346895dd1023e/html5/thumbnails/2.jpg)
Meet.Share.Learn 29th & 30th August, Sydney, Australia
AusLUG2011
2
Who is Russell Maher?
• Independent consultant located outside of Chicago• Developing, administering, teaching, speaking on
Notes/Domino since 1993• Co-presenter of The VIEW Advanced XPages for
Domino Developers• XPageTips.com• Managing partner of QDiligence
![Page 3: Showtime! An XPage Dynamic Table Managed Bean](https://reader035.fdocuments.net/reader035/viewer/2022081512/56816176550346895dd1023e/html5/thumbnails/3.jpg)
Meet.Share.Learn 29th & 30th August, Sydney, Australia
AusLUG2011
3
Agenda
• Application Requirements• Architectural Overview• The Code• Deployment• Using the Custom Control
![Page 4: Showtime! An XPage Dynamic Table Managed Bean](https://reader035.fdocuments.net/reader035/viewer/2022081512/56816176550346895dd1023e/html5/thumbnails/4.jpg)
Meet.Share.Learn 29th & 30th August, Sydney, Australia
AusLUG2011
4
Agenda
• Application Requirements• Architectural Overview• The Code• Deployment• Using the Custom Control
![Page 5: Showtime! An XPage Dynamic Table Managed Bean](https://reader035.fdocuments.net/reader035/viewer/2022081512/56816176550346895dd1023e/html5/thumbnails/5.jpg)
Meet.Share.Learn 29th & 30th August, Sydney, Australia
AusLUG2011
5
What is this about?
Domino developers have always needed ability to provide dynamic tables.
This presentation describes a dynamic table solution using XPages and managed beans that is easy to administer and deploy.
![Page 6: Showtime! An XPage Dynamic Table Managed Bean](https://reader035.fdocuments.net/reader035/viewer/2022081512/56816176550346895dd1023e/html5/thumbnails/6.jpg)
Meet.Share.Learn 29th & 30th August, Sydney, Australia
AusLUG2011
6
Application Requirements
• Users…– Must be able to add any
number of rows to a table within the same document
– Must be able to save document as a Draft or Final
– If document is not saved, table must be restored next time document is opened
• Administrators…– Must be able to configure
table without programming
• Column Headings• Number of columns• Field types• Field choices• Field validation
![Page 7: Showtime! An XPage Dynamic Table Managed Bean](https://reader035.fdocuments.net/reader035/viewer/2022081512/56816176550346895dd1023e/html5/thumbnails/7.jpg)
Meet.Share.Learn 29th & 30th August, Sydney, Australia
AusLUG2011
7
Demo!
![Page 8: Showtime! An XPage Dynamic Table Managed Bean](https://reader035.fdocuments.net/reader035/viewer/2022081512/56816176550346895dd1023e/html5/thumbnails/8.jpg)
Meet.Share.Learn 29th & 30th August, Sydney, Australia
AusLUG2011
8
Agenda
• Application Requirements• Architectural Overview• The Code• Deployment• Using the Custom Control
![Page 9: Showtime! An XPage Dynamic Table Managed Bean](https://reader035.fdocuments.net/reader035/viewer/2022081512/56816176550346895dd1023e/html5/thumbnails/9.jpg)
Meet.Share.Learn 29th & 30th August, Sydney, Australia
AusLUG2011
9
Architectural Overview
• Table data is stored on a single document– Repeated fields
Answer1_1,Answer1_2,Answer1_3Answer2_1,Answer2_2,Answer2_3Answer3_1,Answer3_2,Answer3_3
– Why?• Less documents• Local data (right on the document)• Easier to code manage
![Page 10: Showtime! An XPage Dynamic Table Managed Bean](https://reader035.fdocuments.net/reader035/viewer/2022081512/56816176550346895dd1023e/html5/thumbnails/10.jpg)
Meet.Share.Learn 29th & 30th August, Sydney, Australia
AusLUG2011
10
Required Configuration Information
• You need a keyed table config document that describes:– # of Columns– Header text for each table column– Field details for each column
• Answer is: Radio, Text, Checkbox, Combobox• Field choices (Yes/No, True/False, etc.)• Is field required?
![Page 11: Showtime! An XPage Dynamic Table Managed Bean](https://reader035.fdocuments.net/reader035/viewer/2022081512/56816176550346895dd1023e/html5/thumbnails/11.jpg)
Meet.Share.Learn 29th & 30th August, Sydney, Australia
AusLUG2011
11
Table Configuration Document
![Page 12: Showtime! An XPage Dynamic Table Managed Bean](https://reader035.fdocuments.net/reader035/viewer/2022081512/56816176550346895dd1023e/html5/thumbnails/12.jpg)
Meet.Share.Learn 29th & 30th August, Sydney, Australia
AusLUG2011
12
Required Dynamic Table Information
• For each dynamic table you must…1. Repeat the # of columns• Found in the table configuration document
2. Repeat the number of rows• Found in the current user document• The document used for data entry
3. Repeat the number of questions in a row• Found in the table configuration document
![Page 13: Showtime! An XPage Dynamic Table Managed Bean](https://reader035.fdocuments.net/reader035/viewer/2022081512/56816176550346895dd1023e/html5/thumbnails/13.jpg)
Meet.Share.Learn 29th & 30th August, Sydney, Australia
AusLUG2011
13
Dynamic Table Visualization
![Page 14: Showtime! An XPage Dynamic Table Managed Bean](https://reader035.fdocuments.net/reader035/viewer/2022081512/56816176550346895dd1023e/html5/thumbnails/14.jpg)
Meet.Share.Learn 29th & 30th August, Sydney, Australia
AusLUG2011
14
Adding A Row
• Initially appears simple:– Increment the rowCount for the table by 1– Add a new row to the table
• What happens if document is…– Not saved?
• You don’t keep the new rows
– Saved as Draft?• You keep the new rows but don’t validate
– Saved as Final?• You validate and keep the rows
![Page 15: Showtime! An XPage Dynamic Table Managed Bean](https://reader035.fdocuments.net/reader035/viewer/2022081512/56816176550346895dd1023e/html5/thumbnails/15.jpg)
Meet.Share.Learn 29th & 30th August, Sydney, Australia
AusLUG2011
15
Deleting a Row
• Again appears simple:– Decrement rowCount by 1– Remove the row from the table
• What happens if document is…– Not saved?
• You can’t lose them – user expects them next time
– Saved as Draft or as Final?• You remove the rows from the table permanently
![Page 16: Showtime! An XPage Dynamic Table Managed Bean](https://reader035.fdocuments.net/reader035/viewer/2022081512/56816176550346895dd1023e/html5/thumbnails/16.jpg)
Meet.Share.Learn 29th & 30th August, Sydney, Australia
AusLUG2011
16
Gaps. You don’t want ‘em.
• You always want:Answer1_1,Answer1_2,Answer1_3Answer2_1,Answer2_2,Answer2_3Answer3_1,Answer3_2,Answer3_3
• You never want “gaps”:Answer5_1,Answer5_2,Answer5_3Answer13_1,Answer13_2,Answer13_3Answer14_1,Answer14_2,Answer14_3
![Page 17: Showtime! An XPage Dynamic Table Managed Bean](https://reader035.fdocuments.net/reader035/viewer/2022081512/56816176550346895dd1023e/html5/thumbnails/17.jpg)
Meet.Share.Learn 29th & 30th August, Sydney, Australia
AusLUG2011
17
Every Save Requires Normalization
• The user document table fields must…– Always accurately reflect the number of rows– Never include missing rows
• On document open you must list rowCount number of rows– Gaps will cause problems
![Page 18: Showtime! An XPage Dynamic Table Managed Bean](https://reader035.fdocuments.net/reader035/viewer/2022081512/56816176550346895dd1023e/html5/thumbnails/18.jpg)
Meet.Share.Learn 29th & 30th August, Sydney, Australia
AusLUG2011
18
Table Field Normalization
• When a dynamic table is saved…– You clean the table fields on the document by…
• Walking the existing table and removing deleted rows– They are only “hidden” when a user deletes them in case they
don’t save
• Rebuilding the table using remaining rows
• Rearranging the document fields to match new table data– You don’t want any “ghost” table fields lingering about on your
document
![Page 19: Showtime! An XPage Dynamic Table Managed Bean](https://reader035.fdocuments.net/reader035/viewer/2022081512/56816176550346895dd1023e/html5/thumbnails/19.jpg)
Meet.Share.Learn 29th & 30th August, Sydney, Australia
AusLUG2011
19
Field Normalization Visualized
![Page 20: Showtime! An XPage Dynamic Table Managed Bean](https://reader035.fdocuments.net/reader035/viewer/2022081512/56816176550346895dd1023e/html5/thumbnails/20.jpg)
Meet.Share.Learn 29th & 30th August, Sydney, Australia
AusLUG2011
20
Agenda
• Application Requirements• Architectural Overview• The Code• Deployment• Using the Custom Control
![Page 21: Showtime! An XPage Dynamic Table Managed Bean](https://reader035.fdocuments.net/reader035/viewer/2022081512/56816176550346895dd1023e/html5/thumbnails/21.jpg)
Meet.Share.Learn 29th & 30th August, Sydney, Australia
AusLUG2011
21
Dynamic Binding Act 1
• Expression Language (EL) binds XPage controls to data
#{dataSource.fieldname}
• EL bindings can be dynamic#{dataSource.SOMEVARIABLE}
![Page 22: Showtime! An XPage Dynamic Table Managed Bean](https://reader035.fdocuments.net/reader035/viewer/2022081512/56816176550346895dd1023e/html5/thumbnails/22.jpg)
Meet.Share.Learn 29th & 30th August, Sydney, Australia
AusLUG2011
22
Dynamic Binding Act 2
• Custom Controls can have defined properties– Property values can be set at runtime– Property values are provided by the containing
XPage/control– Accessed from within the custom control as:
• compositeData.propertyname
![Page 23: Showtime! An XPage Dynamic Table Managed Bean](https://reader035.fdocuments.net/reader035/viewer/2022081512/56816176550346895dd1023e/html5/thumbnails/23.jpg)
Meet.Share.Learn 29th & 30th August, Sydney, Australia
AusLUG2011
23
Dynamic Binding Finale
• Dynamic EL binding + Custom Control =#{dataSource[compositeData.propertyname]}
• This allows you to have any field on a custom control bind to any field on the document that you wish
![Page 24: Showtime! An XPage Dynamic Table Managed Bean](https://reader035.fdocuments.net/reader035/viewer/2022081512/56816176550346895dd1023e/html5/thumbnails/24.jpg)
Meet.Share.Learn 29th & 30th August, Sydney, Australia
AusLUG2011
24
Dynamic Binding Illustration
![Page 25: Showtime! An XPage Dynamic Table Managed Bean](https://reader035.fdocuments.net/reader035/viewer/2022081512/56816176550346895dd1023e/html5/thumbnails/25.jpg)
Meet.Share.Learn 29th & 30th August, Sydney, Australia
AusLUG2011
25
Dynamic Binding Illustration 2
![Page 26: Showtime! An XPage Dynamic Table Managed Bean](https://reader035.fdocuments.net/reader035/viewer/2022081512/56816176550346895dd1023e/html5/thumbnails/26.jpg)
Meet.Share.Learn 29th & 30th August, Sydney, Australia
AusLUG2011
26
Table_Configuration.xsp
• Contains…– Lookup Key Field– Number of Columns Field– Repeat control…
• Repeats “Number of Columns” times• Repeats a configTableColumnControl for each column
![Page 27: Showtime! An XPage Dynamic Table Managed Bean](https://reader035.fdocuments.net/reader035/viewer/2022081512/56816176550346895dd1023e/html5/thumbnails/27.jpg)
Meet.Share.Learn 29th & 30th August, Sydney, Australia
AusLUG2011
27
Table Configuration
![Page 28: Showtime! An XPage Dynamic Table Managed Bean](https://reader035.fdocuments.net/reader035/viewer/2022081512/56816176550346895dd1023e/html5/thumbnails/28.jpg)
Meet.Share.Learn 29th & 30th August, Sydney, Australia
AusLUG2011
28
configTableColumnControl
• Contains…– configColumnLabelControl
• Contains column header label for a column
– configFieldTypeControl• Defines type of field: Radio, Checkbox, etc.
– configFieldChoicesControl• List choices for appropriate fields
– configFieldRequiredControl• Is this field required?
![Page 29: Showtime! An XPage Dynamic Table Managed Bean](https://reader035.fdocuments.net/reader035/viewer/2022081512/56816176550346895dd1023e/html5/thumbnails/29.jpg)
Meet.Share.Learn 29th & 30th August, Sydney, Australia
AusLUG2011
29
configTableColumnControl
![Page 30: Showtime! An XPage Dynamic Table Managed Bean](https://reader035.fdocuments.net/reader035/viewer/2022081512/56816176550346895dd1023e/html5/thumbnails/30.jpg)
Meet.Share.Learn 29th & 30th August, Sydney, Australia
AusLUG2011
30
UserDocument.xsp
• Contains…– A tableBeanDynamicTableControl custom control
• Gets single property:
the key of the configuration document
![Page 31: Showtime! An XPage Dynamic Table Managed Bean](https://reader035.fdocuments.net/reader035/viewer/2022081512/56816176550346895dd1023e/html5/thumbnails/31.jpg)
Meet.Share.Learn 29th & 30th August, Sydney, Australia
AusLUG2011
31
tableBeanDynamicTableControl
• Contains…– An XPage table control
• Repeat control for the column headers• Repeat for the table rows which contains…
– Repeat for each row of questions
– Buttons• Add New Row• Save as Draft• Save as Final
![Page 32: Showtime! An XPage Dynamic Table Managed Bean](https://reader035.fdocuments.net/reader035/viewer/2022081512/56816176550346895dd1023e/html5/thumbnails/32.jpg)
Meet.Share.Learn 29th & 30th August, Sydney, Australia
AusLUG2011
32
tableBeanDynamicTableControl
DEMO
![Page 33: Showtime! An XPage Dynamic Table Managed Bean](https://reader035.fdocuments.net/reader035/viewer/2022081512/56816176550346895dd1023e/html5/thumbnails/33.jpg)
Meet.Share.Learn 29th & 30th August, Sydney, Australia
AusLUG2011
33
EL = Bean Connection
• Expression Language actually binds controls to a JavaBean• #{dataSource.fieldname}
really means
“Connect to the dataSource bean and access its fieldname property.”
![Page 34: Showtime! An XPage Dynamic Table Managed Bean](https://reader035.fdocuments.net/reader035/viewer/2022081512/56816176550346895dd1023e/html5/thumbnails/34.jpg)
Meet.Share.Learn 29th & 30th August, Sydney, Australia
AusLUG2011
34
Managed Beans
• Managed beans …– Are Java classes not represented by a UI control
• vs. the “backing beans” used by the XPage controls
– Are a different way to code your XPage application business logic
– Are like agents or script libraries that are running all the time• You just call their functionality whenever you need them to
do something
![Page 35: Showtime! An XPage Dynamic Table Managed Bean](https://reader035.fdocuments.net/reader035/viewer/2022081512/56816176550346895dd1023e/html5/thumbnails/35.jpg)
Meet.Share.Learn 29th & 30th August, Sydney, Australia
AusLUG2011
35
Managed Bean Development Process
1. Write a Java class
2. Deploy the managed bean into your NSF
3. Use EL to bind your XPage controls the your managed bean
![Page 36: Showtime! An XPage Dynamic Table Managed Bean](https://reader035.fdocuments.net/reader035/viewer/2022081512/56816176550346895dd1023e/html5/thumbnails/36.jpg)
Meet.Share.Learn 29th & 30th August, Sydney, Australia
AusLUG2011
36
Write a Managed Bean Class
![Page 37: Showtime! An XPage Dynamic Table Managed Bean](https://reader035.fdocuments.net/reader035/viewer/2022081512/56816176550346895dd1023e/html5/thumbnails/37.jpg)
Meet.Share.Learn 29th & 30th August, Sydney, Australia
AusLUG2011
37
TableBean
• One managed bean that provides all dynamic table functionality
• Represents a single table• Called from the dynamicTableControl• Creates a session scoped representation of the
entire table for current document
![Page 38: Showtime! An XPage Dynamic Table Managed Bean](https://reader035.fdocuments.net/reader035/viewer/2022081512/56816176550346895dd1023e/html5/thumbnails/38.jpg)
Meet.Share.Learn 29th & 30th August, Sydney, Australia
AusLUG2011
38
TableBean Construction Methods
• buildBean() – Creates an entire table object
• getTableColumnHeadings()– Returns a Vector of column headings
• getTableRows()– Returns a Vector of table rows
![Page 39: Showtime! An XPage Dynamic Table Managed Bean](https://reader035.fdocuments.net/reader035/viewer/2022081512/56816176550346895dd1023e/html5/thumbnails/39.jpg)
Meet.Share.Learn 29th & 30th August, Sydney, Australia
AusLUG2011
39
TableBean Management Methods
• addTableRow() • removeTableRow()• cleanTableFields()• saveAsDraft()• saveAsFinal()
![Page 40: Showtime! An XPage Dynamic Table Managed Bean](https://reader035.fdocuments.net/reader035/viewer/2022081512/56816176550346895dd1023e/html5/thumbnails/40.jpg)
Meet.Share.Learn 29th & 30th August, Sydney, Australia
AusLUG2011
40
Agenda
• Application Requirements• Architectural Overview• The Code• Deployment• Using the Custom Control
![Page 41: Showtime! An XPage Dynamic Table Managed Bean](https://reader035.fdocuments.net/reader035/viewer/2022081512/56816176550346895dd1023e/html5/thumbnails/41.jpg)
Meet.Share.Learn 29th & 30th August, Sydney, Australia
AusLUG2011
41
Managed Bean Deployment
• Your Java source files need to be accessible to your NSF– Use the Package Explorer– Create a new source folder
• Right-click the project• Use Build Path…New Source Folder…
– Place your packaged Java source in the new source folder
![Page 42: Showtime! An XPage Dynamic Table Managed Bean](https://reader035.fdocuments.net/reader035/viewer/2022081512/56816176550346895dd1023e/html5/thumbnails/42.jpg)
Meet.Share.Learn 29th & 30th August, Sydney, Australia
AusLUG2011
42
Making a Source Folder
![Page 43: Showtime! An XPage Dynamic Table Managed Bean](https://reader035.fdocuments.net/reader035/viewer/2022081512/56816176550346895dd1023e/html5/thumbnails/43.jpg)
Meet.Share.Learn 29th & 30th August, Sydney, Australia
AusLUG2011
43
Managed Bean Deployment
• Tell the NSF the managed bean exists– Package Explorer– Edit faces-config.xml– Give the bean a name
• This is the name you use in your code to call the bean
– Identify the Java source of the bean– Identify the scope of the managed bean
• application, session, view, request, none
![Page 44: Showtime! An XPage Dynamic Table Managed Bean](https://reader035.fdocuments.net/reader035/viewer/2022081512/56816176550346895dd1023e/html5/thumbnails/44.jpg)
Meet.Share.Learn 29th & 30th August, Sydney, Australia
AusLUG2011
44
Editing faces-config.xml
![Page 45: Showtime! An XPage Dynamic Table Managed Bean](https://reader035.fdocuments.net/reader035/viewer/2022081512/56816176550346895dd1023e/html5/thumbnails/45.jpg)
Meet.Share.Learn 29th & 30th August, Sydney, Australia
AusLUG2011
45
“Then A Miracle Happens”
• Once you have configured your managed bean, the first call to any of its methods instantiates the bean!
![Page 46: Showtime! An XPage Dynamic Table Managed Bean](https://reader035.fdocuments.net/reader035/viewer/2022081512/56816176550346895dd1023e/html5/thumbnails/46.jpg)
Meet.Share.Learn 29th & 30th August, Sydney, Australia
AusLUG2011
46
Code & Demo Time!
![Page 47: Showtime! An XPage Dynamic Table Managed Bean](https://reader035.fdocuments.net/reader035/viewer/2022081512/56816176550346895dd1023e/html5/thumbnails/47.jpg)
Meet.Share.Learn 29th & 30th August, Sydney, Australia
AusLUG2011
47
Agenda
• Application Requirements• Architectural Overview• The Code• Deployment• Using the Custom Control
![Page 48: Showtime! An XPage Dynamic Table Managed Bean](https://reader035.fdocuments.net/reader035/viewer/2022081512/56816176550346895dd1023e/html5/thumbnails/48.jpg)
Meet.Share.Learn 29th & 30th August, Sydney, Australia
AusLUG2011
48
Using the Dynamic Table Control
• If you want it, you can have it.
• http://www.rgmconsulting.com/tablebean
• Need to clean the Java code and add more comments then I will send people a link and post publicly.
![Page 49: Showtime! An XPage Dynamic Table Managed Bean](https://reader035.fdocuments.net/reader035/viewer/2022081512/56816176550346895dd1023e/html5/thumbnails/49.jpg)
Meet.Share.Learn 29th & 30th August, Sydney, Australia
AusLUG2011
49
Questions??
• Thank you!• Visit XPagetips.com• Contact Me If You Have Questions
Russell [email protected]