question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

TreeTable/Datatable: Dynamic Columns Issue

See original GitHub issue

1) Environment

2) Expected behavior

3) Actual behavior

org.primefaces.component.api.DynamicColumn cannot be cast to org.primefaces.component.column.Column: java.lang.ClassCastException: org.primefaces.component.api.DynamicColumn cannot be cast to org.primefaces.component.column.Column
	at org.primefaces.component.treetable.TreeTable.updateColumnsVisibility(TreeTable.java:655)
	at org.primefaces.component.treetable.TreeTableRenderer.preRender(TreeTableRenderer.java:226)
	at org.primefaces.component.treetable.TreeTableRenderer.encodeEnd(TreeTableRenderer.java:161)

4) Steps to reproduce

Press “Refresh” button

5) Sample XHTML

<h:form id="form">
	<p:commandButton value="Refresh" update="@form" />
	<p:commandButton id="toggler" type="button" value="Columns" style="float:right" icon="ui-icon-calculator" />
	<p:columnToggler datasource="idDataTable" trigger="toggler" />

	<p:treeTable id="idDataTable" var="cars" value="#{tableBean.carsTree}">
		<p:column value="Column">
			<h:outputText value="Column" />
		</p:column>
		<p:columns value="#{tableBean.columns}" var="column" columnIndexVar="columnIndx" visible="true">
			<f:facet name="header">
				#{column.header}
			</f:facet>
			<h:outputText value="#{cars[column.property]}" />
		</p:columns>
	</p:treeTable>
</h:form>

6) Sample bean

public class TableBean implements Serializable {
    private List<ColumnModel> columns = new ArrayList<ColumnModel>();
    private DefaultTreeNode carsTree = new DefaultTreeNode();

	public TableBean() {
        populateColumns();
        
        Car car = new Car();
        car.setManufacturer("Audi");
        car.setModel("A4");
        car.setYear(2015);
        new DefaultTreeNode(car, carsTree);
    }

    public void populateColumns() {
        String[] columnKeys = new String[]{"model","year","color"};
        for(String columnKey : columnKeys) {
            columns.add(new ColumnModel(columnKey.toUpperCase(), columnKey));
        }
    }
    //getters and setters

    public List<ColumnModel> getColumns() {
		return columns;
	}

	public void setColumns(List<ColumnModel> columns) {
		this.columns = columns;
	}

    public DefaultTreeNode getCarsTree() {
		return carsTree;
	}

	public void setCarsTree(DefaultTreeNode carsTree) {
		this.carsTree = carsTree;
	}

	static public class ColumnModel {
        private String header;
        private String property;

        public ColumnModel(String header, String property) {
            this.header = header;
            this.property = property;
        }
        public String getHeader() {
            return header;
        }
        public String getProperty() {
            return property;
        }
    }
}

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:52 (48 by maintainers)

github_iconTop GitHub Comments

1reaction
tandraschkocommented, Dec 14, 2020

i refactored it now and fixed the exception but it still doesnt work and all columns are hidden

0reactions
mellowarecommented, Dec 15, 2020

Weird you are right its definitely a firefox issue doesn’t happen on Chrome or Edge. Let me see what I can find out.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Dynamic Columns For TreeTable - PrimeFaces
Static p:column and Dynamic p:columns can be used together and sorting is also supported using a dynamic column. Live demo is available at ......
Read more >
Dynamic Columns Problem — DataTables forums
I have a request where the datatable columns depend on the value of a select field. Initially the datatable has 17 columns.
Read more >
Problem with 'Dynamic' row height in treetable - Webix Forum
Hi, I am using 'adjustRowHeight()' inorder to make the row height dynamic in a treetable. But the folder for treetable gets dislocated.
Read more >
Jquery-TreeTable how to dynamically add columns in the tree ...
But now I have problem even in show rows, it does not show as tree in tree-table. Could you tell me where is...
Read more >
Creating DataTable Programmatically with Dynamic Columns
This example demonstrates how to create dynamic DataTable with runtime column ... selectedColumns}" label="Table Columns"> <f:selectItems ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found