4

Currently I am re-engineering a bigger application. In the backend I want to use only java instead of javascript, therefore, and for many other reasons (cleaner code, separation of concerns, etc.) I am using the XPages Scaffolding project from Jesse Gallagher (thanks to him for this work).

I really like the controller classes of this project, but one question I have to this architectural approach:

enter image description here

The controller class has a one-to-one connection to an xpage (.xsp). In the BasicDocumentController class the following method protected DominoDocument getDoc() is responsible for getting the corresponding datasource (DominoDocument) but - and here is my challenge - I have more than one datasource in one xpage.

Possible approaches:

a) Overriding the getDoc() method in MyDocumentController (make only sense for one datasource)

b) Two controller classes MyDocumentControllerA MyDocumentControllerB?

c) etc.

What would be an appropriate approach to handle this requirement?

Thanks in advance for any hint!

Georg Kastenhofer
  • 1,387
  • 12
  • 32

1 Answers1

5

In that case, you could really just ditch the BasicDocumentController and use BasicXPageController. The former is mostly there for the simple case of a form-like XPage, but there's nothing too magical about it other than having a couple pre-made method stubs that are useful for hooking up to a document data source. With using multiple documents, you could make private DominoDocument getDocA() { return (DominoDocument)ExtLibUtil.resolveVariable("docA"); } and an equivalent for the other.

Jesse Gallagher
  • 4,461
  • 13
  • 11
  • Thanks for your prompt answer. In my opinion one disadvantage handling more than one DominoDocument in one class is, that it is not so easy to deal with method names (for method binding) like save() or cancel() and so on. E.g. if I have to handle two sources I have to code two methods: saveDocA() and saveDocB()... – Georg Kastenhofer Mar 08 '16 at 14:38
  • 2
    That definitely depends on how you want to handle it. If they will logically be saved via separate actions, then yeah, having multiple methods would be the way to go. If they're saved together, though, the existing save method from `BasicXPageController` will save all data sources in the same way a stock "Save" action button does. – Jesse Gallagher Mar 08 '16 at 14:50
  • 1
    In my page controllers I might have multiple custom objects and as need might do - controller.getObject1().save() and controller.getObject2().save(). – David Leedy Mar 08 '16 at 15:52
  • @DavidLeedy: i had the same idea yesterday, good to know that other experts come to the same design decision :) – Georg Kastenhofer Mar 09 '16 at 09:09