I suggest using Strut's ActionForm as a helper structure that holds relevant data, in this case we could code like this:
In the Action that extends BaseAction (assuming that base action takes care of redirecting to given functions ):
public ActionForward createNew(ActionMapping mapping, ActionForm actionForm, HttpServletRequest request, HttpServletResponse response) throws Exception {
EventForm form = (EventForm) actionForm;
form.setModeCreate();
form.setEvent( new Event() );
form.setEventTypes( getListOfTypesSomehow() );
return mapping.findForward("crud");
}
public ActionForward saveNew(ActionMapping mapping, ActionForm actionForm, HttpServletRequest request, HttpServletResponse response) throws Exception {
EventForm form = (EventForm) actionForm;
Event evt = form.getEvent( );
eventDao.saveEvent( evt );
form.setModeEdit();
return mapping.findForward("crud");
}
EventForm extends CRUDForm{
Event event;
List eventTypes;
Event Event()....
setEvent()....
....
Integer getEventTypeId(){
getEvent().getEventTYpe().getId();
}
void setEventTypeId( Integer id){
EventType et = findEventTypeInTheListById( id, getEventTypes() );
getEvent().setEventType( et );
}
}
Note that the code assumes that eventTyoe field of the Event is never NULL, if that is nullable then we need guards here and there.
_________________ --------------
Konstantin
SourceLabs - dependable OpenSource systems
|