For populating a drop-down based on another drop-down value
For populating a drop-down based on another drop-down value.
---------------------------------------------------------------------------------------------
We have 2 List objects namely A and B, contains different Bean objects each. All these Bean objects have a Long property in common (private Long amount).
List A contains 4 bean objects.
List B contains 20 bean objects which inturn contains other properties as well.
We need to fetch only the relevant 4 bean objects from List B that match the bean objects from List A. This match is based on the common Long property.
----------------------------------------------------------------------------------------------
Long code = objRequestForm.getTransactionDropDownValue();
List
List
Map
List
if(requestTransactionMap != null && !requestTransactionMap.isEmpty()) {
requestTransactionList = requestTransactionMap.get(code);
}
List
if(requestTransactionList != null) {
for(RequestTransactionBean objRequestTransactionBean: requestTransactionList) {
Long requestTxnTypeKey = objRequestTransactionBean.getRequestTxnTypeKey();
transactionCodeList.add(requestTxnTypeKey);
}
for(RequestTxnTypesBean objRequestTxnTypesBean: requestTxnTypesList) {
if(transactionCodeList.contains(objRequestTxnTypesBean.getRequestTxnTypeKey())){
resultantTransactionList.add(objRequestTxnTypesBean);
}
}
for(RequestTxnTypesBean objRequestTxnTypesBean: resultantTransactionList) {
if(objRequestTxnTypesBean.getRequestTxnTypeKey().equals(TRASACTIONTYPEKEY)) {
objRequestForm.setRequestTransactionTypeKey(TRASACTIONTYPEKEY);
} else {
objRequestForm.setRequestTransactionTypeKey(GTEMApplicationConstants.ZEROVALUE);
}
}
objRequestForm.setLstRequestTxnTypes(resultantTransactionList);
} else {
objRequestForm.setRequestTransactionTypeKey(GTEMApplicationConstants.ZEROVALUE);
}
----------------------------------------------------------------------------------------------
Step - 1 : We are getting the first drop-down value and storing it in Long property called code.
Step - 2 : We are calling a Map which returns a List object which contains 4 bean objects of type RequestTransactionBean
Step - 3 : We are invoking getLstRequestTxnTypes() method which returns a List objects which contains 20 objects of type RequestTxnTypesBean.
Step - 4 : We are iterating requestTransactionList which contains objects of type RequestTransactionBean and fetch the Long property from RequestTransactionBean and store it in a new List transactionCodeList of type Long.
Step - 5 : We are iterating requestTxnTypesList which contains objects of type RequestTxnTypesBean. We are comparing whether transactionCodeList contains Long property from objects RequestTxnTypesBean. If successful then add the RequestTxnTypesBean object to a new List object.
0 Comments:
Post a Comment
<< Home