(Sorry for not replying till now. Been out of the office for a couple of days)
It sounds like what you need to do would be to implement a struts PlugIn that reads the initial values from the database and creates beans containing this information. (These beans could in fact be instances of the ActionForm class they are intended as default values for). You store these default value beans in the servlet context. You will still need to copy the properties from these beans to the actual ActionForm that you are using however, and you only wish to do this once (after the form is created). The logical place to do this would be in the action that you go through before forwarding to the JSP for the first time. (Its considered best to always go through an action first and not have hyperlinks that go directly to .jsp files. Indeed most struts developers will hide the jsps under WEB-INF to stop them being accessible without first hitting an action). You may wish to make use of BeanUtils.copyProperties() method to simplify this step. Its javadoc is here: http://jakarta.apache.org/commons/beanutils/api/org/apache/commons/beanutils /BeanUtils.html Since your copying from the beans you created at startup in the plugin, no extra db calls are involved so there wont be an efficiency issue. The other place I mentioned you could initialise the values in the new actionform instance was in the reset() method. Struts will call this method after instantiating the form instance and before populating it. (Im not sure if it calls it when the form tag causes an instance to be instantiated - but it will get called if its an action you are hitting). You could set a private flag in the ActionForm to keep track of whether this is the first time it is reset or not, and if it is, have code in the reset method look up the default values from the beans in the servlet context. If not the first time, then just do the normal reset type stuff. This however is not as good a solution as simply copying the properties in the action before going to the view. -----Original Message----- From: Curtney Jacobs [mailto:[EMAIL PROTECTED] Sent: Tuesday, 12 August 2003 00:39 To: Struts Users Mailing List Subject: Re: UPON APPLICATION STARTUP!!!!!!!!!!!!!!!! Thanks Nathan, Andrew. I am sorry that my earliler post was not specific and a little bit on the "sassy" side. Yes. My forms are session mapped forms and I will be getting the default values from my database. Andrew, the reason why I decided not use an action to load the default values in the forms is that this would be a query to the database *everytime*. Since, theses default values are static (will never change), I thought it makes more sense to load then upon application startup and have it within the current session. Oops, they should span accross multiple sessions, therefore, as you and Nathan suggested they should be put within the servlet context. Andrew, can you elaborate a littile bit more on the ActionForm reset issue that you mentioned? Thanks. _CJ On Sunday 10 August 2003 11:08 pm, Andrew Hill wrote: > Yeh alright mate. Keep ya hair on and enough with the shouting already! > > Since the forms are only instantiated when a request for that mapping comes > in its gonna be kinda hard to prepopulate values on them cos they dont > exist yet. Indeed unless you are using session mapped forms (such as for a > multipage wizard or such like) the form is only going to exist for the > scope of the request. > > Now Im assuming that you need to read these default values from somewhere > (which must be why you dont just slap em into the form constructors > directly). Since they dont change while the app is running (another > assumption your post didnt bother clarifying) your best bet would be to > read them into some kind of config objects (perhaps even a 'prototype' > instance of the forms in question) and store these in the servlet context. > Implement a struts plugin to do this at startup time. > > You could initialise the values in the form instance from these config > objects in the reset method. Dont forget to do this only on the first reset > (or you will overwite input). > > I reckon you would be best off doing as you were advised and copying the > defaults into the form in an action though rather than overloading the > reset method for this purpose. > > As for the lists of selectable choices in things such as drop downs - that > would best be left as shared beans in servlet scope (like Nathan says in > his reply to your post) - you would only want to copy values into the form > instance for defaults for stuff, as you can have your tags access the > shared beans directly for such tasks as rendering options in selects... > > > -----Original Message----- > From: Curtney Jacobs [mailto:[EMAIL PROTECTED] > Sent: Monday, 11 August 2003 13:46 > To: Struts Users Mailing List > Subject: UPON APPLICATION STARTUP!!!!!!!!!!!!!!!! > > > Greetings! > > I would like to load default values in my forms upon application startup. > Is this possible with STRUTS? Seriously, is this possible with STRUTS? If > not, I > will have to look some where else for this. > > Many of my forms have drop down list that enables the user to choose the > appropriate values. It would be nice that UPON APPLICATION STARTUP forms > that > need default values are automatically populated with said values. > > I am aware that I can call an action that can prepopulate my forms with > those > values. However, it seems tedious to always call an action to populate a > form > with default values. > > Has anyone done this before, if so, I would greatly appreciate some > assistance. > > > This is like the upteen post concerning this. I find it hard that no one > else > needs this or has done this. > > Regards, > > Curtney > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]