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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T13:08:10+00:00 2026-06-09T13:08:10+00:00

I’m trying execute the DataTable example avaiable on Primefaces Showcase . All functions works

  • 0

I’m trying execute the DataTable example avaiable on Primefaces Showcase. All functions works but when i select a row, the value of the selected row isn’t displayed on my <p:dialog>.

I’ve already checked all alternatives and nothing works. Could someone help me?

I’m using Primefaces 3.3 and glassfish 3.0.1. Here goes my code:

dataTableComplex.xhtml

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

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

    <h:head>

    </h:head>

    <body>

        <h:form id="form">

            <p:dataTable var="car" value="#{tableBean.cars}" rowKey="#{car.model}" paginator="true" rows="10"
                         selection="#{tableBean.selectedCar}" selectionMode="single" id="carsTable">

                <p:ajax event="rowSelect" update=":form:display" oncomplete="carDialog.show()" />

                <f:facet name="header">
                    List of Cars
                </f:facet>

                <p:column headerText="Model" sortBy="#{car.model}" filterBy="#{car.model}" id="model">
                    #{car.model}
                </p:column>

                <p:column headerText="Year" sortBy="#{car.year}" filterBy="#{car.year}" id="year">
                    #{car.year}
                </p:column>

                <p:column headerText="Manufacturer" sortBy="#{car.manufacturer}" filterBy="#{car.manufacturer}" id="manufacturer">
                    #{car.manufacturer}
                </p:column>

                <p:column headerText="Color" sortBy="#{car.color}" filterBy="#{car.color}" id="color">
                    #{car.color}"
                </p:column>

            </p:dataTable>

            <p:dialog header="Car Detail" widgetVar="carDialog" resizable="false"
                      width="200" showEffect="explode" hideEffect="explode">

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

                    <h:outputText value="Model:" />
                    <h:outputText value="#{tableBean.selectedCar.model}" id="model"/>

                    <h:outputText value="Year:" />
                    <h:outputText value="#{tableBean.selectedCar.year}" id="year"/>

                    <h:outputText value="Manufacturer:" />
                    <h:outputText value="#{tableBean.selectedCar.manufacturer}" id="manufacturer"/>

                    <h:outputText value="Color:" />
                    <h:outputText value="#{tableBean.selectedCar.color}" id="color"/>
                </h:panelGrid>
            </p:dialog>
        </h:form>            
    </body>

</html>

TableBean.java

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import javax.enterprise.context.SessionScoped;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;

@ViewScoped
@ManagedBean(name = "tableBean")
@SessionScoped

public class TableBean implements Serializable {

private final static String[] colors;

private final static String[] manufacturers;

static {
    colors = new String[10];
    colors[0] = "Black";
    colors[1] = "White";
    colors[2] = "Green";
    colors[3] = "Red";
    colors[4] = "Blue";
    colors[5] = "Orange";
    colors[6] = "Silver";
    colors[7] = "Yellow";
    colors[8] = "Brown";
    colors[9] = "Maroon";

    manufacturers = new String[10];
    manufacturers[0] = "Mercedes";
    manufacturers[1] = "BMW";
    manufacturers[2] = "Volvo";
    manufacturers[3] = "Audi";
    manufacturers[4] = "Renault";
    manufacturers[5] = "Opel";
    manufacturers[6] = "Volkswagen";
    manufacturers[7] = "Chrysler";
    manufacturers[8] = "Ferrari";
    manufacturers[9] = "Ford";
}

private List<Car> cars;

private Car selectedCar;

private Car[] selectedCars;

public TableBean() {
    cars = new ArrayList<Car>();

    populateRandomCars(cars, 50);
}

public Car getSelectedCar() {
    return selectedCar;
}

public void setSelectedCar(Car selectedCar) {
    this.selectedCar = selectedCar;
}

private void populateRandomCars(List<Car> list, int size) {
    for(int i = 0 ; i < size ; i++)
        list.add(new Car(getRandomModel(), getRandomYear(), getRandomManufacturer(), getRandomColor()));
}

private int getRandomYear() {
    return (int) (Math.random() * 50 + 1960);
}

private String getRandomColor() {
    return colors[(int) (Math.random() * 10)];
}

private String getRandomManufacturer() {
    return manufacturers[(int) (Math.random() * 10)];
}

private String getRandomModel() {
    return UUID.randomUUID().toString().substring(0, 8);
}

public List<Car> getCars() {
    return cars;
}
}

Car.java

import java.io.Serializable;
import javax.enterprise.context.SessionScoped;
import javax.faces.bean.ManagedBean;

@ManagedBean(name = "car")
@SessionScoped

public class Car implements Serializable {

private String model;
private int year;
private String manufacturer;
private String color;
private int price;

public Car(){

}
public Car(String model, int year, String manufacturer, String color) {
            this.model = model;
            this.year = year;
            this.manufacturer = manufacturer;
            this.color = color;
    }

    public Car(String model, int year, String manufacturer, String color, int price) {
            this.model = model;
            this.year = year;
            this.manufacturer = manufacturer;
            this.color = color;
    this.price = price;
    }

    public String getModel() {
            return model;
    }

    public void setModel(String model) {
            this.model = model;
    }

    public int getYear() {
            return year;
    }

    public void setYear(int year) {
            this.year = year;
    }

    public String getManufacturer() {
            return manufacturer;
    }

    public void setManufacturer(String manufacturer) {
            this.manufacturer = manufacturer;
    }

    public String getColor() {
            return color;
    }

    public void setColor(String color) {
            this.color = color;
    }

 public int getPrice() {
    return price;
}

public void setPrice(int price) {
    this.price = price;
}

    @Override
    public boolean equals(Object obj) {
            if(obj == null)
                    return false;

            if(!(obj instanceof Car))
                    return false;

            Car compare = (Car) obj;

            return compare.model.equals(this.model);
    }

    @Override
    public int hashCode() {
            int hash = 1;

        return hash * 31 + model.hashCode();
    }

@Override
public String toString() {
    return "Car{" + "model=" + model + ", year=" + year + ", manufacturer=" + manufacturer + ", color=" + color + ", price=" + price + '}';
}
}

Edited: to solve this problem just add @ViewScoped on TableBean.java.

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

    Your TableBean should be ViewScoped.

    Add @ViewScoped on top of TableBean or configure it using faces-config.xml file.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm trying to select an H1 element which is the second-child in its group
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I am trying to render a haml file in a javascript response like so:
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this

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.