I have a requirement when I am asked to charge a fee for a certain course. But the problem is that for few courses the same fee applies to all types of users, and for some courses a professional fee applies. For example, if the user is a teacher, then he pays less than if he were an industry professional.
There are predefined professions in the database.
Here is my current logic with code.
Depending on the switch, I switch the correct div and certain logic at the back end.
<input type="radio" name="professionWiseFees" value="true"> <input type="radio" name="professionWiseFees" value="false"> <div id="totalAmount" class="hidden"> <input class="feeAmountOnly" name="feeAmount" type="text" /> </div> <div id="professionWiseAmount" class="hidden"> <c:forEach items="${applicationScope.professionList}" var = "profession" > Course Fee For ${profession.profession} <input type="hidden" value="${profession.id}" name="profession" type="text"/> <input class="feeAmoun2t" name="profession" type="text" /> </c:forEach> <div>
Now I am checking what type of fees is applicable and filling out the hash map accordingly. if prefessionWiseFees is not applied, then adding the same fees to all professions.
Boolean isProfessionWiseFeesApplicable = Boolean.parseBoolean(reqParams.get("professionWiseFees")[0]); Map<Integer,Double> feeProfessionMap = new HashMap<>(); List<Profession> professions = (List<Profession>) servletContext.getAttribute("professionList"); if(isProfessionWiseFeesApplicable) { String[] propfessionWiseFees = reqParams.get("profession");
Model class:
public class CourseBean { // few fields private Map<Integer, Double> professionWiseFees; // <profession_id ,fees> // all setters and getters }
So how can I solve this problem elegantly? requestParam.get in code
spring spring-mvc
Govinda sakhare
source share