File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Struts and the fly likes How to use the select tag - Struts2 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "How to use the select tag - Struts2 " Watch "How to use the select tag - Struts2 " New topic
Author

How to use the select tag - Struts2

Peter Mest
Ranch Hand

Joined: Aug 14, 2009
Posts: 30
When I press the button witch takes me to index.jsp where is this form(see below), the list cities from my Action is populated using a DB query.
Something like this (this is just a GENERAL photo, it's not from my code):




The question: how can I know what values are selected from the select tag in the Action? What is the name of variable which holds the chosen id?

David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Create action properties named as the select elements are?

You should check out some of the Struts 2 tutorials before going too much further; dealing with forms in Struts 2 is pretty important stuff and should be understood.
Peter Mest
Ranch Hand

Joined: Aug 14, 2009
Posts: 30
The problem is that I use the SAME action, for the both things.

When I press the button witch takes me to index.jsp, my "cities" properties is initialized using a static method;

List<City> cities = refresh();

And when I press the submit button, I go in the same Action, this time using the execute method(), but here the cities proprieties has the same values returned by refresh(). Any ideas?
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

I'm not sure what you're saying; the "list" attribute defines where the list values come from--not the action property that holds the selected values.

See how your textfield tag has a "name" attribute? Why doesn't your select tag?
Peter Mest
Ranch Hand

Joined: Aug 14, 2009
Posts: 30
David Newton wrote:I'm not sure what you're saying; the "list" attribute defines where the list values come from--not the action property that holds the selected values.

See how your textfield tag has a "name" attribute? Why doesn't your select tag?



Moron.
I thought you use the select tag in a different way. I just found an example and copy-pasted in my code, without reading the documentation.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to use the select tag - Struts2