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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T09:40:26+00:00 2026-05-25T09:40:26+00:00

my form looks like this: When the user clicks + Add a new distance

  • 0

my form looks like this:

enter image description here

When the user clicks “+ Add” a new distance input shows up:

enter image description here

The user can repeat this operation as many times as desired, but all distances must be filled in, and individual messages must be served for missing data:

enter image description here

So i’m trying to stablish dynamic ids for the distance inputs. However, when i try to pass dynamic values everything fails. up to now i’ve tried two different techniques:

  • using the binding HtmlDataTable’s rowIndex <- it always shows -1
  • setting the id as an attribute of the Distance class <- ugly exception

here’s my code:

Backing bean:

private List<Distance> distances;
private HtmlDataTable distancesUI;

public void addDistance(ActionEvent e) {
    distances.add(new Distance());
}

JSPX:

<h:dataTable
binding="#{Bean.distancesUI}"   
value="#{Bean.distances}"
var="distance"> 
    <h:column> 
        <h:inputText 
        id ="distance_#{Bean.distancesUI.rowIndex}" // <- always renders "distance_-1"
        value="#{distance.value}" />
    </h:column>
</h:dataTable>

I need to be able to show individual “required” messages. Any ideas?

thanks in advance

  • 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-25T09:40:26+00:00Added an answer on May 25, 2026 at 9:40 am

    I need to be able to show individual “required” messages. Any ideas?

    For that you don’t need to fiddle with IDs. JSF will do it for you. Just do

    <h:dataTable id="table" value="#{bean.distances}" var="distance"> 
        <h:column> 
            <h:inputText id="distance" value="#{distance.value}" required="true" />
            <h:message for="distance" />
        </h:column>
    </h:dataTable>
    

    This will end up in generated HTML like follows:

    <table id="form:table">
        <tr><td><input id="form:table:0:distance" /></td></tr>
        <tr><td><input id="form:table:1:distance" /></td></tr>
        <tr><td><input id="form:table:2:distance" /></td></tr>
        ...
    </table>
    

    Rightclick the page in browser and choose View Source to see it yourself.

    Any validation error will just be shown in the same row as the input.

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

Sidebar

Related Questions

A string looks like this: <form id=unban method=post action=unban.php?uid=<? echo $uID; ?>> <input type=hidden
I have a form in a .html files where input/select box looks like this
I have a form that looks like this: class SampleForm(forms.Form): text = forms.CharField(max_length=100) In
I have a form that looks like this. <form action=index.php method=post> <select name=dropdownOption> <option
I would like to validate the DNF (Disjunctive normal form) which looks like this
I have a form that looks kind of like this: <div> <div class=contact> <h1>Person's
y0 c0derz! My formula looks like this: <form method=post action=index.php?sida=upl enctype=multipart/form-data name=myform> <input type=file
I have a webpage with a form, which looks kinda like this: @using (Html.BeginForm(MyAction,
I have a form that allows the user to add as many upload forms
I have 2 tables which in simplified form look like this: Products( id: int,

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.