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 8374375
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T14:54:33+00:00 2026-06-09T14:54:33+00:00

I wonder if anyone can help. I’m writing a Spring MVC / Webflow web

  • 0

I wonder if anyone can help. I’m writing a Spring MVC / Webflow web app where I need to collect data from the user. I have a form backing object which mirrors the backend schema (I think JAXB was used to generate the classes). Anyway, one of the fields I need to capture is DOB, which in the form backing object is a single property of type XMLGregorianCalendar

For the most part, html input fields on the form are a 1 to 1 mapping to the property in the form backing object – eg: the html input “surname” maps to the String property called “surname” in the form backing object (via the getters and setters). Nice 🙂

But date fields are a bit different. In the form backing object, it is only one property with one getter/setter pair; but on screen we might want to present it as 3 seperate fields – perhaps a drop down for Day, a dropdown for Month and a text box for Year

This type of problem must come up in every web app, regardless of backend technology, and I’m wondering how other people deal with it.

I’ve got two thoughts:

1) extend my form backing object so that I have properties for dobDay, dobMonth and dobYear, then as part of my validator take the 3 values and set the real DOB property from them. I’ve done this in the past, it kind of works, but if feels a bit rubbish, especially if the web app has lots of dates.

2) Find or write a jsp taglib that does this magic for me. I can see how this work work when rendering the form – the taglib can be called with the property name in the FBO, it can get the current date value, then can write to the output 3 html fields. But I cant see how the submission would work – something would need to read the 3 html fields and ‘glue’ them into the real property in the FBO

So, really, its just a call for help – what have other people done with this kind of thing in the past?

Appreciate your thoughts

Nathan

  • 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-09T14:54:34+00:00Added an answer on June 9, 2026 at 2:54 pm

    You could use either option, but I tend to agree with you that it isn’t very slick to have the command object contain the date components.

    Number 2 will work if you add a hidden field in the page for the date field and you use the value to fill your three combos for day, month and year. On form submit you must first use javascript to reassemble the values from the combos inside this hidden field (which will map with the date field in the command object).

    I think this is the cleanest way, but if you don’t want to use javascript, you could submit the three values (with no correspondent fields in the command object) and assemble them after your command is bind.

    You don’t mention the Spring version you are using but for 2.x you could intervene in the workflow on the onBind method to reassemble the values there.

    Things changed in Spring 3 and the controller classes are deprecated in favor of annotated controllers but you might get a similar result if you use an InitBinder in combination with the request to register a custom date editor and reassemble the fields; for example:

    Command:

    public class TestCommand implements Serializable {
        private static final long serialVersionUID = 1L;
        private Date someDate;
    
        public Date getSomeDate() {
            return someDate;
        }
    
        public void setSomeDate(Date someDate) {
            this.someDate = someDate;
        }
    }
    

    Controller:

    @Controller
    @RequestMapping(value="/testAction")
    public class TestController {
    
        @RequestMapping(method=RequestMethod.GET)
        public String handleInit() {
            return "form";
        }
    
        @InitBinder
        protected void initBinder(WebDataBinder dataBinder, WebRequest webRequest) {
            dataBinder.registerCustomEditor(Date.class, "someDate", new TestPropertyEditor(webRequest));
        }
    
        @RequestMapping(method=RequestMethod.POST)
        public String handleSubmit(@ModelAttribute("testCommand") TestCommand command, BindingResult result) {
            return "formResult";
        }
    }
    

    Form:

    <form:form modelAttribute="testCommand" action="testAction" method="post">
        <%-- need a parameter named "someDate" or Spring won't trigger the bind --%>
        <input type="hidden" name="someDate" value="to be ignored" /> 
    
        year: <input type="text" name="year" value="2012" /><br/>
        month: <input type="text" name="month" value="5" /><br/>
        day: <input type="text" name="day" value="6" /><br/>
    
        <input type="submit" value="submit" />
    </form:form>
    

    Form result:

    some date: ${testCommand.someDate}
    

    Property editor:

    public class TestPropertyEditor extends PropertyEditorSupport {
        private WebRequest webRequest;
    
        public TestPropertyEditor(WebRequest webRequest) {
            this.webRequest = webRequest;
        }
    
        @Override
        public void setAsText(String text) throws IllegalArgumentException {
            Map<String, String[]> parameterMap = webRequest.getParameterMap();
    
            // should validate these...
            Integer year = Integer.valueOf(parameterMap.get("year")[0]);
            Integer month = Integer.valueOf(parameterMap.get("month")[0]);
            Integer day = Integer.valueOf(parameterMap.get("day")[0]);
    
            try {
                String value = String.format("%1$d-%2$d-%3$d", year, month, day);
                setValue(new SimpleDateFormat("yyyy-MM-dd").parse(value));
            } catch (ParseException ex) {
                setValue(null);
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I wonder if anyone can help me filter this data in some way? Here
Wonder if anyone can help. I have a c# web application that uses the
I wonder if anyone can help improve my understanding of JOINs in SQL. [If
I wonder if anyone can help - I have this error showing recently when
I wonder if anyone can help me to understand where I could be going
I wonder if anyone can help - I want to select a table and
I wonder if anyone can help? After Google announced that it will take note
I wonder if anyone can help with a jQuery problem I am having. I
I'm new to KnockoutJs and I wonder if anyone can help with this. I
I'm a newbie programmer working with jQuery and wonder if anyone can help me

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.