Win a copy of TensorFlow 2.0 in Action this week in the Artificial Intelligence and Machine Learning forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Paul Clapham
  • Bear Bibeault
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Jj Roberts
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • salvin francis
  • Scott Selikoff
  • fred rosenberger

struts2 select and js

 
Ranch Hand
Posts: 104
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi. Does anyone know if its possible to populate a struts2 form select tag with options via javascript as opposed to using <s:select list = "someCollection"...
cheers
 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sure; it's just an HTML control.
 
vik ar
Ranch Hand
Posts: 104
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have the following html which works nicely:



What happens is when the page is loaded the city dropdown is updated with options via js and when a city is selected the area dropdown is updated as required. I cant seem to transfer this to a struts2 form as follows:



As you can see at the moment I am just trying to get the city select to populate when the page loads. However I am getting the following error



thanks

 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, you're giving it a list attribute with no list. Try giving it an empty list.

If your requirements run counter to the intended functionality of the Struts 2 tag why bother using the Struts 2 tag?
 
vik ar
Ranch Hand
Posts: 104
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i have code which performs struts2 validation and preventing double submits. I also have javascript code which handles the select box functionality I require. If I am unable to integrate the two together I will likely rewrite the functionality that my javascript does in the form of java code, so when there is an onchange event on the city select box a action will be called and this will populate the area select as required
 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
S2 validation doesn't require the use of S2 tags. The only benefit S2 tags give is automatic display of validation messages--and that can be done by hand.

Again--try providing an empty list to the select tag if you're populating it manually. Or do the initial list population in the action and use a list property.
 
vik ar
Ranch Hand
Posts: 104
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I tried with list = {} and nothing is displayed in the select box
 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

vik ar wrote:I tried with list = {} and nothing is displayed in the select box


Well no, that's an empty list--what would you expect to be displayed?

Perhaps you should re-state your expectations and requirements.
 
vik ar
Ranch Hand
Posts: 104
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

David Newton wrote:Again--try providing an empty list to the select tag if you're populating it manually.



???
 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Perhaps you should re-state your expectations and requirements.


Otherwise I'll have to give up.
 
vik ar
Ranch Hand
Posts: 104
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have now got the following



My city dropdown is still empty when the page is loaded. When I uncomment the java code above it is populated fine and the onchange javascript function also poulates the area select box correctly. Bit of a botch job I have to say!!!
 
vik ar
Ranch Hand
Posts: 104
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
does anyone know why my onload function does not prepopulate the city select???
 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How could we? You haven't shown it.
 
Marshal
Posts: 67463
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

David Newton wrote:How could we? You haven't shown it.


Is your crystal ball broken too?

 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
The glass is neither half full or half empty. It is too big. But this tiny ad is just right:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic