InputText in Datatable with Checkboxes

UI Components for JSF
Post Reply
JStzb
Posts: 2
Joined: 22 May 2017, 11:24

22 May 2017, 12:04

In my project I use primefaces datatable with multirow selection and to edit containing data i use Primefaces inputtext.

In IE11 Compatbility Mode these inputs don't accept whitespaces.

Reproducible with derived example of Basic Datatable example from
https://www.primefaces.org/showcase/ui/ ... asic.xhtml
and following setup:
JSF: 2.0.11-03
Primefaces: 6.1
Webserver: apache-tomee-webprofile-1.7.4
Java:1.6

basic.xhtml

Code: Select all

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

<h:head>
	<f:facet name="first">
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    </f:facet>
	<title>Test</title>
	<meta charset="utf-8" />
	<meta name="viewport" content="width=device-width, initial-scale=1" />
	<link rel="stylesheet" href="../css/style.css" />
	<h:outputScript library="primefaces" name="jquery/jquery.js" target="head" />
	<h:outputScript name="jquery/jquery-plugins.js" library="primefaces" />
</h:head>
<h:body>
	<h:form>
		<p:dataTable var="car" value="#{dtBasicView.cars}" selection="#{dtBasicView.selectedCars}" rowKey="#{car.hashCode()}">
		
			<p:column selectionMode="multiple" style="width:16px;text-align:center"/>
		
		    <p:column headerText="Id">
		        <p:inputText value="#{car.id}"  />
		    </p:column>
		 
		    <p:column headerText="Year">
		        <p:inputText value="#{car.year}"  />
		    </p:column>
		 
		    <p:column headerText="Brand">
		        <p:inputText value="#{car.brand}"  />
		    </p:column>
		 
		    <p:column headerText="Color">
		        <p:inputText value="#{car.color}"  />
		    </p:column>
		</p:dataTable>
	</h:form>
</h:body>
</html>

Controller

Code: Select all

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import javax.annotation.PostConstruct;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import javax.faces.bean.ViewScoped;


@ManagedBean(name = "dtBasicView")
@ViewScoped
public class BasicView implements Serializable
{
  private static final long serialVersionUID = 2849222102019842736L;

  private List<Car> cars;
  private List<Car> selectedCars;


  @ManagedProperty("#{carService}")
  private CarService service;


  @PostConstruct
  public void init()
  {
    cars = service.createCars( 10 );
    this.selectedCars = new ArrayList<Car>();
  }


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


  public void setService( CarService service )
  {
    this.service = service;
  }


  public List<Car> getSelectedCars()
  {
    return selectedCars;
  }


  public void setSelectedCars( List<Car> selectedCars )
  {
    this.selectedCars = selectedCars;
  }
}

Code: Select all

package com.twt.layoutDB.controller;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.UUID;

import javax.faces.bean.ApplicationScoped;
import javax.faces.bean.ManagedBean;


@ManagedBean(name = "carService")
@ApplicationScoped
public class CarService
{

  private final static String[] colors;

  private final static String[] brands;

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

    brands = new String[10];
    brands[0] = "BMW";
    brands[1] = "Mercedes";
    brands[2] = "Volvo";
    brands[3] = "Audi";
    brands[4] = "Renault";
    brands[5] = "Fiat";
    brands[6] = "Volkswagen";
    brands[7] = "Honda";
    brands[8] = "Jaguar";
    brands[9] = "Ford";
  }


  public List<Car> createCars( int size )
  {
    List<Car> list = new ArrayList<Car>();
    for( int i = 0; i < size; i++ )
    {
      list.add( new Car( getRandomId(), getRandomBrand(), getRandomYear(), getRandomColor(), getRandomPrice(),
              getRandomSoldState() ) );
    }

    return list;
  }


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


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


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


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


  public int getRandomPrice()
  {
    return (int) (Math.random() * 100000);
  }


  public boolean getRandomSoldState()
  {
    return (Math.random() > 0.5) ? true : false;
  }


  public List<String> getColors()
  {
    return Arrays.asList( colors );
  }


  public List<String> getBrands()
  {
    return Arrays.asList( brands );
  }
}

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: Google [Bot] and 54 guests