Closed rootkit007 closed 11 years ago
Assigned to Sudheer.
Same problem here for any expression containing a method or something that is not a get/set property. I tried setting style="display: none;", but the outputText is read even if it's not shown.
Maybe data that is not visible on screen shouldn't be exported.
Could you please post your datatable and exporter code
I'm using the default ExcelExporter (xlsx) and traced the problem to the same line as rootkit007, it happens when expr.getType() is called for a datatable component like:
h:outputText value="#{fundReturns.getFundClassName(fundReturns.navReturns[date][eCounter.index].idtLinkedTo)}"
The error happens when the code tries to get the expected type to find a converter, because getType is for properties and not for methods.
I remember seeing the same discussion about PF dataExporter component. One of proposed fixes was to change that call to getExpectedType(), but I havent tried this myself
I have just tried and it works, but it returned me an Object, even with the return type of my method being a String, so I don't know whether it will break other things or not.
Hi,
We use getType() in other components too. The correct method is in ComponentsUtils.java. Sudheer, please use the method getConverter() from there. It works as follows:
public static Converter getConverter(final FacesContext fc, final UIComponent component) {
if (!(component instanceof EditableValueHolder)) {
return null;
}
Converter converter = ((EditableValueHolder) component).getConverter();
if (converter != null) {
return converter;
}
ValueExpression valueExpression = component.getValueExpression("value");
if (valueExpression == null) {
return null;
}
Class<?> converterType = valueExpression.getType(fc.getELContext());
if (converterType == null || converterType == String.class || converterType == Object.class) {
// no conversion is needed
return null;
}
return fc.getApplication().createConverter(converterType);
}
It works for me.
Do you mean my code above with "it works for me"?
Yes, I called getConverter() from ComponentUtils.java
Good to hear. This is how it works in JSF impl. too. PF didn't have these lines
if (converterType == null || converterType == String.class || converterType == Object.class) {
// no conversion is needed
return null;
}
and it was the problem. Don't know about the current PF version.
So, Sudheer, please fix the Exporter asap :-)
The String type check isn't right in all cases because user can have string converter for trimming etc. Please just call our ComponentUtils#getConverter, i will later change it to PF ComponentUtils
Set for 0.7.1
Fixed.
If my dataTable contains value expressions like:
it will render fine on the screen but throw 'Property getData not found on myBean' exception when exporting. This is apparently caused by this code in Exporter class:
//Try to guess else { ValueExpression expr = component.getValueExpression("value"); if (expr != null) { Class<?> valueType = expr.getType(context.getELContext()); if (valueType != null) { Converter converterForType = context.getApplication().createConverter(valueType);
on line expr.getType