Meaningless Drivel is fun!*
The moose likes Servlets and the fly likes storing array in beans???? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "storing array in beans????" Watch "storing array in beans????" New topic
Author

storing array in beans????

raymond yadao
Ranch Hand

Joined: Jan 29, 2001
Posts: 88
is it possible to store an array in a beans???
for example
public class sample
{ protected String[] try;
public sample() {}
public void setTry(String[] sValue)
{ for (int i=0; i>sValue.length; i++)
{ try[i] = sValue[i] }
}
public String[] getTry()
{ return try[]; } }

in the getTry(), how would i return the array???

thanks in advance!!!
raymond
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12806
    
    5
There is no need to create a second String array, as in:
"public void setTry(String[] sValue)
{ for (int i=0; i>sValue.length; i++)
{ try[i] = sValue[i] }
}
public String[] getTry()
{ return try[]; } }
"
/* which would not work since you have not created try = new String[ sValue.length ] ;
*/
Just set try = sValue ;
When executing getTry, just use code like:
String[] str = X.getTry();
Bill

------------------
author of:
raymond yadao
Ranch Hand

Joined: Jan 29, 2001
Posts: 88
hi!!!
how would i do that???

protected String[] try;

public void setTry (String sValue)
{ try = sValue; }
public String getTry()
{
String[] try = x.getTry();
// should i declare x???
}
or i would be better if you could write the complete code for me
thanks.
raymond
raymond yadao
Ranch Hand

Joined: Jan 29, 2001
Posts: 88
hi.
it would be better if you provide the code for me.

thanks.
raymond
Marcos Maia
Ranch Hand

Joined: Jan 06, 2001
Posts: 977
As long try is already a string array(isn�t it a reserved word from the try catch block, I think so, you should change the variable�s name)you only have to return the reference without the []�s.
public String[] getTry()
{
return try;
}
raymond yadao
Ranch Hand

Joined: Jan 29, 2001
Posts: 88
yeah, its okay now. i in the set method i just use fname = sValue ( i change try to fname) and in the get method i just return fname.
my problem right now is when i use this bean and set the value in jsp
myBean.setFname("a","b");
it display an error message wrong number of arguments. why is this so? in the myBeans the set method is
public void setFname(String[] sValue)
{ fname = sValue; }

thanks.
raymond
Gene Tucker
Greenhorn

Joined: Aug 17, 2001
Posts: 4
Hi, Raymond: I have been reading your thread. Would you let me know in the statement
String[] fname = X.getFname();
what this X is? Thanks.
 
wood burning stoves
 
subject: storing array in beans????