Hi Bryan, On 15 Mar 2002, Bryan Field-Elliot wrote:
> Date: 15 Mar 2002 13:33:05 -0700 > From: Bryan Field-Elliot <[EMAIL PROTECTED]> > Reply-To: Struts Developers List <[EMAIL PROTECTED]> > To: [EMAIL PROTECTED] > Subject: DynaActionForm questions > > Hi, > > I'm just today getting around to having a peek at the new > DynaActionForm. I'm slightly confused as to how useful this is, in a > setting in which you don't know at compile-time what fields you're going > to need to ask for. > Interesting that this has come up twice in the last week. The current DynaActionForm implementation is indeed aimed at the case where you know ahead of time which properties you need the bean to represent, so that you can configure them in the struts-config.xml file. The basic idea is to avoid the need to create custom ActionForm bean classes for all the simple cases. Right now, you would still need to create your own bean if you needed a custom validate method, but even there we can look at adding declartive ways to define simple validations (required fields, date formats, and so on) so that even those don't require any custom Java code. Since form beans are really part of the view tier in the Struts implementation of MVC, one of the benefits of this will be that responsibility for designing and configuring form beans can now be migrated to the page designer that understands enough XML to code the appropriate struts-config settings, instead of requiring a Java developer to do this. And, since creating form bean classes is pretty boring, the Java developer gets to stay focused on the fun stuff. > Let's say for example I'm introspecting a JDBC table for a list of > columns and types, and want to dynamically build a form for CRUD > operations on this table. Or, instead of a JDBC table, maybe I want to > assemble a form out of an XML DTD or Schema. DynaActionForm doesn't help you do either of these without custom Java form bean classes. Of course, neither did the original-style form beans ... Doing this kind of form creation dynamically, though, is going to require more than just "DynaDynaActionForm" classes. You'll also need to figure out how to decide what field prompts to create, what data types and formats are valid, and other stuff like that. > > I see that I can build an ActionForm class to hold values for this > table, out of DynaClasses (I'm basically already doing this in the > Simper project). > > Where I'm missing something is, are there new Struts JSP tags for > building an HTML form out of a DynaActionForm? I don't see them, but > perhaps I'm missing the obvious. > You don't see them because they aren't needed :-) > If the answer is, "There are no new JSP tags for building HTML forms out > of DynaActionForms", then I'm wondering just how useful DynaActionForm > is without it... What's a typical use case for it? > The existing Struts tags work fine because they use BeanUtils and PropertyUtils underneath. These two classes have been made smart about the bean object they are manipulating -- if you pass them a DynaBean, they use the dynamic getters and setters. Otherwise they use the Java reflection mechanism as before. So, you can even change your mind about whether a particular form bean is a DynaActionForm, or a plain old-style form bean, without affecting your pages at all -- just change the <form-bean> declaration and you are all set. Pretty slick, huh? :-) > Thanks, > > Bryan > Craig -- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>