Why don't you design your bean like this:
If it's a one time set of the collection,then  

public class NestedParentBean extends ActionFormBase{

      private String parentName = null;
      private String parentId = null;
      private java.util.ArrayList childBeanCollection = null;

      public String getParentName() {
        return parentName;
      }
      public void setParentName(String parentName) {
        this.parentName = parentName;
      }
      public String getParentId() {
        return parentId;
      }
      public void setParentId(String parentId) {
        this.parentId = parentId;
      }
      public java.util.ArrayList getChildBeanCollection() {
        return childBeanCollection;
      }
      public void setChildBeanCollection(java.util.ArrayList
childBeanCollection) {
        if (childBeanCollection != null && childBeanCollection.size() >
0) {

          if ( this.childBeanCollection == null)  {
            this.childBeanCollection = new
ArrayList(childBeanCollection.size());
          }

          for (int i = 0; i < childBeanCollection.size(); i++ ) {
            this.childBeanCollection.add(childBeanCollection.get(i));   
          }
        }

      }
}

Else just set the this.childBeanCollection = null before allocating
memory in setChildBeanCollection















-----Original Message-----
From: RAMYA BALA CHIVUKULA Padmanabha [mailto:[EMAIL PROTECTED] 
Sent: Tuesday, December 23, 2003 1:09 AM
To: Struts-User (E-mail)
Subject: Nested Problem.

Hi ,
Can any one solve this problem for me.

I have a Parent Bean of the Structure.

public class NestedParentBean extends ActionFormBase{
  private String parentName;
  private String parentId;
  private java.util.ArrayList childBeanCollection;

  public NestedParentBean() {

    for(int i=0;i<20;i++){
      NestedChildBean nesChldBean = new NestedChildBean();
      childBeanCollection.add(nesChldBean);
    }
  }
  public String getParentName() {
    return parentName;
  }
  public void setParentName(String parentName) {
    this.parentName = parentName;
  }
  public String getParentId() {
    return parentId;
  }
  public void setParentId(String parentId) {
    this.parentId = parentId;
  }
  public java.util.ArrayList getChildBeanCollection() {
    return childBeanCollection;
  }
  public void setChildBeanCollection(java.util.ArrayList
childBeanCollection) {
    this.childBeanCollection = childBeanCollection;



And Child Bean of the Structure


public class NestedChildBean extends ActionFormBase{
  private String childId;
  private String childName;
  public NestedChildBean() {
  }
  public String getChildId() {
    return childId;
  }
  public void setChildId(String childId) {
    this.childId = childId;
  }
  public String getChildName() {
    return childName;
  }
  public void setChildName(String childName) {
    this.childName = childName;
  }
The problem for me now is .. I do not know the number of childBeans that
would be available and I do not want to hardcode as shown above, I'm
able to display in the Jsp.. 

ActionFormBase refers to one of our baseclasses


Can anyone help me out with how to create dynamic reference for the
childBean?


Regards,
Ramya 

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


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

Reply via email to