 |
AppletTalk.com Java discussions newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
alberto Guest
|
Posted: Tue Apr 26, 2005 7:25 pm Post subject: [Struts] impostare le ActionForm |
|
|
Scrivo piu' che altro per chiedere opioni e suggerimenti (ovvero vostri
approcci alternativi al problema).
Tempo fa si era discusso di come inizializzare le ActionForm, ovvero di come
vanno preparate prima della visualizzazione nella JSP.
Il mio approccio era una cosa di questo tipo:
UserForm userForm = new UserForm();
BeanUtils.copyProperties(userForm, user);
request.getSession().setAttribute("userForm", userForm);
....
il problema era l'inconsistenza tra lo scope della form in questo codice e
lo scope dichiarato nel file di configurazione di struts. .
La cosa non mi soddisfa ho provato a implementare un metodo che posiziona la
ActionForm nel posto giusto coerentemente con quando dichiarato in
"struts-config.xml" :
protected void setActionForm(HttpServletRequest request,
String formBeanName, String actionPath, ActionForm form)
throws Exception {
ModuleConfig moduleConfig = (ModuleConfig)
request.getAttribute(Globals.MODULE_KEY);
ActionMapping mapping = (ActionMapping)
moduleConfig.findActionConfig(actionPath);
if (moduleConfig == null) {
moduleConfig = (ModuleConfig) getServlet().getServletContext()
.getAttribute(Globals.MODULE_KEY);
}
if ("request".equals(mapping.getScope())) {
request.setAttribute(formBeanName, form);
} else {
request.getSession().setAttribute(formBeanName, form);
}
}
un esempio di utilizzo é:
UserForm userForm = new UserForm();
.....
setActionForm(request, "/user-save", userForm);
....
Come potete vedere però il problema si é solo spostato (o forse é
addirittura peggiorato) perché nasce una nuova potenziale inconsistenza con
il nome della Action che riceverà il Form.
Come considerate questo secondo approccio?
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|