Smart questions
Smart answers
Smart people
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

Join Tek-Tips
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

LINK TO THIS FORUM!

Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

Partner With Us!

"Best Of Breed" Forums Add Stickiness To Your Site
Partner Button
(Download This Button Today!)

Feedback

"...I also believe that we all can contribute to each other's growth by sharing knowlege and experiences. I would love to take my skills and help people around the world solve problems..."

Geography

Where in the world do Tek-Tips members come from?
jetechie (TechnicalUser)
28 May 06 23:15
I have the following called from a JSP page:

String setI1 = dimA1.getsetI1();
String setI2 = dimA1.getsetI2();
String setI3 = dimA1.getsetI3();
String setI4 = dimA1.getsetI4();

Is there a way I call call these dynically, like in a for loop similiar to this?

for ( int i = 1; i < 5; i++)
{
 String setI + i = dimA1.getsetI + i();
}

I get the following when trying to do this:
Syntax error, insert "AssignmentOperator ArrayInitializer" to complete Expression

Thanks for any advice!
jemminger (Programmer)
29 May 06 0:22
nope - this is one of the benefits of a scripting language like python.

you could perhaps get a similar effect using a Map to store objects with dynamically created keys like "setI" + i, and some clever use of reflection to dynamically call the right method on dimA1

-jeff
www.jeffemminger.com
lost: one sig, last seen here.

Diancecht (Programmer)
29 May 06 4:11
Use an array.

Cheers,
Dian
jetechie (TechnicalUser)
29 May 06 11:06
An array is not going to help me here, because it will treat it as a string.
Diancecht (Programmer)
29 May 06 11:12
huh?

Instead of 5 strings in dim1, define an array of strings.

Cheers,
Dian
jetechie (TechnicalUser)
29 May 06 11:34
Could you provide an example?  I'm not sure how i could get the "dimA1.getsetI1();" to execute from within an array?

Thanks!
JE
Diancecht (Programmer)
29 May 06 12:05
Instead of

CODE

public String getSetI1();

modify your bean

CODE

public String[] getSets();

Cheers,
Dian
jetechie (TechnicalUser)
29 May 06 12:24
Dian,
Currently, my code is like this.  If I remove the following:
public String getsetI1() { return i1; }

How do I get my specific value returned?


---CODE------- (not sure how to mark this as code from teh forum)

package jspBean;
public class dimA {
    
//Indicator 1
String i1;
String i2;

public void setI1( String value )
    {
        i1 = value;
    }

public void setI2( String value )
    {
        i2 = value;
    }

 public String getsetI1() { return i1; }
 public String getsetI2() { return i2; }

}

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close