Here's what I'd like to do. I have a Task interface whose implementations on the back end know how to call the various services that need to be called to get things done.
Some of the things I need to have done, in some cases, must be confirmed. For example, if I'm adding a person to the database, I want the back end to check and see if there's already somebody in the database who is semantically proximate to the present candidate. If so, I want a confirmation page: "The new name Roger Abernathy is very similar to the preexisting name Roger Abernethy. Are you sure you want to add Roger Abernathy?" So I have a ConfirmableTask with confirmationRequired and confirmed properties. When I click Submit on my CreatePerson page, if there's no confirmation required, I want onSuccess () to execute the Task and return another CreatePerson page to accept the next candidate. But if confirmation is required, I want a generic Confirm page to appear, display the "The new name..." message along with any other accumulated reasons continuing with the create may not be a good idea, and present a "Yes, go ahead" button and a "No, no need" button. I want the Confirm page to carry the same Task that was set up by the original CreatePerson page (or any other page initiating an action that might need confirmation). If the user clicks "Yes, go ahead," the Confirm page should set the confirmed property on the Task and resubmit it, then return a CreatePerson page just as the CreatePerson page itself would have done if no confirmation had been required. If the user clicks "No, no need," the Confirm page should return a CreatePerson page with the same Task in it so that the user can change the values and try again. (I'm about to lie a little for the sake of simplicity.) My ConfirmableTask, therefore, has getConfirmPage () and getAbortPage () methods on it; the Confirm page's onSuccess () method calls one of them, depending on which button the user clicks, to determine where to navigate. The problem, of course, is getting hold of the pages to return. I can't construct them myself: Tapestry has to construct them. I can't find a way to get copies directly from the page pool either. So right now my Confirm.java class has a bunch of private fields with @InjectPage annotations, one for each page class that might need confirmation. My ConfirmableTasks know the classes of the pages they want to return on submit and abort, and so I take that class and reflectively go looking through either the fields on the class that have @InjectPage annotations on them (for unit and integration tests), or the methods on the class whose names begin with "_$read_inject_page" (for production and PageTester tests, since Tapestry apparently does some weird bytecode weaving), for the one that has the proper type; then I get the field value or invoke the method to get hold of the page instance that was @InjectPaged and return it from Confirm.onSuccess (). That feels like a monumental hack, and I haven't gotten it to work reliably yet. This HAS to be a solved problem, and there's got to be a right way to do this kind of thing. Does anybody know what it is? Thanks, Dan --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
