I am using the Struts framework with and am trying to dynamically build a web page based upon what data is pulled out of an Oracle database. The field types can be checkbox, radio button, or text. I was thinking I could us a map-backed action for this but I'm stuck on an issue. I need to understand how I get the data from the action class to the form (where I've got my get and set methods) and then to the JSP. Of course then I need to concern getting the updates from the user back to the other way so it gets persisted back in the database. I'm looking for an example, can you either walk me through this or provide an example please. Thanks in advance.
Thaks Jathrek, you helped be get by my first hurdle, I was hoping you could help me with this next related issue. My model is comletely dynamic, and my question is: can I have a form that would have an Arraylist that includes a Java object such as an object that contains two Hashmaps? If so, do you recommend that I build a helper class that gets used from the Action class to build these objects from the database to get and set this data from an I/O perspective? Feeling a bit over my head on this.
Jathrek
Well, I don't really understand the structure of data you're trying to achieve, but the concept I use is usually the same no matter how I work;
I use a multiple layered architecture;
- Model (accessors to database, eventually EJB's & digests mechanisme)
- View (containing Struts action, JSP, ...)
When a URL is called on my server, I usually call a first Struts action (that I qualify as "View" action) where I load all the dynamic data used in the JSP rendering the HTML (like the content of the forms, the default values of the fields, object's contents under the form of digests, ...). Then, when the user submit this view action, I call a "Submit" Struts action, which handles the request (and usually ends up calling another URL, meaning that it will redirect to another "View" Struts action). So in my case, I'm using those View to retrieve the dynamic content of my JSP pages using a "model" layer, which can be a simple database accessor or a more complex EJB.
Lately, I've had more complex Action forms for which I've build wrapper around them, mostly to ease the validation (the form only had String as properties - the wrapper being used to convert those Strings to digits, date or more complex homemade objects).
The problem, if you're build a too complex structure within a Struts action form is that it'll probably be painful to access the sub-sub-sub-sub elements in the form; you'll have to use a lot of bean:define to each time go a level lower in your object hierarchy until you reach the object you need (or it's parent if you use both "name" and "proprety" attributes in Struts tags).
So I'll advise you to avoid complex structures (at most arrays or maps) and to try to separate this complex structure in multiple easier-to-handle properties within the form.
I don't know if it helped you, just tell me if you want more details...
tjhenry
ASKER
Jathrek, I apprecaite your continued assistance. I'm understanding you for the most part. My model is based upon a data model that can be "configured" to hold any of the following datatypes in any order: checkbox, radio buttons, and text. I would need to be able to retrieve this configuration and related data from the database, prepare it for the form, and when the page is submitted re-assemble the objects back to the same formate so I can store changes in the database. Have you worked with such a flexible model in the past? If so, can you provide some additinal guidance or do you feel I should be able to move forward based upon what you've already provided?
Nah, I've been thinking to several solutions, but they were either unsucessfull or just totally ugly...
I'll try to think about it in the next days, but I'm not sure I'll be able to help you...
I'm not sure that you'll be able to use such a complex objects structure directly in a form, you may need to use little hacks like using multiple maps or stuff like that, but I don't really have any good advices for you :(