Robert, I followed your advices. Your code works very well. I have successfully inserted all the values of my bean properties into the database. Thank you very much. --- Robert Taylor <[EMAIL PROTECTED]> wrote: > The same problem exists, you are calling getters on > a ThreadBean instance > which has not yet been populated. > > > Below three ways to accomplish your goal: > > METHOD 1: > Try this (proxy): > > public final class ThreadHandler { > > MessageDAO md = new MySQLMessageDAO(); > > public int insertThread(ThreadBean bean) > throws throws MessageDAOSysException, > ObjectNotFoundException { > > int identity = 0; > > md.createThread(bean.getReceiver(), > bean.getSender(), > bean.getThreadTopic(), > bean.getThreadBody(), > bean.getThreadCreationDate(), > bean.getThreadViewCount(), > bean.getThreadReplyCount()); > > // get identity > > return identity; > > } > > > } > > ThreadBean bean = new ThreadBean(); > BeanUtils.copyProperties(bean, postForm); > ThreadHandler th = new ThreadHandler() > th.insertThread(bean); > > If you do it this way, then it would be better if > ThreadHandler was a > singleton, > but that's a different discussion :) > > > > > METHOD 2: > Another way to do it (design by composition). > > public final class ThreadHandler { > > MessageDAO md = new MySQLMessageDAO(); > ThreadBean bean; > > public ThreadHandler(ThreadBean bean) { > > this.bean = bean; > > } > public int insertThread() > throws throws MessageDAOSysException, > ObjectNotFoundException { > > int identity = 0; > > md.createThread(bean.getReceiver(), > bean.getSender(), > bean.getThreadTopic(), > bean.getThreadBody(), > bean.getThreadCreationDate(), > bean.getThreadViewCount(), > bean.getThreadReplyCount()); > > // get identity > > return identity; > > } > > > } > > ThreadBean bean = new ThreadBean(); > BeanUtils.copyProperties(bean, postForm); > ThreadHandler th = new ThreadHandler(bean) > th.insertThread(); > > > METHOD 3: > Yet another way via classic inheritance: > > public final class ThreadHandler > extends ThreadBean { > > MessageDAO md = new MySQLMessageDAO(); > > > public ThreadHandler() { > > super(); > > } > public int insertThread() > throws throws MessageDAOSysException, > ObjectNotFoundException { > > int identity = 0; > > md.createThread(this.getReceiver(), > this.getSender(), > this.getThreadTopic(), > this.getThreadBody(), > this.getThreadCreationDate(), > this.getThreadViewCount(), > this.getThreadReplyCount()); > > // get identity > > return identity; > > } > > > } > > ThreadHandler th = new ThreadHandler(); > BeanUtils.copyProperties(th, postForm); > th.insertThread(); > > > > hth, > > robert > > > > -----Original Message----- > > From: Caroline Jen [mailto:[EMAIL PROTECTED] > > Sent: Thursday, January 08, 2004 11:48 AM > > To: Struts Users Mailing List > > Subject: RE: All The Bean Properties Are Null in > the Business Tier!!! > > (Used BeanUtils to Convert DynaValidatorForm) > > > > > > Thank you for your comment, which is very helpful. > > > > Instead of extends ThreadBean, I now import the > > ThreadBean into my ThreadHandler class (see the > code > > below). I am still getting all null or zero values > > from the bean. > > > > What is the proper way to do it? I simply want to > > insert the value of all the properties into the > > database. Most of the fields in my database > require > > NOT NULL. > > > > code: > > ================================================== > > import org.apache.artimus.message.ThreadBean; > > > > class ThreadHandler > > { > > ThreadBean threadBean = new ThreadBean(); > > > > String receiver = threadBean.getReceiver(); > > String sender = threadBean.getSender(); > > String threadTopic = threadBean.getPostTopic(); > > String threadBody = threadBean.getPostBody(); > > Timestamp threadCreationDate = > > threadBean.getThreadCreationDate(); > > int threadViewCount = > > threadBean.getThreadViewCount(); > > int threadReplyCount = > > threadBean.getThreadReplyCount(); > > > > MessageDAO md = new MySQLMessageDAO(); > > public int insertThread( ThreadBean threadBean > ) > > throws > MessageDAOSysException, > > > > > ObjectNotFoundException > > > > { > > System.out.println( "The sender is " + > sender + > > "." ); > > System.out.println( "The subject is " + > > threadTopic + "." ); > > System.out.println( "The creation date is " > + > > threadCreationDate ); > > System.out.println( "The number of replies > are === message truncated ===
__________________________________ Do you Yahoo!? Yahoo! Hotjobs: Enter the "Signing Bonus" Sweepstakes http://hotjobs.sweepstakes.yahoo.com/signingbonus --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]