Allow me to ask three more questions: 

1. If I want to reset some specific text fields when
the JSP is re-displayed, do I code the PostForm.java
like this (please confirm):

code:
-----------------------------------------------------
import org.apache.struts.validator.DynaValidatorForm;
import org.apache.struts.action.ActionMapping;
import javax.servlet.http.HttpServletRequest;
public class PostForm extends DynaValidatorForm  
{
   public void reset(ActionMapping mapping,
HttpServletRequest request)
   {
      super.reset( mapping, request );
      set( "receiver", new String("") );
      set( "sender", new String("") );
   }
   public PostForm () {}
}
-------------------------------------------------------

2. if I want to reset all the text fields when the JSP
is re-displayed, do I code like this (please confirm):

code:
-------------------------------------------------------
import org.apache.struts.validator.DynaValidatorForm;
import org.apache.struts.action.ActionMapping;
import javax.servlet.http.HttpServletRequest; 

public class PostForm extends DynaValidatorForm  
{   
   public void reset(ActionMapping mapping,
HttpServletRequest request)       
   {
       initialize( mapping );
   }
   public PostForm () {}
}
------------------------------------------------------


3. What is the difference between 

code:
-------------------------------------------------------
<form-bean      
   name="postForm"          
   type="package.package.package.PostForm">           
      <form-property  
          name="receiver"  
          type="java.lang.String"/>     
      <form-property    
          name="sender"   
          type="java.lang.String"/>     
</form-bean>
-------------------------------------------------------

AND

code:
------------------------------------------------------
<form-bean 
   name="postForm"            
type="org.apache.struts.validator.DynaValidatorForm"> 
      <form-property            
          name="receiver"             
          type="java.lang.String"/>
      <form-property   
          name="sender" 
          type="java.lang.String"/>
</form-bean>
---------------------------------------------------

Thank you very much.

--- Joe Hertz <[EMAIL PROTECTED]> wrote:
> Not at all.
> 
> First off, set(String, String) is predefined for
> you. You don't need to 
> create any of that. In fact, what you will find in a
> DynaValidatorForm is 
> that your form classes start to get very sparse.
> Here's really what it could 
> look like.
> 
> 
> public class PostForm extends BaseDynaForm {
> 
> 
>   public void reset(ActionMapping actionMapping,
> HttpServletRequest 
> httpServletRequest) {
>       // throw new UnsupportedOperationException("Method
> is not 
> implemented");
>       }
> 
>     public PostForm () {
>    }
> 
> 
> }
> 
> In your ActionForm itself, beanUtils would work
> something like this. All you 
> need is to get the right formBean object. 
> 
>   public ActionForward  execute(ActionMapping
> mapping, ActionForm form, 
> HttpServletRequest request, HttpServletResponse
> response) throws Exception {
> 
>               PostForm pForm = (PostForm) form;
> 
>                // other code you write here
> 
>               BeanUtils.copyProperties(yourBean, pForm);
> 
> // etc
> 
> Doing it yourself without beanUtils?
> 
> Instead of calling getSender() and having a String
> returned, you call get
> ("sender") and it will return an Object (cast it
> yourself to whatever type 
> the sender form property really is). I made a base
> form class with a 
> getString method that calls get() and does the
> String cast for me to save the 
> tediom.
> 
> Making sense now?
> 
> > -----Original Message-----
> > From: Caroline Jen [mailto:[EMAIL PROTECTED] 
> > Sent: Sunday, January 04, 2004 2:46 AM
> > To: Struts Users Mailing List
> > Subject: RE: Please Help - ClassCastException
> > 
> > 
> > I am still confused...
> > 
> > I have a jsp that provides text fields for user to
> > fill out information.  All the information is
> passed
> > via HttpRequest and to be validated.  And all the
> > properties in my PostForm are populated by the
> > information retrieved from those text fields.
> > 
> > And my PostForm is of 
> >
>
type="org.apache.struts.validator.DynaValidatorForm">
> > 
> > Therefore, in my PostForm.java, I should do
> something
> > like this?  I just do not think the following code
> is
> > correct.
> > 
> >
>
======================================================
> > import
> org.apache.struts.validator.DynaValidatorForm;
> > 
> > public class PostForm extends DynaValidatorForm  {
> >  
> >     private String receiver;
> >     private String sender;
> >     
> >     public void set(String receiver, String
> receiver);
> >     public void set(String sender, String sender);
> 
> >     public String get(String receiver, String
> > receiver);
> >     public String get(String sender, String
> sender); 
> > }
> >
>
======================================================
> > And you are saying that in my action class, I
> should
> > 
> > .......
> > import org.apache.struts.action.Action;
> > import org.apache.struts.action.ActionForward;
> > import org.apache.struts.action.ActionMapping;
> > import org.apache.struts.action.ActionForm;
> > 
> > import org.apache.commons.beanutils.BeanUtils;
> > import javax.servlet.http.HttpServletRequest;
> > import javax.servlet.http.HttpServletResponse;
> >  
> > import org.apache.artimus.message.PostForm;
> > import org.apache.artimus.message.PostBean;
> > import org.apache.artimus.message.ThreadBean;
> > import
> org.apache.artimus.message.utility.DateUtil;
> > 
> > public final class StoreMessage extends Action
> > {
> >    public ActionForward execute(ActionMapping
> mapping,
> >                                 ActionForm form,
> >                                 HttpServletRequest
> >  request, 
> >                                
> HttpServletResponse
> >  response)
> >         throws Exception 
> >    {
> >  
> >       int parentPostID;
> >       int threadID;
> >       String memberName = request.getRemoteUser();
> >       Timestamp now =
> >  DateUtil.getCurrentGMTTimestamp();
> >       parentPostID = Integer.parseInt(
> >  request.getParameter( "parent" ) );
> >  
> >       ActionForm postForm = ( ActionForm )form;
> >  
> >       ThreadHandler thandler = new
> ThreadHandler();
> > 
> >       ThreadBean threadBean = new ThreadBean();
> >       BeanUtils.copyProperties( threadBean,
> postForm
> > );
> > 
> >       if (parentPostID == 0 ) // new topic
> >       {
> >          threadBean.setLastPostMemberName(
> memberName
> > );
> >          threadBean.setThreadCreationDate( now );
> >          .........
> >          .........
> >   
> >          threadID = thandler.insertThread(
> threadBean
> > );
> >  
> >       }
> >    .......
> >    .......
> >    }
> > }
> > 
> > --- Joe Hertz <[EMAIL PROTECTED]> wrote:
> > > Well, first off:
> > > 
> > > In your (dyna) form, you don't create setters
> and
> > > getters for the properties
> > > though. With DynaForms you would say
> > > set("myPropertyName", "myString") 
> > > instead of calling
> setMyPropertyName("myString").
> > > This is the Dyna part of 
> > > DynaForms. It's much less tedious IMHO.
> > > 
> > > In your action, you absolutely want to cast the
> form
> > > to PostForm. Otherwise
> > > the form variable has no way to know properties
> are
> > > associated with it. So 
> > > yes, once you cast it to PostForm calls to
> > > BeanUtils.copyProperties() can and 
> > > will work properly.
> > > 
> > > Hope this helps,
> > > 
> > > -Joe
> 
=== message truncated ===


__________________________________
Do you Yahoo!?
Protect your identity with Yahoo! Mail AddressGuard
http://antispam.yahoo.com/whatsnewfree

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to