how to rename columns in dataExporter?

UI Components for JSF
Post Reply
User avatar
wikisky
Posts: 53
Joined: 16 Jul 2010, 17:30
Location: Oakville,ON
Contact:

25 Aug 2010, 04:48

Is it possible to rename column names in dataExporter component?
I need to normalize column names in xml report, i.e. remove spaces and other unacceptable for xml tag name characters.
Thanks

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

25 Aug 2010, 10:51

As far as I know, still you can contribute a patch for XMLExporter class.

User avatar
wikisky
Posts: 53
Joined: 16 Jul 2010, 17:30
Location: Oakville,ON
Contact:

25 Aug 2010, 19:50

To make it simple I would replace just spaces with underscores.

Line 110 in XMLExporter.java

Code: Select all

String tag = header.toLowerCase();
replace with

Code: Select all

String tag = header.toLowerCase().replaceAll(" ","_");
Therer'e more rare cases to deal with like name cannot start with a digit or "xml" prefix:

Code: Select all

if ((tag.charAt(0)>='0' && tag.charAt(0)<='9') || tag.startsWith('xml')) tag='_'+tag;

User avatar
wikisky
Posts: 53
Joined: 16 Jul 2010, 17:30
Location: Oakville,ON
Contact:

25 Aug 2010, 20:39

One more bug to fix. To deal with hidden and excluded columns error issue:
Updated XMLExporter.getheaderTexts():

Code: Select all

    private List<String> getHeaderTexts(List<UIColumn> columns) {
        List<String> headers = new ArrayList<String>();

        for(UIColumn child:columns) {
            if (child.isRendered() && child.getHeader() != null && child.getHeader().isRendered()) {
                String value = ComponentUtils.getStringValueToRender(FacesContext.getCurrentInstance(), child.getHeader());

                headers.add(value);
            } else {
                headers.add("");
            }
        }
        return headers;
    }
and line 51 with the function call replace parameter:

Code: Select all

List<String> headers = getHeaderTexts(columns);

User avatar
wikisky
Posts: 53
Joined: 16 Jul 2010, 17:30
Location: Oakville,ON
Contact:

25 Aug 2010, 22:23

There one more bug with miscounting hidden columns
Fix:
in Exporter.java line 46

Code: Select all

if(Arrays.binarySearch(excludedColumns, i) < 0)
replcae with:

Code: Select all

if(Arrays.binarySearch(excludedColumns, i) < 0  && allColumns.get(i).isRendered())
It will fix miscounted columns in PDFExporter:

Code: Select all

    	int numberOfColumns = columns.size();

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

25 Aug 2010, 23:54

Issue tracker is the best way to attach patches. Please create subversion patches, also we need these for all exporters for consistency.

User avatar
wikisky
Posts: 53
Joined: 16 Jul 2010, 17:30
Location: Oakville,ON
Contact:

26 Aug 2010, 00:15

I added new issue: https://code.google.com/p/primefaces/is ... il?id=1177
But, it would be easier if I check in the changes myself. I will review other export options. I can contribute some other features that I'm missing as well.

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

26 Aug 2010, 02:30

Only committers can check in to the code, please create a subversion patch that would be easier for us to test.

User avatar
wikisky
Posts: 53
Joined: 16 Jul 2010, 17:30
Location: Oakville,ON
Contact:

26 Aug 2010, 04:22


jnoone
Posts: 2
Joined: 06 Apr 2011, 00:08

18 Apr 2011, 15:51

Would it be possible to add these three lines of code to the getHeaderTexts? this will take care of 95% of the invalid xml problems with column headers.

// if there are non number or letter characters replace them
// with _
value = value.replaceAll("[^<>0-9A-Za-z]", "_");

// replace the <xml with <_
value = value.replaceFirst("^<xml", "<_");

// replace any number that starts the header with an _
value = value.replaceAll("<[0-9]", "<_");


can I piggy back off the patch that was submitted for the hidden columns or do I need to submit my own patch?

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

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