Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8533115
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T09:52:59+00:00 2026-06-11T09:52:59+00:00

I’ new to spring and i’ve managed to collect data from a form in

  • 0

I’ new to spring and i’ve managed to collect data from a form in a JSP view and to submit my form to a controller . From the data aquired from the view , i’m instantiating a model object , which also contains other model objects :

@RequestMapping(value = "/updateEntry", method = RequestMethod.GET)
public RedirectView updateAction(ModelAndView model,
@RequestParam(value = "name", defaultValue = "none") String selectedWaveName,
@RequestParam(value = "id", defaultValue = "-1") int id,
@RequestParam(value = "function", defaultValue = "none") String function,
@RequestParam(value = "evidence", defaultValue = "none") String evidence,
@RequestParam(value = "action", defaultValue = "none") String action,
@RequestParam(value = "topicId", defaultValue = "-1") int topicId,
@RequestParam(value = "topic", defaultValue = "none") String topic,
@RequestParam(value = "topicDesc", defaultValue = "none") String topicDesc,
@RequestParam(value = "waveId", defaultValue = "-1") int waveId,
@RequestParam(value = "waveStart", defaultValue = "none") String waveStart,
@RequestParam(value = "waveEnd", defaultValue = "none") String waveEnd)
throws ParseException {

DateFormat formatter = new SimpleDateFormat("dd-MM-yyyy");
Date dateStart = formatter.parse(waveStart);;
Date dateEnd = formatter.parse(waveEnd);

waveDAO.updateFormResults(new FormResults(id, 
new Topic(topicId, topic, topicDesc), 
new Wave(waveId, selectedWaveName, dateStart, dateEnd), 
evidence, action, function));
return new RedirectView("/hr/?name=" + selectedWaveName);
}

How can i replace the whole @RequestParam lines with fewer lines using @ModelAttribute ?
Do i also need to add the @ModelAttribute annotation to the model classes (FormResults , Topic , Wave) ?

Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T09:53:01+00:00Added an answer on June 11, 2026 at 9:53 am

    The ModelAttribute annotation did work eventually , I found out that when using this annotation , the variables that you’re passing from the front end , in my case from the JSP page , should have the exactly same name as the attributes declared in you’re model class !

    For example if you have a model class like :

    public class FormResults {
    
    private int id;
    private Topic topic;
    private Wave wave;
    private String evidence;
    private String action;
    private String manager;
     ... }
    

    Also you need getter and setter methods for all the class attributes , and a default constructor !

    The variables which you are sending from the JSP page , to the controller method that uses @ModelAttribute annotation , would be named like this :

    <input type="text" name="id"     ...
    <input type="text" name="evidence" ...
    <input type="text" name="action"   ....
    <input type="text" name="manager"  ...
    

    And this also works in the case where you have a complex object that has another object as attribute (like in my case : Topic , Wave).
    All you have to do is name those inputs with the prefix of the class name : ex: topic , wave , followed by that classes attributes , ex: topic.id , wave.id …

    And here is my controller method’s signature :

    @RequestMapping(value = "/updateEntry", method = RequestMethod.GET)
    public ModelAndView updateAction(ModelAndView model,
            @ModelAttribute("fr") FormResults fr) throws ParseException {
    ...}
    

    Spring automatically creates a FormResults object . That`s it! 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a text area in my form which accepts all possible characters from
I have a view passing on information from a database: def serve_article(request, id): served_article
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I want use html5's new tag to play a wav file (currently only supported
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have an MVC Razor view @{ ViewBag.Title = Index; var c = (char)146;
Does anyone know how can I replace this 2 symbol below from the string

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.