• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

loading parameters in a loop

 
Dalibor Toth
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
 
Manfred Leonhardt
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic