I’ve been using using @ModelAttribute to “cast” my form variables into a class (which represents a table in the database) and this has worked quite nicely.
But I’m working on another form and I need to have a hidden field in the form that doesn’t represent data in the database. I’m just passing it for the business logic section of my code.
How do I access this hidden field now in my function? I don’t want to edit my table class to add this new field as that seems bad programming. And I know I can create a new class that just contains the all the fields in my form but I’m unsure if that is the best way to go.
thanks! 🙂
These are what I have right now(only has table fields but works).
my jsp page
<form:form modelAttribute="fab" method="post" action="SaveEventRegistration.html">
my java code to accept form submission
@RequestMapping("/SaveEventRegistration")
public ModelAndView saveEventRegistration(@ModelAttribute Fab fab) {
System.out.println(fab.getStudentId());
You don’t need to change the table and its pojo. To get the hidden fields values those are not available to be bind in your ModelAttribute object, you can just simply declare that hidden field in the jsp inside your form with html input tag and make it hidden with required value.
Now in the controller function you need to have a parameter
HttpServletRequest requestand get the value of your hidden field say with name hdParam withrequest.getParameter("hdParam").I hope this helps you. Cheers.