Win a copy of Head First Android this week in the Android forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Rob Spoor
  • Devaka Cooray
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Jj Roberts
  • Al Hobbs
  • Piet Souris

ActionForm contains ArrayList

 
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,

I have a problem with Struts. I have a ArrayList in my ActionForm which is not getting populated when the form is submitted. How do i do this ? Is there any solution ?

Thanks in Advance
 
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You cannot populate an arraylist, instead use a String[] for that property.
Now if you want an arraylist in your action add a simple getter to return an arraylist from the string[] in the formbean.

I think you got what iam saying.
 
Mickey Smith
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Kamesh,

Can you be more clear. Can i get some code here.

Regards,
 
Kamesh Rao
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok let me put in this way.

Say you provide an user an option to select multiple values for an input element(say a list box)

< html:select name="userForm" property="userGroups" size="5" multiple="true" >
< html ptions collection="groupsList" property="groupCode" labelProperty="name" / >

< / html:select >


The property userGroups under the formbean should be declared as String[]

//used by struts
String[] userGroups;
//can be used in the action
List<String> userGroupList =new ArrayList();

public void setUserGroups(String strings[])
{
Collection list = new ArrayList();
for(int i = 0; i < strings.length; i++)
if(strings[i] != null)
{
list.add(strings[i]);
}

setUserGroupList(list);
userGroup = strings;
}
public String[] getUserGroup()
{
return userGroup;
}

public List<String> getUserGroupList(){
return userGroupList;
}

public void setUserGroupList(List<String> groupList){
this.userGroupList=groupList;
}

so whenever the page is rendered struts uses the String[] property and you can use the arraylist property in your action.
[ December 28, 2006: Message edited by: Kamesh Rao ]
 
Ranch Hand
Posts: 502
jQuery Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I read from some where that struts currently allows only String, boolean and Array to be automatically converted into the Action Form properties.
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic