How to pass an ArrayList from JavaAction class(struts 1) to JSP page

426 Views Asked by At

I am new to struts. Please excuse me for any mistake.

There is one Action.java class in my application and in that file there is one ArrayList in which values are coming form DB like List products = miscDao.getInsSubProd("Y", locCntryId);

There is one JSP file as well. I want to use that ArrayList(products) in my JSP file.

I am trying to create an autocomplete in the same JSP page, for that I need all the values to be stored in another arraylist from ArrayList(products).

I am using struts 1 in this application. If I want these values to show in dropdown list. I can do that using <option collection="products"> tag. What I need to do, If I want it to show in textbox as autocomplete.

1

There are 1 best solutions below

3
On

two options here: you can generate a javascript array in your jsp with the elements of the list:

<script type="text/javascript">
var products = [
<c:forEach var="prod" items="${products}">
    "<c:out value='${prod}'/>",
</c:forEach>
];
</script>

Or, you can place an event handler on the input events of your text box and do an ajax call to the server to obtain an already filtered list of products.