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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T12:35:51+00:00 2026-05-31T12:35:51+00:00

I’m having trouble making a dataTable where each row has a inputText and a

  • 0

I’m having trouble making a dataTable where each row has a inputText and a commandLink. When the link is clicked, only it’s row’s inputText’s data is submitted.

Something like this?

<h:dataTable value="#{bean.items}" var="item">
    <h:column>
        <h:inputText value="#{bean.value}"/>
    </h:column>
    <h:column>
        <h:commandLink action="#{bean.save}" value="save">
            <f:setPropertyActionListener target="#{bean.item}" value="#{item}" />
        </h:commandLink>
    </h:column>
</h:dataTable>

Bean:

@RequestScoped
public class Bean {

    private Item item;
    private String value;

Right now, as it is, it’s using the last row’s inputText to fill the value. I wrapped another h:form, but it broke other things and I’ve learned that nested h:form is not the right way to do it hehe

What’s the correct way to do this?

Thanks.

  • 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-31T12:35:53+00:00Added an answer on May 31, 2026 at 12:35 pm

    You’re binding the value of all HTML input elements to one and same bean property. This is of course not going to work if all those HTML input elements are inside the same form. All values are subsequently set on the very same property in the order as the inputs appeared in the form. That’s why you end up with the last value. You’d like to move that form to inside the <h:column> (move; thus don’t add/nest another one).

    The usual approach, however, would be to just bind the input field to the iterated object.

    <h:inputText value="#{item.value}"/>
    

    An alternative, if you really need to have your form around the table, is to have a Map<K, V> as bean property where K represents the type of the unique identifier of the object behind #{item} and V represents the type of value. Let’s assume that it’s Long and String:

    private Map<Long, String> transferredValues = new HashMap<Long, String>();
    
    // +getter (no setter necessary)
    

    with

    <h:inputText ... value="#{bean.values[item.id]}" />
    

    This way you can get it in the action method as follows:

    String value = values.get(item.getId());
    

    By the way, if you happen to target Servlet 3.0 containers which supports EL 2.2 (Tomcat 7, Glassfish 3, etc), then you can also just pass the #{req} as a method argument without the need for a <f:setPropertyActionListener>.

    <h:commandLink ... action="#{bean.save(item)}" />
    

    See also:

    • How and when should I load the model from database for h:dataTable
    • How can I pass selected row to commandLink inside dataTable?
    • How to dynamically add JSF components
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
Basically, what I'm trying to create is a page of div tags, each has
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm having trouble keeping the paragraph square between the quote marks. In firefox the
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I want use html5's new tag to play a wav file (currently only supported
In my XML file chapters tag has more chapter tag.i need to display chapters

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.