Weird behavior of binded dataTable

UI Components for JSF
Post Reply
jbmeyer
Posts: 18
Joined: 25 Jun 2010, 11:30

30 Jun 2010, 12:13

Hi,

I'm using binding in datatable in the last version of prime faces ( PrimeFaces-2.1.RC1-SNAPSHOT ), and when I click many time on a corner of a header, a new line in this header is created.
Here is a video to show what I'm saying :
http://www.youtube.com/watch?v=S1RtQKHQ3k8
This code works well with the version 2.0.2 of prime faces

Here is the code used in my JSF

Code: Select all

<p:dataTable id="resGroupBy"
									 styleClass="gridColumns1"
									 paginator="true" 
									 rows="50" 
									 binding="#{searchController.dynamicDataTable}"
									 rendered="#{ (searchZone.groupByResults != null and searchZone.displayGroupByResult) }">
</p:dataTable>
And here is the code used in my Request Scope bean

Code: Select all

.....
 dynamicDataTable.setValueExpression("value", createValueExpression("#{searchZone.dynamicList}", List.class));
			 dynamicDataTable.setVar("dynamicItem");
			
			int colWidth = DATATABLE_WIDTH / dynamicHeaders.length;
			
		     /*Iterate over columns. */
	   		for (int i = 0; i < sz.getDynamicList().get(0).size(); i++) {
	
		         /*Create <h:column>.*/
		         Column column = new Column();
		         dynamicDataTable.getChildren().add(column);
	
		         /*Create <h:outputText value="dynamicHeaders[i]"> for <f:facet name="header"> of column. */
	        	 HtmlOutputText header = new HtmlOutputText();
	        	 header.setValue(dynamicHeaders[i]);
	        	 column.setHeader(header);
	        	 
			    //column.setValueExpression("sortBy", createValueExpression("#{dynamicItem[" + i + "]}",String.class ) ) ;
			    // column.setValueExpression("filterBy", createValueExpression("#{dynamicItem[" + i + "]}",String.class ) ) ;
		       
	 		     column.setSortBy( createValueExpression("#{dynamicItem[" + i + "]}", String.class) );
	        	   
		         /*Create <h:outputText value="#{dynamicItem[" + i + "]}"> for the body of column.*/
		         HtmlOutputText output = new HtmlOutputText();
		         output.setValueExpression("value", createValueExpression("#{dynamicItem[" + i + "]}", String.class));
		         
		         column.getChildren().add(output);
		         column.setWidth(colWidth);
		         column.setResizable(true);
		         
		         
		    }
		}
....
This is a very easy example !

I don't know if you will be able to reproduce this bug but that's funny :)
JB

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

30 Jun 2010, 12:22

Is your column sortable?

jbmeyer
Posts: 18
Joined: 25 Jun 2010, 11:30

30 Jun 2010, 12:25

No the column is not sortable. But this is the same problem if add a sortBy or a filterBy.

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

01 Jul 2010, 18:55

I see what happens if you don't use binding? Can you replicate it even though binding is not used?

jbmeyer
Posts: 18
Joined: 25 Jun 2010, 11:30

02 Jul 2010, 09:21

If I don't use binding it work perfectly like in the showcase. I think the problem is coming from the binding itself.
And this code works perfectly with the version 2.0.2

jbmeyer
Posts: 18
Joined: 25 Jun 2010, 11:30

02 Jul 2010, 10:51

Here is a full example to test if you want

Code: Select all

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

import javax.el.ValueExpression;
import javax.enterprise.context.RequestScoped; 
import javax.faces.component.html.HtmlOutputText;
import javax.faces.context.FacesContext; 
import javax.inject.Named;  

import org.primefaces.component.column.Column;
import org.primefaces.component.datatable.DataTable;
 
@Named 
@RequestScoped 
public class DynamicBinding implements Serializable {
	private static final long serialVersionUID = 1L;
	
	private DataTable  dynamicDataTable = null;
  
	private List<List<String>> data ;
	
	public DataTable getDynamicDataTable() {
		 		return dynamicDataTable;
	}

	private ValueExpression createValueExpression(String valueExpression, Class<?> valueType) {
        FacesContext facesContext = FacesContext.getCurrentInstance();
        return facesContext.getApplication().getExpressionFactory().createValueExpression(
            facesContext.getELContext(), valueExpression, valueType);
    }
	
	public void setDynamicDataTable(DataTable dynamicDataTable) {
		this.dynamicDataTable = dynamicDataTable;
		
		if ( this.dynamicDataTable == null)
		{
			this.dynamicDataTable = new DataTable();
		}
		 
		String[] headerName = new String[]{"Pet","Color","Number" };
		
		data = new ArrayList<List<String>>(); 
		data.add(Arrays.asList(new String[]{"Dog","Cat","Fish"})) ;
		data.add(Arrays.asList(new String[]{"Black","White","Red"})) ;
		data.add(Arrays.asList(new String[]{"2","1","4"})) ;
		
		dynamicDataTable.setValueExpression("value", createValueExpression("#{dynamicBinding.data}", List.class));
		dynamicDataTable.setVar("selectedList");
		 
	     /*Iterate over columns. */
   		for (int i = 0; i < headerName.length; i++) {

	         /*Create <h:column>.*/
	         Column column = new Column();
	         dynamicDataTable.getChildren().add(column);
 
        	 HtmlOutputText header = new HtmlOutputText();
        	 header.setValue(headerName[i]);
        	 column.setHeader(header);
        	  	   
	         HtmlOutputText output = new HtmlOutputText();
	         output.setValueExpression("value", createValueExpression("#{selectedList[" + i + "]}", String.class));
	         
	      
	         
	         column.getChildren().add(output);
	       
	         column.setResizable(true);
	         
	         
	    }
	}

	public List<List<String>> getData() {
		return data;
	}

	public void setData(List<List<String>> data) {
		this.data = data;
	}
 
	
	 
	
}
And here is the JSF

Code: Select all

<!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:ui="http://java.sun.com/jsf/facelets"
   xmlns:f="http://java.sun.com/jsf/core"
   xmlns:p="http://primefaces.prime.com.tr/ui">
	

	<h:head>
      <title>Test</title>
      <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  
      <link type="text/css" rel="stylesheet" href="#{request.contextPath}/resources/css/cupertino/skin.css"></link>    
 
 
   </h:head>

   <h:body >
 
 <h:form >
 
   			<p:dataTable id="testBinding" binding="#{dynamicBinding.dynamicDataTable}" >
			</p:dataTable>
 </h:form>
			
      
   </h:body>
</html>
If you click several times very fast on the corner of a header it will create new lines on headers.
We won't be able to migrate to primefaces 2.1.RC1 with this problem.
Any ideas ?

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 45 guests