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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T12:41:27+00:00 2026-06-09T12:41:27+00:00

I have a contact table, this table contains a first name, a last name,

  • 0

I have a contact table, this table contains a first name, a last name, and multiple phone numbers. So my model is something like



    Contact {
    String firstName;
    String lastName;
    List phones;
    }

    Phone {
    String category; //home, work, mobile, etc
    String phoneNumber;
    }


So it will have web page contains two input text for first name and last name, and an add phone button. When add button is clicked, it will generate two input text again for category and phone number, and an delete button to that row.

I have tried using indexed=true, it will generate an html like

<input type="text" name="phone[0].category" ... />
<input type="text" name="phone[0].phoneNumber" ... />

The problem is, i dont know how to write the javascript, because i dont know what is current index if user click add button, how about if user have clicked delete button and then add button, what index it will be? It is ok if i have missing index? Something like

<input type="text" name="phone[0].category" ... />
<input type="text" name="phone[0].phoneNumber" ... />
<input type="text" name="phone[3].category" ... />
<input type="text" name="phone[3].phoneNumber" ... />

Note: please consider for the edit scenario too.

  • 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-09T12:41:28+00:00Added an answer on June 9, 2026 at 12:41 pm

    The first thing here is to use well the indexed and logic:iterate tags to generate the code. If having doubts about this, check out this answer given by me, which explains in detail how to use indexed attributes in struts: indexed and logic:iterate

    Then, you have to consider the scenario where an user wants to add or delete rows, and update indexes correctly so struts will be able to retrieve data as you submit the form. I encountered this problem once and what I did was:

  2. on add: using javascript, find out what is the last line of the table and, by looking at the generated code of the page, generate a new table row with empty contents, the index inside the square brackets. Finally, add to table
  3. EXAMPLE:

    a table:

    <table><tr><td name='whatever[0].something'>asdf</td></tr>  
    <tr><td name='whatever[1].something'>asdf</td></tr>
    <tr><td name='whatever[2].something'>asdf</td></tr>
    </table>
    

    to add a row, create it in javascript like this:

    var newRow = '<tr><td name='whatever[3].something'>asdf</td></tr>
    

    and append it to the table.

  4. on del:Using the same technique as above find out which line (or corresponding index) was deleted. Then, edit the indexes of the remaining rows so that it matches the order of elements for the subsequent rows.
  5. EXAMPLE:

    a table:

    <table><tr><td name='whatever[0].something'>asdf0</td></tr>  
    <tr><td name='whatever[1].something'>asdf1</td></tr>
    <tr><td name='whatever[2].something'>asdf2</td></tr>
    </table>
    

    let’s say you delete asdf1 by removing it from the dom. then, the new table will look like this:

    <table><tr><td name='whatever[0].something'>asdf0</td></tr>  
    <tr><td name='whatever[2].something'>asdf2</td></tr>
    </table>
    

    now we have to update indexes so it matches the right order, by changing the name of the second td to have an index of 1, that way, the table is back to a struts indexed format:

    <table><tr><td name='whatever[0].something'>asdf0</td></tr>  
    <tr><td name='whatever[1].something'>asdf2</td></tr>
    </table>
    

    I hope it’s clear enough. I obviously can’t write all the js functions, since they require some work, but with this information you can make it on your own.

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

Sidebar

Related Questions

I have a table in MySQL of contact information ; first name , last
I have a table which contains contact information. This table has 1 column relevant
I have a table for a contact form and this table contains another table
I have a contacts table which contains fields such as postcode , first name
I have a table of contact details (name, province, etc) and I have a
I have some tables like this : I. parent table : id_client id_group package
I have a table that contains the columns: employer_id contact_id primary First two are
We have a SQL Server table containing Company Name, Address, and Contact name (among
I have a simple database with a Persons table UserId, Name,DOB The table contains
I have about 1 million records in my contact table in the DB, now

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.