> Hello,
>
> I have a jsp (create.jsp), a form-bean (CreateMessageForm.java), and
> an action (CreateMessageAction.java).
>
> Currently, the user inputs their info into create.jsp, hits 'submit',
> and the action gets the info from the form-bean and does stuff with
> it. Instead, I would like to get some information( collections)
> from a database and populate "create.jsp" with them. So I would like
> to:
>
> - get a collection from the database
> - put this collection into the request
> - populate create.jsp from the request object
> - let the user edit the form (including the pre-populated parts)
> - hit submit
> - CreateMessageAction gets info from form-bean and does stuff...
>
> Do I have to write a separate Action class for putting the collection
> (from database) into the request object? Or can I somehow
> incorporate this into my current CreateMessageAction class ?
I generally create a separate Action, let's call it EditMessageAction,
but either way it's going to need something like this:
int id = getInt(request, "id");
// if id is greater than zero I should get data from a db
if (id > 0) {
// get data from db, this is just an example
Message message = Message.select(id);
// prepopulate the form
form.setProperty(message.getProperty());
form.setAnotherProperty(message.getAnotherProperty());
// alternately use beanutils to prepopulate the form
BeanUtils.copyProperties(form, message);
}
return mapping.findForward("messageForm");
Regarding collections, you would put those in the request scope as you
normally would:
request.setAttribute("myCollection", aCollection);
Then you could use an <html:options/> or other iterative tag/technique
to work with it.
HTH,
- Dave
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]