I know how to do this in PHP so I'm hoping I can do it in Java as well. Here is some of my Java code:
String curYear = form.getCurYear();
if(curYear == null || curYear.length() == 0 || !curYear.matches(decimalRegex)) {
errors.rejectValue("curYear", "supplier.curYear.invalid", "Invalid format for dollar amount");
}
String lastYear = form.getLastYear();
if(lastYear == null || lastYear.length() == 0 || !lastYear.matches(decimalRegex)) {
errors.rejectValue("lastYear", "supplier.lastYear.invalid", "Invalid format for dollar amount");
}
These 2 chunks are followed by several more almost identical chunks where just the variable names/strings change. So I wanted to create a for(or foreach) loop to create all these using an array of the variable names. But for the form.getCurYear(); code, the first character of the variable name(curYear) is capitalized, so I would need to construct the variable name beforehand. Easy enough: String capField = inputField.substring(0, 1).toUpperCase() + inputField.substring(1);
Now how do I use that variable name in the form property call? I know form.capField() won't work. Is this even possible?