• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to use the select tag - Struts2

 
Peter Mest
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic