I have what may be a stupid question regarding the usage of forms in
Struts. I have a web application which has a page displaying a list of
items. When the user clicks on one of the items I want to bring up a form
which allows the user to edit the items. Nothing too hard. My question is
about what the best way is to go about populating the form within the
Struts framework. If I were just displaying information, I would simply
create an Action for the page which would populate a bean which would then
be referenced by the corresponding JSP page. However, since this is a
form, I want to make use of Struts form handling capabilities. If I use a
form action, the action occurs on submission. How do I control the initial
values of the form?
One way that I can think of is to use some sort of "action" parameter. If
the action parameter is missing, the form action populates the bean
properties, otherwise it saves the bean properties back to the system. The
problem I have with this approach is that I have to have a hidden field on
the page which is used to store the "action" value. It's not a big deal,
but it seems clumsy. The other approach I can think of is to have a
regular action defined which is used to populate the page and a form action
which is used for form submission. This requires two actions for the same
JSP but eliminates some of the funny business with hidden fields.
I guess my question is, how do most people handle the pre-population of
data entry forms.
Thanks.