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>
faces-config.xml
or did you forget the annotations? We need to see why the managed bean is not retaining data after a server request. Could you please include your faces-config.xml? – maple_shaft<center></center>
tag is deprecated right? – Catfish