You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Will Spies/Towers Perrin <sp...@towers.com> on 2001/04/05 16:12:57 UTC

struts populating ActionForm behavior

My ActionForm contains another JavaBean along with native types. For
example:

public class MyForm extends ActionForm
{
public void setString( String str);
public String getString( );

public void setData( MyObject str);
public MyObjectg getData();

}

I have this working fine right now but the way I got it to work was by
making sure the object (MyObject) is NOT initialized to null inside MyForm.
For example, the following are two examples. The first one fails and the
second one works. By failing I mean struts will not create and fill the
MyObject attribute of the form form the JSP due to it being null :

public class MyForm extends ActionForm
{
private  String str = null;
private  MyObject obj = null;

public void setString( String str);
{
  this.str = str;
}

public String getString( )
{
return str;
}

public void setData( MyObject obj )
{
this.obj = obj;
}
public MyObjectg getData();
{
return obj;
}

}

However, this code works:

public class MyForm extends ActionForm
{
private  String str = null;
private  MyObject obj = new MyObject();

public void setString( String str);
{
  this.str = str;
}

public String getString( )
{
return str;
}

public void setData( MyObject obj )
{
this.obj = obj;
}
public MyObjectg getData();
{
return obj;
}

}

This latter code works due to the initialization of MyObject to a non-null
object.

Is this the expected/correct behavior or am I doing something wrong??

Thanks,

Will