aspose file tools*
The moose likes Struts and the fly likes struts2 select and js Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "struts2 select and js" Watch "struts2 select and js" New topic
Author

struts2 select and js

vik ar
Ranch Hand

Joined: Jul 31, 2009
Posts: 104
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
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Sure; it's just an HTML control.
vik ar
Ranch Hand

Joined: Jul 31, 2009
Posts: 104
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
Rancher

Joined: Sep 29, 2008
Posts: 12617

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

Joined: Jul 31, 2009
Posts: 104
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
Rancher

Joined: Sep 29, 2008
Posts: 12617

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

Joined: Jul 31, 2009
Posts: 104
I tried with list = {} and nothing is displayed in the select box
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

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

Joined: Jul 31, 2009
Posts: 104
David Newton wrote:Again--try providing an empty list to the select tag if you're populating it manually.


???
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Perhaps you should re-state your expectations and requirements.

Otherwise I'll have to give up.
vik ar
Ranch Hand

Joined: Jul 31, 2009
Posts: 104
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

Joined: Jul 31, 2009
Posts: 104
does anyone know why my onload function does not prepopulate the city select???
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

How could we? You haven't shown it.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61654
    
  67

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

Is your crystal ball broken too?



[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: struts2 select and js