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

  • Home
  • SEARCH
  • 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 5966379
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T19:47:31+00:00 2026-05-22T19:47:31+00:00

I am using Spring 3 MVC Annotation Validation. I know how to do it

  • 0

I am using Spring 3 MVC Annotation Validation. I know how to do it in JSP(using modelAttribute property in JSP), but I don’t have any clue how to apply this kind of data binding in Freemarker.

Example of JSP equivalence

<c:url var="addUrl" value="/admin/workerAdd" />
<form:form modelAttribute="worker" action="${addUrl}" method="post">
    <p>
 <form:label for="code" path="code">Code</form:label>
     <form:input path="code" readonly="false" />
    </p>
...

Example of Controller:

@Controller
@RequestMapping("/admin/*")
public class AdminController {    
    @Autowired
    private CommonService commonService;

    /**
     * For every request for this controller, this will 
     * create a person instance for the form.
     */
    @ModelAttribute
    public Worker newRequest(@RequestParam(required=false) String id) {
        return (id != null ? commonService.getWorkerById(id) : new Worker());
    }

    @RequestMapping(value="/workerAdd", method=RequestMethod.POST)
    public final String performAddUser(@Valid Worker worker, BindingResult result) throws Exception {
        if (result.hasErrors()) {
            return null;
        }

            // Create the worker here.

        return "redirect:/administration/manageUser";
    }

Now I want to use the same controller, but the views are written by Freemarker(ftl). The data-binding in my below freemarker doesn’t work (which is understandable, since it should have different syntax). I did some research and learn about command object in FTL, but I don’t get the point. I think it should be a similar attribute that tell Spring to do the binding but I still not find it yet.

<form id="worker" modelAttribute="worker" action="${rc.getContextUrl('/admin/workerAdd')}" method="post" >          
            <div class="Entry">
            <label for="code">Code</label>
            <input type="text" id="code" name="code" value="${worker.code}" />
            </div>

Is there any simple way to make this annotation validation way (and the databinding as well) works with FTL? Any help will be appreciated.

Thanks,

Hoang Long

  • 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-05-22T19:47:32+00:00Added an answer on May 22, 2026 at 7:47 pm

    You JSP code can be rewritten in Freemarker as follows:

    <#import "spring.ftl" as spring />
    ...
    <form id="worker" action="${rc.getContextUrl('/admin/workerAdd')}" method="post" > 
        <p>
            <label for = "code">Code</label>
            <@spring.formInput "worker.code" />
        </p> 
    ...
    

    Note that Spring library for Freemarker doesn’t have specifal element for form, so you need to use ordinary html form and prepend model attribute name to paths of individual fields.

    See also:

    • 16.4 Velocity & FreeMarker
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using Spring MVC and my jsp's have a <div id=debug> section that I
I have problem using annotated validation in spring 3 mvc. I´m not sure if
I am using Spring MVC to build my web application, and I have a
I have specified <mvc:annotation-driven /> in dispatcher-servlet. I am not using @InitBinder. And I
I have some problems with validation using Data Annotations in ASP.NET MVC 2. For
I'm developing webapp using spring 3 mvc and using annotation-based controllers. I want to
I'm writing webapp using Spring 3 MVC with annotations. I use jsp for view
I'm trying to setup a Spring 3 Web MVC project, using the @Controller, annotation-based
I'm using Spring MVC. I want to include menu page (named menu.jsp) with a
I'm building a MVC web application (using the Spring MVC framework), and I'm a

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.