File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Struts and the fly likes extracting some elements from ArrayList on JSP Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "extracting some elements from ArrayList on JSP" Watch "extracting some elements from ArrayList on JSP" New topic
Author

extracting some elements from ArrayList on JSP

lubna kausar
Ranch Hand

Joined: May 06, 2006
Posts: 51
hello everyone.
On my JSP i am having a dropdown box to select a category.
and on selection of that i want all its subcategories to be displayed in another dropdown box.
now the thing is that my categoryBean contains CatagoryId,CategoryName,ParentCategoryId.
and list of all categories(including all subcategories and everything) are inside CategoryList(ArrayList)
and i have....
<html:select property="category" size="1">
<jsp:useBean id="categoryList" class="java.util.ArrayList" scope="session" />
<html ptions collection="categoryList" labelProperty="catName" property="catId"/></html:select></td>

now when user selects a category...
how can i check that the categories are containg XYZ as its parent category???
and how to get them in another dropdown box???
any help will be appriciated...
thank you...
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
Here's how I used to do it:

1. Code an "onchange" event in the first dropdown that submits the form
2. Have the action class read the option selected in the first dropdown and build the list for the second dropdown
3. Redispaly the page, putting the focus on the second dropdown.


Now, I use AJAX, which is much smoother and doesn't require a redisplay of the page. Here's roughly how it works:

1. code an "onchage event in the first dropdown that makes an AJAX call to the server.
2. Code a server Method that will return a list of options based on what was selected in the first.
3. The "callback function" of the AJAX call takes the list of options returned and uses the Document Object Model (DOM) to build a second dropdown with the list of options.

This option requires learning some of the principles of AJAX, though, and will involve a bit of a learning curve. I'd suggest using DWR as a framework for your AJAX calls.
[ June 12, 2006: Message edited by: Merrill Higginson ]

Merrill
Consultant, Sima Solutions
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: extracting some elements from ArrayList on JSP