I am stuck and need external help from JSF experts with the following problem: I defined some converters in faces-config.xml for certain classes, so I don’t need to constantly use the attribute converter or tag. For instance:
<converter>
<converter-for-class>org.joda.time.DateTime</converter-for-class>
<converter-class>com.example.converter.JodaDateTimeConverter</converter-class>
</converter>
Now there is a need for a crawler for the JSF component (mostly rich: extendedDataTable), which builds the entire tree of components and converts level by level into CSV, HTML, or whatever may be needed later. Namely, the general way to export to CSV, HTML, ... without having to implement it again each time. This is almost done (thanks to the great idea of my old colleague), and it works fine, except for one part:
Object expressionResult = expression.getValue(FacesContext.getCurrentInstance().getELContext());
expressionResultString = expressionResult.toString();
This command retrieves the value of h: outputText and converts it to String. The last line is what I want to replace with a converter for the class, if there is a special converter for a specific Result expression. I cannot find out how to find this exact converter for my classes (as indicated by faces-config). FacesContext does not seem to contain any useful method / object for my use case. Accessing face-config.xml directly seems to be wrong. The correct approach might look something like this:
Converter converter = magically_fetch_the_correct_converter_for_expressionResult_type;
converter.getAsString(FacesContext.getCurrentInstance(), component,
expressionResult);
It would be quite easy if I used the converter identifier and the corresponding attribute / tag for the components themselves, but I really want to avoid such useless additional code.
Can someone out there please help me?
source
share