AppletTalk.com Forum Index AppletTalk.com
Java discussions newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

[Struts] impostare le ActionForm

 
Post new topic   Reply to topic    AppletTalk.com Forum Index -> Java (Italian)
View previous topic :: View next topic  
Author Message
alberto
Guest





PostPosted: Tue Apr 26, 2005 7:25 pm    Post subject: [Struts] impostare le ActionForm Reply with quote



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
Display posts from previous:   
Post new topic   Reply to topic    AppletTalk.com Forum Index -> Java (Italian) All times are GMT
Page 1 of 1

 
Jump to:  
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


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.