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

storing values chosen from dropdown

shah rah
Ranch Hand

Joined: Jan 04, 2007
Posts: 124
I have a dropdown box and the user can select as many as he wants. I have another dropdown that stores the user selections. I want to display the user selections in the confirmation page.

form-property name="chosenstates" type="java.lang.String[]"

Action class
String [] states= (String [])stateForm.get("chosenstates");
myStateFormbean.setStates(states);

JSP
myForm.getStates()(loop thru array is not working)

The above code is not working..How do I do this?
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
I'm afraid you haven't given us enough information to help solve the problem. Please show us the code that's not working and the error messages you're getting.


Merrill
Consultant, Sima Solutions
shah rah
Ranch Hand

Joined: Jan 04, 2007
Posts: 124
user can choose upto a max of 3 states. The states chosen are placed in chosenstates dropdown using javascript addOptions.

My chosenstates dropdown gets successfully populated based on the user's selections in states box. This works perfectly. When I submit the home.jsp page I try to display the chosen states in confirm.jsp. None of the states show up. I see the array length as 0.

Is this a right way to store values chosen by user? or is there a more good aproach?

home.jsp





Struts-config



Action class


confirm.jsp //returns nothing.


[ March 17, 2007: Message edited by: shah rah ]
[ March 17, 2007: Message edited by: shah rah ]
Brent Sterling
Ranch Hand

Joined: Feb 08, 2006
Posts: 948
Keep in mind that the only id values that will get submitted are the ones that are actually selected. You have added the items to you second list but nothing will be submitted unless the items are selected. What I have done for this type of page is to add some java script to select all the items in the list of chosen items when the user clicks the submit button.

- Brent
shah rah
Ranch Hand

Joined: Jan 04, 2007
Posts: 124
how to select all the items in second list using javascript?
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
Just loop through the options, setting the selected property of each one to true. Example:
 
jQuery in Action, 2nd edition
 
subject: storing values chosen from dropdown