aspose file tools*
The moose likes Struts and the fly likes How to populate values in a <s:select> tag from database? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "How to populate values in a <s:select> tag from database?" Watch "How to populate values in a <s:select> tag from database?" New topic
Author

How to populate values in a <s:select> tag from database?

Jyothsna Panchagnula
Ranch Hand

Joined: Jul 11, 2005
Posts: 113
Hi all,

I have to retrieve list of statesfrom the database and populate it in the drop down on load of the page.

Sample Jsp page


sample Action class


sample UserRegistrationActionform


I see the following error when the page is loaded
java.lang.IndexOutOfBoundsException: Index: 1, Size: 1
java.util.ArrayList.RangeCheck(Unknown Source)
java.util.ArrayList.get(Unknown Source)

Can any one tell me where am I going wrong

Thanks,
Jyothsna
Bilal A. Siddiqui
Ranch Hand

Joined: Sep 14, 2008
Posts: 53

Hi jyotsna,

It seems your indexoutofbound exception is coming due to the declaration of your index=1. Make it index=0 and it will run fine. If this part is running fine we can move forward with populating issue.

Cheers !!!
Bilal


Cheers!!! Bilal
Handsome Android||@bilal_speed||LinkedIn
Jyothsna Panchagnula
Ranch Hand

Joined: Jul 11, 2005
Posts: 113
Hi Bidal,


I did change the index from 0 to 1 as it was giving out of bounds exception.
I am not able to figure out whats wrong with the code

is there any other way to populate the data into a drop down from java class.



thanks,
Jyothsna
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

What version of Struts are you actually using? Your subject says "<s:select>", which is Struts 2, while all your code implies Struts 1.

I'm a bit confused on some of your code:Note that I've gone ahead and made the code readable--it's nice to take care when posting and make sure that it has posted the way you expect it to.

Why do you create empty array lists then immediately assign new values? There's no reason to create the list if you just overwrite the value a line or two later.

If your array is of size 1 then there is no element at index 1--Java indexes arrays and lists starting with index 0.

The appendList() method is creating a list of ActionForms--this is almost *certainly* not what you want, unless I'm completely misunderstanding the code--in which case the code should probably be cleaned up to better express its intent.

Your stack traces would be more valuable if (a) they were complete, and (b) you were compiling with debug information so it would include the line number of where the exception took place--pointing to the middle of Java code doesn't help us determine where *your* code is at fault.

Your JSP fragment involves a "stateList" while your Java fragment shows a "countryList"--this is an additional layer of confusion. Please narrow down the problem to one or the other and post the current code, properly escaped, with more useful error information.s
Shailesh Narkhede
Ranch Hand

Joined: Jul 10, 2008
Posts: 365
Why don't you use Iterater on ArrayList simply,
Instead of writing separate logic.
That is better I guess.



Thanks,
Shailesh
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to populate values in a <s:select> tag from database?
 
Similar Threads
parsing data and storing in the xml
JspException: Failed to obtain specified collection for Struts:optionscollection
How to use html:options
Cannot find bean in any scope
How to display a list box with values from an "Array List" in "Struts2"