In my controller class, I'm setting some attributes to the request as below.
for(ConsumerVO dep:quoteVO.getConsumerFamily().getDependents())
{
request.setAttribute("dependent_"+depCount+"_birthdateMM", dep.getBirthdateMM());
request.setAttribute("dependent_"+depCount+"_birthdateDD", dep.getBirthdateDD());
request.setAttribute("dependent_"+depCount+"_birthdateYYYY", dep.getBirthdateYYYY());
depCount++;
}
In the jsp, I'm trying to access it by setting the variable name dynamically. But itsn't working. No data is in ${depMM}, ${depDD} etc. I'm looking for something like ${${depMM}}. How can I access the request variables in a loop ?
jQuery(function(){
var dependent_data = [];
for(j=1;j<16;j++){
var depMM = "dependent_"+j+"_birthdateMM";
var depDD = "dependent_"+j+"_birthdateDD";
var depYY = "dependent_"+j+"_birthdateYYYY";
if (typeof '${depMM}' !== 'undefined' && '${depMM}' !=="") {
dependent_data.push('${depMM}','${depDD}','${depYYYY}');
}
}
PS: When I did this, it printed the data.
var dependent1MM_data = '${dependent_1_birthdateMM}';
alert(dependent1MM_data);