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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T14:55:14+00:00 2026-05-28T14:55:14+00:00

I have a template with a table of input box were each row represents

  • 0

I have a template with a table of input box were each row represents a model object.
I can’t figure out what would be the best way to map this in my controller.

  #{form id:'targetsForm', method:'POST', action:@createTargets()}
      <table  id="targetsTable">
      <tr>
        <th>Name</th>
        <th>January</th>
        <th>February</th>
        <th>March</th>
      </tr>
      <tbody>
        <tr>
        <td class="center" id="object2">Object1</td>
        <td class="center"><input id="01-jan" type="number" name="01-jan" size="20" value="" class="target-input" /></td>
        <td class="center"><input id="01-feb" type="number" name="01-feb" size="20" value="" class="target-input" /></td>
        <td class="center"><input id="01-mar" type="number" name="01-mar" size="20" value="" class="target-input" /></td>
        </tr>
        <tr>
        <td class="center" id="object2">Object2</td>
        <td class="center"><input id="02-jan" type="number" name="02-jan" size="20" value="" class="target-input" /></td>
        <td class="center"><input id="02-feb" type="number" name="02-feb" size="20" value="" class="target-input" /></td>
        <td class="center"><input id="02-mar" type="number" name="02-mar" size="20" value="" class="target-input" /></td>
        </tr>
      </tbody>
      </table>
  #{/form}

How could I map object 1 and object 2 in the routes and controller, know that there might be n objects in the form?

  • 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-28T14:55:15+00:00Added an answer on May 28, 2026 at 2:55 pm

    In your template, you could do something like this:

    #{form @createTargets()}
    
        #{field 'january[0]'}
            <input type="number" name="${field.name}" value=""/>
        #{/field}
        #{field 'february[0]'}
            <input type="number" name="${field.name}" value=""/>
        #{/field}
        #{field 'march[0]'}
            <input type="number" name="${field.name}" value=""/>
        #{/field}
    
        #{field 'january[1]'}
            <input type="number" name="${field.name}" value=""/>
        #{/field}
        #{field 'february[1]'}
            <input type="number" name="${field.name}" value=""/>
        #{/field}
        #{field 'march[1]'}
            <input type="number" name="${field.name}" value=""/>
        #{/field}
    #{/form}
    

    And then in your controller, your createTargets method would look like this:

    public static void save(List<Integer> january, List<Integer> february, List<Integer> march) { ... }
    

    You don’t need to do anything special to map the fields from the template to the controller. Play will map the names (i.e. january, february, march) to the name of the parameters in the controller.

    Instead of having individual months as parameters into the action method, you could create an object like this:

    public class Target {
        private int january;
        private int february;
        private int march;
    
        ...
    }
    

    And then the template would look like this:

    #{form @createTargets()}
    
        #{field 'targets[0].january'}
            <input type="number" name="${field.name}" value=""/>
        #{/field}
        #{field 'targets[0].february'}
            <input type="number" name="${field.name}" value=""/>
        #{/field}
        #{field 'targets[0].march'}
            <input type="number" name="${field.name}" value=""/>
        #{/field}
    
        #{field 'targets[1].january'}
            <input type="number" name="${field.name}" value=""/>
        #{/field}
        #{field 'targets[1].february'}
            <input type="number" name="${field.name}" value=""/>
        #{/field}
        #{field 'targets[1].march'}
            <input type="number" name="${field.name}" value=""/>
        #{/field}
    #{/form}
    

    Then the controller would be simply this:

    public static void save(List<Target> targets) { ... }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have such code in my JSF template: <h:form> <table id=users cellspacing=0> <a4j:repeat var=person
I am hosting SpiderMonkey in a current project and would like to have template
I have some template code that I would prefer to have stored in a
we have a template project we often copy. so we can costumize the copy
There is one table that have fields included the add row button. I am
I have a table named Template which I set my messages to send them
I have this Razor Template <table> <tr> <td>@Html.RadioButtonFor(i => i.Value, 1)</td> <td>@Html.LabelFor(i => i.Value,
I have this input text: <html><head><meta http-equiv=content-type content=text/html; charset=utf-8></head><body><table cellspacing=0 cellpadding=0 border=0 align=center width=603>
I have a simple HTML input file; which contains a table. The column headers
I have a author model and a books model. A user can modify properties

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.