File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

storing values chosen from dropdown

 
shah rah
Ranch Hand
Posts: 124
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4864
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
shah rah
Ranch Hand
Posts: 124
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 948
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 124
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
how to select all the items in second list using javascript?
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just loop through the options, setting the selected property of each one to true. Example:
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic