*
The moose likes Struts and the fly likes Drop down list value Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Drop down list value" Watch "Drop down list value" New topic
Author

Drop down list value

meena latha
Ranch Hand

Joined: Jan 24, 2005
Posts: 219
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
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
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?


Merrill
Consultant, Sima Solutions
meena latha
Ranch Hand

Joined: Jan 24, 2005
Posts: 219
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
Timothy Sam
Ranch Hand

Joined: Sep 18, 2005
Posts: 746
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...


SCJP 1.5
http://devpinoy.org/blogs/lamia/ - http://everypesocounts.com/
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
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')">
<htmlptionsCollection 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

Joined: Jan 24, 2005
Posts: 219
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

Joined: Jan 24, 2005
Posts: 219
Thanks to all.
I did it using javascript function.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Drop down list value
 
Similar Threads
Retaining Retaining Drop down value
dynamic drop down list values
Reg : Drop-down box
ArrayList gets duplicate values in JSP
Dynamic Drop Down Lists.