|
From: Andy D. <an...@ma...> - 2007-05-04 23:44:22
|
Has anyone given much thought to support for buttons or actions on forms? When you think about it, Spring's Form framework is MVC, with the Form (and binding) being the controller. With this in mind, I'd like to "bind" buttons on the form to actions. Since the Form instance ends up being the closest thing to a Controller, it seems to me the best approach would be to register actions (ActionCommand, or ActionCommandExecutor?) with the Form. Components in the view can then bind to these actions by name (ActionCommands have an 'id'), much in the same way components are bound to properties by name. In our case, we use a UI designer, and then a custom FormUIProvider to load and bind the generated UI at runtime. We use a convention where the UI designer names each component on the UI that can be bound (via Component's name property) with the name of the property to bind to + "_bound". So, if I named a component "name_bound", then that component will be bound to the "name" property in the FormModel. I'd like to do the same for a button. If a button is bound, then it binds to the ActionCommand registered with the Form with the specified name. This approach causes any "action" to be handled by the controller (Form instance), and avoids putting such code into the View or the backing bean. With this approach, the MVC pattern is split up like so: 1. View = predesigned UI + FormUIProvider 2. Model = backing JavaBean + FormModel 3. Controller = Spring's Form + registered actions + Spring binding framework Thoughts, suggestions? - Andy |