Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Call JSP Bean Dynmically

Status
Not open for further replies.

jetechie

Technical User
May 23, 2006
15
US
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!
 
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
lost: one sig, last seen here.
 
An array is not going to help me here, because it will treat it as a string.
 
huh?

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

Cheers,
Dian
 
Could you provide an example? I'm not sure how i could get the "dimA1.getsetI1();" to execute from within an array?

Thanks!
JE
 
Instead of

Code:
public String getSetI1();

modify your bean

Code:
public String[] getSets();

Cheers,
Dian
 
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; }

}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top