How to create a dependent drop down list using [Apache POI]

Ads
 

How to create a dependent drop down list using [Apache POI]

Here I am creating one excel template using [Apache POI] in that user can fill data. In that two drop down list are there. Want to create a drop down list that depends on previous cell's drop down. For example: If I select veg category in cell 3, and "rice, curd, milk" items will appear in the dependent drop down list in cell 4. Codes are below.

Here collecting data

List<InternetItemResponse> internetItems = internetItemService.getAllByHotelId(hotelId);
if (CollectionUtils.isNotEmpty(internetItems)) {
String[] itemsName = new String[internetItems.size()];
String[] itemsCategory = new String[internetItems.size()];
String itemName;
String itemCategory;
Map<String, Set<String>> categoryVsItemName = new HashMap<>();
Set<String> itemList;
for (int i = 0; i < internetItems.size(); i++) {
    InternetItemResponse itemResponse = internetItems.get(i);
    if (itemResponse != null) {
        itemCategory = itemResponse.getCategory();
        if (!StringUtils.isEmpty(itemCategory)) {
            itemsCategory[i] = itemCategory;
            itemName = itemResponse.getTitle();
            itemsName[i] = itemName;
            if (CollectionUtils.isEmpty(categoryVsItemName.get(itemCategory))) {
                itemList = new HashSet<>();
                itemList.add(itemName);
                categoryVsItemName.put(itemCategory, itemList);
            } else {
                categoryVsItemName.get(itemCategory).add(itemName);
            }
        }
    }
}

}

Assigning the data in drop down

// Setting drop down values
for (int i = 0; i < headerColumns.length; i++) {
    if (i == 3) {
        XSSFDataValidationHelper mealdvHelper = new XSSFDataValidationHelper((XSSFSheet) sheet);
        XSSFDataValidationConstraint mealdvConstraint = (XSSFDataValidationConstraint) mealdvHelper
                .createExplicitListConstraint(itemsCategory);
        // CellRangeAddressList(int firstRow, int lastRow, int firstCol, int lastCol)
        CellRangeAddressList addressListmeal = new CellRangeAddressList(1, 99, i, i);
        XSSFDataValidation categoryDataValidation = (XSSFDataValidation) mealdvHelper
                .createValidation(mealdvConstraint, addressListmeal);
        categoryDataValidation.setShowErrorBox(true);
        categoryDataValidation.setSuppressDropDownArrow(true);
        categoryDataValidation.setShowPromptBox(true);
        sheet.addValidationData(categoryDataValidation);
    } else if (i == 4) {
        XSSFDataValidationHelper rmCategorydvHelper = new XSSFDataValidationHelper((XSSFSheet) sheet);
        XSSFDataValidationConstraint rmCategorydvConstraint = (XSSFDataValidationConstraint) rmCategorydvHelper
                .createExplicitListConstraint(itemsName);
        CellRangeAddressList addressListrmCategory = new CellRangeAddressList(1, 99, i, i);
        XSSFDataValidation itemNameValidation = (XSSFDataValidation) rmCategorydvHelper
                .createValidation(rmCategorydvConstraint, addressListrmCategory);
        itemNameValidation.setShowErrorBox(true);
        itemNameValidation.setSuppressDropDownArrow(true);
        itemNameValidation.setShowPromptBox(true);
        sheet.addValidationData(itemNameValidation);
    }
}
View Answers

Ads









Related Tutorials/Questions & Answers:
Dependent drop down list
JSP Dependent Drop Down Menu
Advertisements
drop down list in Struts
dependent drop down box - JSP-Servlet
How to pass parameter through drop down list using session management in jsp??
How to insert multiple drop down list data in single column in sql database using servlet
dynamic drop down list
view data from database using drop down list
validation for drop down list
how to retreive data dynamically from mysql to drop down list
Excel Cell Drop Down List
Get values in drop down list
Dependant & dynamic drop down list
Drop down list from database
store values of drop down list box in database
how to make drop down list in JSF & fetch data Item from database
Java Swing dependent JList
Display related data in other drop down list on selecting one data in one drop down list
Drop Down Reloads again in IE..How to prevent this?
Select functionality of drop down list - Struts
Drop Down
drop down menu
Dependant & dynamic drop down list - Follow up
dynamic drop down list box - Java Beginners
how to store multiple values from drop down in database where i am using java struts 1.3
Add/Remove Rows Dynamically with drop down list in html table using php
Passing Multi select list box values using ajax to get values to dependent list box
Choice Option (Combo) In Java
drop down
How to create runtime drag and drop form builder using asp.net mvc and jquery
creation of drop down menu using ajax in java - Ajax

Ads