dataTable selection issue

UI Components for JSF
Post Reply
Jeyaraman G
Posts: 6
Joined: 02 Aug 2010, 06:09

05 Aug 2010, 06:49

Hi

I had posted regarding an issue with dataTable row selection. There was no response. I could recreate the issue with the sample code from PrimeFaces demo. So, I am posting the issue again with different content.

I have a modal dialog that displays the content of the selected row in the dataTable. there are buttons to save, reset and exit from the dialog.

This modal dialog has fields with required="true". If the required validation fails on any of the fields in the dialog, clicking on any other row in the dataTable leads to the overwriting of the newly selected row's content with the previous row's content.

The code below is the modfied version of the dataTable sample in PrimeFaces demo.

editCars.xhtml

Code: Select all

<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:p="http://primefaces.prime.com.tr/ui"
      >

    <h:head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
        <title>Facelets Template</title>
    </h:head>

    <h:body>
        <h:form id="idList" prependId="false">

            <p:dataTable var="car" value="#{tableBean.cars}" paginator="true" rows="10"
                         selection="#{tableBean.selectedCar}" 
                         selectionMode="single"
                         update="display"
                         dynamic="true"
                         onselectComplete="carDialog.show()"
                         id="idCarTable">
                <p:column>
                    <f:facet name="header">
                        <h:outputText value="Model" />
                    </f:facet>
                    <h:outputText value="#{car.model}" />
                </p:column>

                 <p:column>
                    <f:facet name="header">
                        <h:outputText value="Manufacturer" />
                    </f:facet>
                    <h:outputText value="#{car.manufacturer}" />
                </p:column>

                <p:column>
                    <f:facet name="header">
                        <h:outputText value="Color" />
                    </f:facet>
                    <h:outputText value="#{car.color}" />
                </p:column>
            </p:dataTable>
        </h:form>

        <p:dialog header="Car Detail" widgetVar="carDialog"
                  modal="true" draggable="false" width="400">
            <h:form id="display" prependId="false">
                <p:messages/>
                <h:panelGrid columns="2">
                    <h:outputText value="Model:" />
                    <h:inputText value="#{tableBean.selectedCar.model}" style="font-weight:bold"
                                 required="true"
                                 requiredMessage="Model should be filled">

                    </h:inputText>

                    <h:outputText value="Manufacturer:" />
                    <h:inputText value="#{tableBean.selectedCar.manufacturer}" style="font-weight:bold"
                                 required="true"
                                 requiredMessage="Manufacturer should be filled"/>

                    <h:outputText value="Color:" />
                    <h:inputText value="#{tableBean.selectedCar.color}" style="font-weight:bold"/>
                </h:panelGrid>
                <h:panelGrid columns="4">
                    <h:column>
                        <p:commandButton value="Save" update="display"/>
                        <p:commandButton type="reset" value="Reset"/>
                        <p:commandButton value="Exit" update="idList" oncomplete="carDialog.hide()"/>

                        <p:ajaxStatus>
                            <f:facet name="start">
                                <h:graphicImage url="../img/ajaxloading.gif"/>
                            </f:facet>
                            <f:facet name="complete">
                                <h:outputText value=""/>
                            </f:facet>
                        </p:ajaxStatus>
                    </h:column>
                </h:panelGrid>
            </h:form>
        </p:dialog>


    </h:body>
</html>

TableBean.java

Code: Select all

package test;

import test.Car;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Random;
import java.util.UUID;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;

import javax.servlet.ServletContext;
@ManagedBean(name="tableBean")
@SessionScoped
public class TableBean {

	private List<Car> cars;

	private Car selectedCar;

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

		for(int i = 0 ; i < 50 ; i++)
			cars.add(new Car("Model_" + i, 5, "Brand_" + i, "Color_" + i));
	}

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

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



Car.java

Code: Select all

/*
 * Copyright 2009 Prime Technology.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package test;

import java.io.Serializable;

public class Car implements Serializable {

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

	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;
	}

	@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();
	}	
}


Steps to recreate the issue


1. Click on the row with model as "Model_5".
2. The dialog displays the correct data from the selected row.
3. Click exit.
4. Click on the row with model as "Model_4"
5. The dialog displays the correct data for Model_4.
6. Remove the content of the Model field.
7. Click Save button. "Model should be filled" message is displayed.
8. Click on exit button.
9. Click on the row with model as "Model_5".
10. The dialog displays the model as "Model_5" and the other fields display the incorrect value (values from Model_4 row).


The above works fine when there is no validation failure.
Is this a problem with the dataTable's selection attribute?

Thanks in advance.

Regards,
PrimeFaces 2.1
Mojarra 2.0.2
Tomcat 6.0.20

cagatay.civici
Prime
Posts: 18616
Joined: 05 Jan 2009, 00:21
Location: Cybertron
Contact:

05 Aug 2010, 12:14

Please create an issue ticket, as we are in the process of reimplementing the datatable, it would be good to make sure this is fixed during new implementation.

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 46 guests