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
how to rename columns in dataExporter?
-
- Prime
- Posts: 18616
- Joined: 05 Jan 2009, 00:21
- Location: Cybertron
- Contact:
As far as I know, still you can contribute a patch for XMLExporter class.
To make it simple I would replace just spaces with underscores.
Line 110 in XMLExporter.java
replace with
Therer'e more rare cases to deal with like name cannot start with a digit or "xml" prefix:
Line 110 in XMLExporter.java
Code: Select all
String tag = header.toLowerCase();
Code: Select all
String tag = header.toLowerCase().replaceAll(" ","_");
Code: Select all
if ((tag.charAt(0)>='0' && tag.charAt(0)<='9') || tag.startsWith('xml')) tag='_'+tag;
One more bug to fix. To deal with hidden and excluded columns error issue:
Updated XMLExporter.getheaderTexts():
and line 51 with the function call replace parameter:
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;
}
Code: Select all
List<String> headers = getHeaderTexts(columns);
There one more bug with miscounting hidden columns
Fix:
in Exporter.java line 46
replcae with:
It will fix miscounted columns in PDFExporter:
Fix:
in Exporter.java line 46
Code: Select all
if(Arrays.binarySearch(excludedColumns, i) < 0)
Code: Select all
if(Arrays.binarySearch(excludedColumns, i) < 0 && allColumns.get(i).isRendered())
Code: Select all
int numberOfColumns = columns.size();
-
- Prime
- Posts: 18616
- Joined: 05 Jan 2009, 00:21
- Location: Cybertron
- Contact:
Issue tracker is the best way to attach patches. Please create subversion patches, also we need these for all exporters for consistency.
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.
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.
-
- Prime
- Posts: 18616
- Joined: 05 Jan 2009, 00:21
- Location: Cybertron
- Contact:
Only committers can check in to the code, please create a subversion patch that would be easier for us to test.
I have attached the patch in https://code.google.com/p/primefaces/is ... il?id=1177
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?
// 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?
-
- Information
-
Who is online
Users browsing this forum: Google [Bot] and 62 guests