• 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

Populating second list based on selection of first list

 
Ranch Hand
Posts: 597
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,

I need very very urgent help.


I have a JSP form in which I have two drop down lists. Second list to be populated on the basis of selection of item in first list. Both list gets populated from database. I am using Struts 1.1. I am not so good in Javascript


Its like suppose I have dept list and employee list. When form is loaded employee list will be blank and dept list will have all the depts. When user selects one dept, the second list will be populated with all the employees in the dept which user has selected from the first list. If user selects another dept, again second list will be populated from the dept selected in first list.

Please please help me.


Thanks alot in advance.
[ November 02, 2006: Message edited by: Rajesh Thakare ]
 
Ranch Hand
Posts: 180
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Rajesh,
You may use Ajax for this. It would be useful. But I am not sure about any issue with Struts 1.1 as I had done the same with Struts1.2.9.
This link would be useful.
https://coderanch.com/t/54752/Struts/reponseXML-empty-Ajax-Struts
Please post specific problem if you face any trouble.
Regards,
Roshani
 
Sandeep Awasthi
Ranch Hand
Posts: 597
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Roshani,

Thanks for reply. I can not use Ajax in this project as my PL will not allow me and I dont know Ajax. I may have to try something with javascript.

For both the list have custom jsp tags which populates list. The tag which populates employee list takes dept as an attribute and it populates list with employee list of that dept. Right now I have hardcoded that attribute with dept = "1" . So its showing me employees of dept 1. I need help to dynamically change this attribute to sepelected dept and populate list again.
 
RoshaniG Gopal
Ranch Hand
Posts: 180
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Rajesh,
Ajax is nothing but Asynchrounous JavaScript and XML. There is nothing new you have to learn if you know JS and little bit of XML. The link that i had given gives the complete code of what you require. I think that your PL should not object to it. And moreover you dont have to do any extra settings, etc nothing.
Regards
Roshani
 
Sandeep Awasthi
Ranch Hand
Posts: 597
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Roshani ,


Thanks alot. I will try it. Thank you very much.


Kind Regards


Rajesh
 
Ranch Hand
Posts: 456
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
would be nice if you choose a more meaningfull subject. you can still edit it, fellow readers will be thankfull.

concerning your problem: why dont you start a ordinary roundtrip based on the user choice of list 1? reload the page with a populated list 2...

regards,
jan
 
Sandeep Awasthi
Ranch Hand
Posts: 597
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Jan,

I changed the subject, thanks for your suggestion.

Regards

Rajesh
 
Sandeep Awasthi
Ranch Hand
Posts: 597
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Roshani,

Thanks for your help. Unfortunately I had to do it with Javascript for the time being because of high work pressure, I did not want to try AJAX right now. But I saw the link provided by you, and it looks quite similar to javascript and I will certainly change this code to use AJAX when I get free time. It was too urgent, so I did not try Ajax, but I really thank you for help.

I did it in following way.

I added one hidden form field to JSP form called reloadEmp with initial value="false"

In my ActionForm I added same field.

through javascript in the form I called form.submit() thiw way

document.empForm.reloadEmps="true";
document.empForm.submit();

In Action class for loading JSP form, I selected emps for that dept and stored in session and while reloading form, populated emplist.

I know it could have been done in very similar way with Ajax, but I did not have time try something new.

Regards
 
Ranch Hand
Posts: 948
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Just curious...did you have to do anything special to disable validation or do others that use this approach have a technique to disable validation? I am asking because I use this approach quite a bit and I have code in the processValidate method of a custom RequestProcessor (TilesRequestProcessor actually). The code there bypasses validation if there is a value in the request parameter "refreshControl". I have not seen anybody mention a similar approach so I am wondering what others do.

- Brent
 
Sandeep Awasthi
Ranch Hand
Posts: 597
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am new to struts so I never tried to bypass validation. I am not even using struts validator. I am doing validation in ActionForm with validation method. But have not done enough coding in struts yet.
 
If you are using a rototiller, you are doing it wrong. Even on this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic