You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Alex Colic <al...@pop-ware.com> on 2001/04/27 16:17:48 UTC

How to iterate to create select box.

Hi,

I am trying to iterate through a vector to populate a select box.

I have a class CategoryList in application scope that holds a list of
Categories. Each category has a CategoryGroup name and a vector of
CategoryValues.

At run time I am trying to create a page that dynamically creates the above
select boxes not knowing how many elements will be in the list.

I can iterate through the CategoryGroupName via:

<logic:iterate id="category" name="CategoryList" property="categoryList"
scope="application">
  <bean:write name="category" property="categoryGroup" filter="true"/>

<!--need to figure out how to create select box -->

</logic:iterate>

Any help in figuring this out is appreciated.

My category class is as follows:

public class pwCategory
{

  private String categoryGroup;
  private String categoryName;
  private String categoryAbrv;
  private int categoryNumber;
  private String categoryValue;
  java.util.Vector categoryValues;

  public pwCategory()
  {
  }

  public String getCategoryGroup()
  {
    return categoryGroup;
  }

  public void setCategoryGroup(String newCategoryGroup)
  {
    categoryGroup = newCategoryGroup;
  }

  public void setCategoryAbrv(String newCategoryAbrv)
  {
    categoryAbrv = newCategoryAbrv;
  }

  public String getCategoryAbrv()
  {
    return categoryAbrv;
  }

  public void setCategoryNumber(int newCategoryNumber)
  {
    categoryNumber = newCategoryNumber;
  }

  public int getCategoryNumber()
  {
    return categoryNumber;
  }

  public void setCategoryValue(String newCategoryValues)
  {
    categoryValue = newCategoryValues;
  }

  public String getCategoryValue()
  {
    return categoryValue;
  }

  public void setCategoryValues(java.util.Vector newCategoryValues)
  {
    categoryValues = newCategoryValues;
  }

  public java.util.Vector getCategoryValues()
  {
    return categoryValues;
  }
}

My categoryList class is as follows:


import java.util.*;
import com.popware.avantis.*;

public class pwCategoryList
{
  private List categoryList=new Vector();

  public pwCategoryList()
  {
  }

  public List getCategoryList()
  {
    return categoryList;
  }

  public void setCategoryList(List categoryList)
  {
    this.categoryList = categoryList;
  }

  public void addCategoryList(pwCategory newCategory)
  {
    categoryList.add(newCategory);
  }
}

Regards

Alex


Re: How to iterate to create select box.

Posted by Rajan Gupta <rg...@yahoo.com>.
How is scope valid, the documentation says that scope is a valid tag
attribute, but looking at the IterateTag.java I could not find such an
attribute. Am I missing something?
--- Alex Colic <al...@pop-ware.com> wrote:
> Hi,
> 
> I am trying to iterate through a vector to populate a select box.
> 
> I have a class CategoryList in application scope that holds a list of
> Categories. Each category has a CategoryGroup name and a vector of
> CategoryValues.
> 
> At run time I am trying to create a page that dynamically creates the
> above
> select boxes not knowing how many elements will be in the list.
> 
> I can iterate through the CategoryGroupName via:
> 
> <logic:iterate id="category" name="CategoryList" property="categoryList"
> scope="application">
>   <bean:write name="category" property="categoryGroup" filter="true"/>
> 
> <!--need to figure out how to create select box -->
> 
> </logic:iterate>
> 
> Any help in figuring this out is appreciated.
> 
> My category class is as follows:
> 
> public class pwCategory
> {
> 
>   private String categoryGroup;
>   private String categoryName;
>   private String categoryAbrv;
>   private int categoryNumber;
>   private String categoryValue;
>   java.util.Vector categoryValues;
> 
>   public pwCategory()
>   {
>   }
> 
>   public String getCategoryGroup()
>   {
>     return categoryGroup;
>   }
> 
>   public void setCategoryGroup(String newCategoryGroup)
>   {
>     categoryGroup = newCategoryGroup;
>   }
> 
>   public void setCategoryAbrv(String newCategoryAbrv)
>   {
>     categoryAbrv = newCategoryAbrv;
>   }
> 
>   public String getCategoryAbrv()
>   {
>     return categoryAbrv;
>   }
> 
>   public void setCategoryNumber(int newCategoryNumber)
>   {
>     categoryNumber = newCategoryNumber;
>   }
> 
>   public int getCategoryNumber()
>   {
>     return categoryNumber;
>   }
> 
>   public void setCategoryValue(String newCategoryValues)
>   {
>     categoryValue = newCategoryValues;
>   }
> 
>   public String getCategoryValue()
>   {
>     return categoryValue;
>   }
> 
>   public void setCategoryValues(java.util.Vector newCategoryValues)
>   {
>     categoryValues = newCategoryValues;
>   }
> 
>   public java.util.Vector getCategoryValues()
>   {
>     return categoryValues;
>   }
> }
> 
> My categoryList class is as follows:
> 
> 
> import java.util.*;
> import com.popware.avantis.*;
> 
> public class pwCategoryList
> {
>   private List categoryList=new Vector();
> 
>   public pwCategoryList()
>   {
>   }
> 
>   public List getCategoryList()
>   {
>     return categoryList;
>   }
> 
>   public void setCategoryList(List categoryList)
>   {
>     this.categoryList = categoryList;
>   }
> 
>   public void addCategoryList(pwCategory newCategory)
>   {
>     categoryList.add(newCategory);
>   }
> }
> 
> Regards
> 
> Alex
> 


__________________________________________________
Do You Yahoo!?
Yahoo! Auctions - buy the things you want at great prices
http://auctions.yahoo.com/