• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Drop down list value

 
Ranch Hand
Posts: 219
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all.
I am doing an application using struts.
In my jsp page i have 2 drop down list.
The value for the first drop down list is obtained by running a query and i am able to display the values in the first drop down list.

The value for the second drop down list depends on the value of the first.
So after selecting the first drop down list i again go to my action class and run the query for getting the second drop down list value by passing the selecting value of the first drop down list.


Everything is fine.Except when i select the first drop down list value and come back again to my same jsp page after running the query for second drop down list the value i have selected for the fist drop down list is changed .My problem is how do i maintain the value of the first drop down after returning to the same jsp .

Any hint or clue or any form of help is really appreciated.
Please let me know if i am not clear with my question.

Thanks
 
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Did you use the <html:select> and <html ptions> tags for the first select box? Can you verify that the ActionForm property contained the value you expected when the form was submitted?
 
meena latha
Ranch Hand
Posts: 219
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the reply.
I am using JSTL tags.I am putting a part of code below.


When onchange happens it goes to my action class.
In my action class i am able to get the value .
Using that only i am running my second query to get the value for second drop down list.I am able to get the value for my second drop down list also.Problem is that when i come back to the jsp the value is initally selected is not appearing in my first drop down list.
It is showing some other value.
Any hint or clue will be really useful.

Thanks
 
Ranch Hand
Posts: 751
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hmmm... You won't be able to capture the value of your form fields to your form bean without using the struts tags as Merill mentioned... Use the <html:select> and <html ptions> tags...
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Change

<c:when test="${iteration.count-1 == pubForm.selectedID}">

to

<c:when test="${pub.pubID == pubForm.selectedID}">

You could also write this as:

<html:select property="selectedId" onchange="submitForm2('display')">
<html:optionsCollection property="pubList" value="pubID" label="pubName" />
</html:select>

The nice thing about the html:select tag is that it automatically selects the option matching the value of selectedId.
[ January 12, 2006: Message edited by: Merrill Higginson ]
 
meena latha
Ranch Hand
Posts: 219
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks to everybody.
A million thanks to Merrill.
Is there any way that i can retrive the value and text of the selected option.In my case value is the ID and text is the Name i need both.

Thanks
[ January 12, 2006: Message edited by: ramya jai ]
 
meena latha
Ranch Hand
Posts: 219
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks to all.
I did it using javascript function.
 
reply
    Bookmark Topic Watch Topic
  • New Topic