490 likes | 611 Vues
This presentation showcases a solution for Domino developers to implement dynamic tables using XPages and managed beans. Learn how to easily administer and deploy tables where users can add rows, save documents as drafts or finals, and ensure data persistence. The session covers application requirements, architectural overview, code implementation, deployment strategies, and the use of custom controls. Streamline your table management while minimizing document complexity and maximizing user experience. Unlock the potential of dynamic tables in your applications today!
E N D
Showtime! An XPage Dynamic Table Managed Bean Russell Maher | President | RGM Consulting rgmconsulting.com XPageTips.com
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
Agenda • Application Requirements • Architectural Overview • The Code • Deployment • Using the Custom Control
Agenda • Application Requirements • Architectural Overview • The Code • Deployment • Using the Custom Control
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.
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
Agenda • Application Requirements • Architectural Overview • The Code • Deployment • Using the Custom Control
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
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?
Required Dynamic Table Information • For each dynamic table you must… • Repeat the # of columns • Found in the table configuration document • Repeat the number of rows • Found in the current user document • The document used for data entry • Repeat the number of questions in a row • Found in the table configuration document
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
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
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
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
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
Agenda • Application Requirements • Architectural Overview • The Code • Deployment • Using the Custom Control
Dynamic Binding Act 1 • Expression Language (EL) binds XPage controls to data #{dataSource.fieldname} • EL bindings can be dynamic #{dataSource.SOMEVARIABLE}
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
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
Table_Configuration.xsp • Contains… • Lookup Key Field • Number of Columns Field • Repeat control… • Repeats “Number of Columns” times • Repeats a configTableColumnControl for each column
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?
UserDocument.xsp • Contains… • A tableBeanDynamicTableControl custom control • Gets single property:the key of the configuration document
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
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.”
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
Managed Bean Development Process • Write a Java class • Deploy the managed bean into your NSF • Use EL to bind your XPage controls the your managed bean
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
TableBean Construction Methods • buildBean() • Creates an entire table object • getTableColumnHeadings() • Returns a Vector of column headings • getTableRows() • Returns a Vector of table rows
TableBean Management Methods • addTableRow() • removeTableRow() • cleanTableFields() • saveAsDraft() • saveAsFinal()
Agenda • Application Requirements • Architectural Overview • The Code • Deployment • Using the Custom Control
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
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
“Then A Miracle Happens” • Once you have configured your managed bean, the first call to any of its methods instantiates the bean!
Agenda • Application Requirements • Architectural Overview • The Code • Deployment • Using the Custom Control
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.
Questions?? • Thank you! • Visit XPagetips.com • Contact Me If You Have Questions Russell Maher Russ.Maher@rgmconsulting.com