• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

Using Struts 2 Select Tag for dynamic values

 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I have an ArrayList which contains String[] array objects. How do i display a selected object using Struts 2 select tag?

Eg:



How do i access the 1, Apple using from the dropdown.

Thanks.
 
Sheriff
Posts: 9709
43
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Abdul I don't think that code will compile. You are storing single quoted Strings arrays into an uninitialized one dimensional String array. And there is a logical mistake too, you are assigning all the values on the same index location i.e. 0. Then you have ArraList about which we don't know if it is a property inside your action or something else. Please clarify all this first...
 
Ranch Hand
Posts: 689
Scala Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ankit Garg wrote:Abdul I don't think that code will compile. You are storing single quoted Strings arrays into an uninitialized one dimensional String array. And there is a logical mistake too, you are assigning all the values on the same index location i.e. 0. Then you have ArraList about which we don't know if it is a property inside your action or something else. Please clarify all this first...



Hi Ankit, yes code gives compile time error.
 
Abdul Mujeeb Md
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Ankit,

Extremely sorry. That was a typo. I have written it as an example. The code has compiled successfully and i am able to access the values of the String Array using <s:property> tag.

The exact representation goes this way.



I am unable to access the same in the drop down. I hope i made myself clear.

Thanks
 
Nishan Patel
Ranch Hand
Posts: 689
Scala Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Convert your array to list using



above code in your action class. Make arrayList global variable. Now your Jsp code looks like..





 
Abdul Mujeeb Md
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Nishan,

Thanks for your response.

That works fine for a single String Array.



How do we extend it to work for the above scenario. What if i have to list the values Red, Yellow, Green in the drop down and access the selected value in the Action using its key i.e; 1 or 2 or 3

Thanks.
 
Nishan Patel
Ranch Hand
Posts: 689
Scala Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you want to use <s:select with multiple list use ><s:merge...> tag..

refer below link for more details ...

Struts 2 merge

or

Java Ranch


 
Abdul Mujeeb Md
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Nishan,

You mean we have to have the String Array converted to a List to be accessed in the Struts Tag? Isn't there any other way we can achieve it?
I am using a Method which returns me an ArrayList(which contains String Array as its objects). The back end logic is hidden from me, what i only have is an ArrayList which has got the data in the said format. As I have only a single getter/setter method for the above ArrayList, i need to iterate it and fetch the data from it.




Now i have to only use arlFruitInfo to access the data from it.

How can this be done in the select drop-down.

Thanks.
 
Abdul Mujeeb Md
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Is there a way to use the select tag to display the bean contents, contained in a collection?

Eg:

How do we access "arlUserInfo" using Struts 2 Select option?

Thanks.
 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You must have appropriate getter for list arlUserInfo. For access this in JSP use attributes list, listkey and listvalue of select tag.

reply
    Bookmark Topic Watch Topic
  • New Topic