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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T22:11:22+00:00 2026-06-08T22:11:22+00:00

Edit2 – I’ve added the faces-config.xml at the end of the post. I’m having

  • 0

Edit2 – I’ve added the faces-config.xml at the end of the post.

I’m having problems with Primefaces datatable row selection. I want to be able to select a row and move the data into an object that I can then manipulate. I’m using a model based on the primefaces showcase example, but it doesn’t work. Frankly, I’m running out of ideas as to what is wrong. Below is my xhtml and managedbean.

<html xmlns="http://www.w3c.org/1999/xhtml"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:p="http://primefaces.org/ui" >
<h:head>

</h:head>
<h:body>
<center>
<h:form id="form">

<p:dataTable id="personTable" var="client" value="#{tableBean.persons}" rowKey="#{client.name}"
             selection="#{tableBean.person}" selectionMode="single">

    <f:facet name="header">
        Click "View" button after selecting a row to see details
    </f:facet>

    <p:column headerText="Name">
        #{client.name}
    </p:column>

    <p:column headerText="Address">
        #{client.address}
    </p:column>

    <p:column headerText="Phone" >
        #{client.phone}
    </p:column>
</p:dataTable>

<h:panelGrid id="display" columns="2" cellpadding="4">


        <h:outputText value="Name:" />
        <h:outputText value="#{tableBean.person.name}" />

        <h:outputText value="Address:" />
        <h:outputText value="#{tableBean.person.address}" />

        <h:outputText value="Phone:" />
        <h:outputText value="#{tableBean.person.phone}" />

</h:panelGrid>

</h:form>

</center>
</h:body>
</html>

Managed Bean here:

package com.dave.test;

import java.util.ArrayList;
import java.util.List;

public class TableBean {

private List<Person> persons = null;
private Person person;

public TableBean() {
    persons = new ArrayList<Person>();
    persons.add(new Person("Jimmy", "18 Maple", "337-278-1019"));
    persons.add(new Person("Sally", "47 Oak", "787-509-3819"));
    persons.add(new Person("Roger", "754 Fifth Ave.", "926-420-8219"));
    persons.add(new Person("Mimi", "891 2nd St.", "713-371-8632"));

}

public List<Person> getPersons() {
    return persons;
}

public void setPersons(List<Person> persons) {
    this.persons = persons;
}

public Person getPerson() {
    return person;
}

public void setPerson(Person person) {
    this.person = person;
}


}

Thanks, Dave

<?xml version="1.0" encoding="UTF-8"?>
<faces-config version="2.0" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xi="http://www.w3.org/2001/XInclude"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"         
 xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-    
 facesconfig_2_0.xsd">
 <managed-bean>
   <managed-bean-name>tableBean</managed-bean-name>
   <managed-bean-class>com.dave.test.TableBean</managed-bean-class>
   <managed-bean-scope>request</managed-bean-scope>
 </managed-bean>
</faces-config>
  • 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-08T22:11:26+00:00Added an answer on June 8, 2026 at 10:11 pm

    I’m assuming that when you click the row, there is no data. That is because you are using a request scoped bean. This means that when you load the page, the bean is populated. After the page is loaded, the bean is gone.

    I would suggest changing your scope to ViewScope to see if that helps at all.

    Also, if you’re using jsf 2.0, you can use annotations instead of the faces-config.xml file. Your backer would look like this:

    package com.dave.test;
    
    import java.util.ArrayList;
    import java.util.List;
    
    public class TableBean {
    
    private List<Person> persons = null;
    private Person person;
    
    @ManagedBean
    @ViewScoped
    public TableBean() {
        persons = new ArrayList<Person>();
        persons.add(new Person("Jimmy", "18 Maple", "337-278-1019"));
        persons.add(new Person("Sally", "47 Oak", "787-509-3819"));
        persons.add(new Person("Roger", "754 Fifth Ave.", "926-420-8219"));
        persons.add(new Person("Mimi", "891 2nd St.", "713-371-8632"));
    
    }
    
    public List<Person> getPersons() {
        return persons;
    }
    
    public void setPersons(List<Person> persons) {
        this.persons = persons;
    }
    
    public Person getPerson() {
        return person;
    }
    
    public void setPerson(Person person) {
        this.person = person;
    }
    
    
    }
    

    Now you can remove your managed bean stuff from faces-config.xml.

    EDIT
    I just realized you don’t have an ajax event to handle the row selection. If you’re looking at the primefaces instant row selection, you need to notice that they are using <p:ajax event="rowSelect" ..../> along with a method in the backing bean to handle this.

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

Sidebar

Related Questions

EDIT: The issue underneath is fixed, GO TO EDIT2 in this post. I have
edit2: solution SQLite and `Object reference not set` exception I am having a hard
edit3: i added the webconfig from the server edit2: I ran the log and
EDIT2: the problem seems to be my xsd. it validates pretty much every XML.
EDIT2 Looks like I can't read properly, disregard this post, I will try to
EDIT2: [SOLVED] The create method in the controller file does not end until after
EDIT2: Waiting to see if my changes were successful. EDIT: I reinstalled everything using
Edit2: After finally being able to profile the two against each other, it appears
EDIT2: OK this is weird. (I can't answer my own question, so I just
EDIT2 : I'm going to be more clear so everybody understands my question. I

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.