New reply on DataCleaner's online discussion forum
(https://datacleaner.org/forum):
Dennis replied to subject 'Results missing when exporting to HTML'
-------------------
Hi Guy,
I tried making a quick test, and this seems to work for me:
{{{
Crosstab<Integer> regionCrosstab = new Crosstab<>(Integer.class,
"Region");
regionCrosstab.where("Region", "EU").put(1, true);
regionCrosstab.where("Region", "USA").put(2, true);
regionCrosstab.where("Region", "Asia").put(3, true);
CrosstabHtmlFragment regionFragment = new
CrosstabHtmlFragment(regionCrosstab, rendererFactory);
Crosstab<Integer> stuffCrosstab = new Crosstab<>(Integer.class,
"Stuff");
stuffCrosstab.where("Stuff", "Foo").put(4, true);
stuffCrosstab.where("Stuff", "Bar").put(5, true);
stuffCrosstab.where("Stuff", "Baz").put(6, true);
CrosstabHtmlFragment stuffFragment = new
CrosstabHtmlFragment(stuffCrosstab, rendererFactory);
HtmlFragment bothCrosstabs = new HtmlFragment() {
@Override
public void initialize(final HtmlRenderingContext context) {
regionFragment.initialize(context);
stuffFragment.initialize(context);
}
@Override
public List<HeadElement> getHeadElements() {
List<HeadElement> headElements = new ArrayList<>();
headElements.addAll(regionFragment.getHeadElements());
headElements.addAll(stuffFragment.getHeadElements());
return headElements;
}
@Override
public List<BodyElement> getBodyElements() {
List<BodyElement> bodyElements = new ArrayList<>();
bodyElements.add(new SimpleBodyElement("<p>Region
crosstab:</p>"));
bodyElements.addAll(regionFragment.getBodyElements());
bodyElements.add(new SimpleBodyElement("<p>Stuff
crosstab:</p>"));
bodyElements.addAll(stuffFragment.getBodyElements());
return bodyElements;
}
};
}}}
The NPEs was probably because the CrosstabHtmlFragments wasn't initialized.
However, as you can see, it's not entirely simple: The renderer is not
initialized with a rendering context (for some reason), but the fragments are.
So by returning a new fragment implementation we can do the initialization when
the rendering context is available (making the HtmlFragment implementation into
a nested or top-level class would probably make my demo code a little less ugly
:))
By the way, since we currently don't have any head elements and only a single
body element in the CrosstabHtmlFragment, you _could_ make it a little simpler
by relying on that, but it would mean that it might break if we change it later
so I'd keep the full copy of head and body elements.
Best regards,
Dennis
-------------------
View the topic online to reply - go to
https://datacleaner.org/topic/1155/Results-missing-when-exporting-to-HTML
--
You received this message because you are subscribed to the Google Groups
"DataCleaner-notify" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/datacleaner-notify.
For more options, visit https://groups.google.com/d/optout.