• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

loading parameters in a loop

 
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK, I have an applet and html file with an applet tag that calls that applet together with some parameters. I need to fetch those parameters dinamicaly, since there might be different number of them. For instance, each parameter could be a sentence, but somethimes there could be 5 of them and the other time, say, 10. Each time my applet needs to know how many of them there is and fatch them all.
I tried naming parameters something like 1,2,3... but to fatch them in a for loop, I first need to know how many of them there are.
for (i = 1; i < ???; i++) {
getParameter into array
}
Thanks!
Sorry for the f... long letter.
Dalibor
 
Ranch Hand
Posts: 1492
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Dalibor,
If you go with your naming convention you could just use a while loop and a collection. For example:
Vector itemCollection = new Vector();
String item = getParameter( 1 );
int itemNumber = 1;
while( item != null and item.length() > 0 )
{
itemCollection.add( item );
item = getParameter( itemNumber++ );
}
Regards,
Manfred.
 
Dalibor Toth
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear Manfred,
Thanks for your code, it seems OK. I'll try it. BTW, my naming convention is not an obligation, it was just a thought, so if you, or anybody else have any other idea, please let me know.
Thanks!
 
Manfred Leonhardt
Ranch Hand
Posts: 1492
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Dalibor,
Unfortunately if you don't make your naming convention an obligation then your applet can not work. The getParameter method requires a name String as input.
The only alternative is to have a comma delimited string as first parameter with the names of all the following parameters. For example:

Regards,
Manfred.
 
That which doesn't kill us makes us stronger. I think a piece of pie wouldn't kill me. Tiny ad:
Devious Experiments for a Truly Passive Greenhouse!
https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
    Bookmark Topic Watch Topic
  • New Topic