If you want to convert an integer to a String on the fly, you can do
this:

    /**
     * Return the script as int
     *
     * @return the script as int
     */
    public int getScriptInt() {
        return ( Integer.valueOf(this.script).intValue() );
    }

Assuming the String has been validated first. 

To move the data from one bean to another, you can either use a bulk
setter or constructor

myBean.set( getScriptInt(),getTitle(),getCurrentDate() ); // or
new myBean( getScriptInt(),getTitle(),getCurrentDate() ); 

Or, if your internal bean is designed to accept Strings for incoming
data (as, say, RowSets are), then you could also have the ActionForm
bean generate a hash map that matched your internal bean's mutators with
the populate() method of Struts BeanUtil.

populate(myInternalBean,myActionForm.toMap());

Ryan Cornia wrote:
> 
> Great article!
> 
> I'm fairly new to Struts and am still struggling with ActionForm setters/getters vs. 
>bean setters/getters. In your template file, all properties for both the form and 
>bean are Strings. How would you implement an int property -
> 
> In the form, it would it be -
> public String getProperty10() {
>   return(this.property10);
> }
> 
> public void setProperty10(String property10) {
>   this.property10 = property10;
> }
> 
> public int getProperty10Int() {
>    return this.property10.intValue();
> }
> 
> In the bean, would it be? -
> 
> int property10Int = 0;
> 
> public int getProperty10Int() {
>   return(this.property10Int);
> }
> 
> public void setProperty10Int(int property10) {
>   this.property10Int = property10;
> }
> 
> If this is the case, how do you copy the properties from the FormBean to the Bean 
>when the Action is done and validated?
> 
> MyForm frm = (MyForm)form;
> MyBean bean = <Should the bean be in the session?>;
> 
> /** What if I have 100 properties, is there a better way to set them all? **/
> bean.setProperty0(frm.getProperty0());
> .
> .
> .
> bean.setProperty10Int(frm.getProperty10Int());
> 
> bean.writeToDatabase();
> 
> Is this the best way to mesh all of this together?
> 
> Thanks for all the hard work. It's a very valuable article.
> Ryan
>

Reply via email to