If you are new to struts I suggest you download community edition(free)of struts called strutsstudio from www.strutsstudio.com. It is the best of the lot ( in my opinion)because this particular company is focusing on building an IDE for struts framework AS IS. Unlike alot of these other vendors who want to give you everything and you will waste your life time working out which framework you should use.
There are three ORM frameworks which I know of which are being used alot with struts when using databases with struts. you can find two of them at http://db.apache.org OJB & Torque. OJB - is an Object/Relational mapping tool that allows transparent persistence for Java Objects against relational databases. http://db.apache.org/ojb Torque - I am personally favouring cayenne from www.objectstyle.org. Incidently struts is also developed at apache.org. As these vendors don't have technical skills or expertise to build their own framework, why use a cut & pasted one and pay for the pleasure of buggy & outdated framework. --- Jan_Aren� <[EMAIL PROTECTED]> wrote: > Thanks for your response, I will get right on it... > And ttry to figure > it out... > > Have some questions though... > > I get the idea of the listener, but if you populate > it with stuff from a > database, this would be wrong I guess, since this > collection never > updates (except when you restart you application). > So what you do here > is to create a constant (based on stuff when the > aplication starts)... > Or did I get i wrong? > > > > If i'm not going to do the listner "thing", since my > list must refresh > from database once and awile... Where do I put the > Colloction creating > code, say this: > > Collection coll = new ArrayList(); > for(int i = 0; i < 10; i++) { > b = new LabelValueBean("1",1); > coll.add(b); > } > request.setAttribute("MY_LIST", coll); > > > > And when I do this on my jsp-page: > > <html:select property="selectedValue" value="-1"> > <html:options collection="MY_LIST" property="value" > labelProperty="label" /> > </html:select> > > Do "value" and "label" represent a getValue() and > getLabel() function in > LabelValueBean? > > > Thanks again for your response, cleared up alot in > my head :D > > /Jan > > -----Ursprungligt meddelande----- > Fr�n: A mailing list about Java Server Pages > specification and reference > [mailto:[EMAIL PROTECTED] F�r Christian > Bollmeyer > Skickat: den 20 oktober 2003 21:01 > Till: [EMAIL PROTECTED] > �mne: Re: Struts question > > > Am Montag, 20. Oktober 2003 15:29 schrieb Jan Aren�: > > Hi > > Hi Jan, > > > I'm learning Struts at the moment and just > finished a very easy > > example. Now when I want to extend it I don't know > for sure where to > > put it, or if I have missunderstood something. > > > > I'm also new to taglibs. So i don't know exacly > how they work either, > > but I think I start to get a hang of it > > > > I have inputpage with ActionForm and > Action-servlets > > There is only one ActionServlet. You surely mean > Struts Actions? > > > On my input page i have 2 fields at the moments, > destination and type. > > > These fields are validated and errormessages are > returned as they > > should etc etc. When validated I go to page2.jsp > that writes "Hello > > World" > > > > Ok. Heter is my problem. > > I now want to change my destination from a > inputform <html:text> to a > > selectbox <html:select>. And I would like to > populate it with a Vector > > > that I shall get from a database. > > First of all: Struts most elegantly supports this > via the <html:options> > tag. You might also want to have a look at the > <html:optionsCollection> > tag. Both are very flexible. The basic idea is that > you populate your > select box with values coming from a Bean. The > selected value then is > passed via the <html:select> property. The > Collection itself can be put > in any scope (request, session, application). For > static lists, as may > be your case as well, I usually use a Listener to > put everything in > application scope when the app starts. Here comes an > code snippet of a > very basic listener: > > package listeners; > > import java.util.*; > import javax.servlet.*; > import PersistenceFacade; // some Singleton DAO > class that does the JDBC > part > > public class ResourceListener implements > ServletContextListener { > > public void > contextInitialized(ServletContextEvent e) { > Collection coll = > PersistenceFacade.getInstance().getSomeList(); > > e.getServletContext().setAttribute("MY_LIST", coll); > } > > public void contextDestroyed(ServletContextEvent > e) { > ((ServletContext) > e.getServletContext()).removeAttribute("MY_LIST"); > } > > The Collection itself is usually an ArrayList built > from LabelValueBeans > (org.apache.struts.util) as follows > (note: code heavily simplified here for sake of > brevity) - > your DAO that does the database access might > look like this somewhere (though I prefer the iBATIS > Database Layer recently, credits to Ted Husted who > pointed me there (www.ibatis.com)): > > [..] > Collection coll = new ArrayList(); > while (rs.next()) { > b = new > LabelValueBean(rs.getString(<LABEL_COLUMN_NAME>), > > rs.getString(<VALUE_COLUMN_NAME>)); > coll.add(b); > } > return coll; > > So you finally have your your list stored in some > scope. Now, in the JSP > page, you can just put something like this: > > <html:select property="selectedValue" value="-1"> > <html:options collection="MY_LIST" property="value" > labelProperty="label" /> > </html:select> > > When the users selects something, it ends up in the > 'selectedValue' > property of your ActionForm. You can specify a > default value ("-1" in > this case) by setting the 'value' property of > <html:select>. > > > Earlier (before struts) I would create a bean > conn. Then call : > > > > conn.createDBConnection(); > > If your server allows, don't use DriverManager > anymore, > but make use of DataSources and use JNDI to locate > it. Some more code in this direction: > > private DataSource getDataSource() { > DataSource ds = null; > try { > Context ctx = new InitialContext(); > ds = (DataSource) > ctx.lookup(Constants.SC_JNDI_DATASOURCE); > } catch (NamingException e) { > log(e.getMessage()); } > return ds; > } > > If you have luckily got a DataSource, it's easy to > get > === message truncated === ________________________________________________________________________ Want to chat instantly with your online friends? Get the FREE Yahoo! Messenger http://mail.messenger.yahoo.co.uk =========================================================================== To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST". For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST DIGEST". Some relevant archives, FAQs and Forums on JSPs can be found at: http://java.sun.com/products/jsp http://archives.java.sun.com/jsp-interest.html http://forums.java.sun.com http://www.jspinsider.com
