GeoChart event handle

Community Driven Extensions Project
Post Reply
sentenced37
Posts: 3
Joined: 10 Sep 2017, 09:20

10 Sep 2017, 10:27

My controller code is following:

private GChartModel geoChart;

private void generateGeoChart() throws PersistenceBeanException, IllegalAccessException {
List<AslRegion> regionList = DaoManager.load(AslRegion.class);
GChartModelBuilder builder = new GChartModelBuilder().setChartType(GChartType.GEO)
.addColumns("State");
for(AslRegion region: regionList){
builder.addRow(region.getMapName());
}

geoChart = builder
.addOption("region", "IT")
.addOption("resolution", "provinces")
.addOption("backgroundColor", "white")
.addOption("datalessRegionColor", "white")
.addOption("defaultColor", "#24a4ff")
.addOption("domain", "IT")
.build();
}

public void onSelectRegion(SelectEvent event) {
System.out.println("onSelectRegion CLICKED");
final JsonArray value = (JsonArray) event.getObject();
if (value.size() > 0) {
final JsonElement element = value.get(0);
final String label = new ArrayList<GChartModelRow>(getChart().getRows())
.get(element.getAsJsonObject().get("row").getAsInt()).getLabel();
FacesContext.getCurrentInstance().addMessage(null,
new FacesMessage(FacesMessage.SEVERITY_INFO, "You have selected: " + label, null));
System.out.println("You have selected: " + label);
}
}

I was able to show map of Italy on web page but I can't handle selection event. When click on a region of Italy nothing happens.
In my xhtml page I have:
<pe:gChart value="#{homeBean.geoChart}" id="italyMap">
<f:ajax event="select" listener="#{homeBean.onSelectRegion}"/>
</pe:gChart>

I also see in Javascript console the message "TypeError: b.wrapper.getChart(...) is null"

Could you help me?

Melloware
Posts: 3716
Joined: 22 Apr 2013, 15:48

10 Sep 2017, 15:09

Let me investigate and see what I find out. I will get back to you.

What version of Extensions and Primefaces are you using?
PrimeFaces Developer | PrimeFaces Extensions Developer
GitHub Profile: https://github.com/melloware
PrimeFaces Elite 13.0.0 / PF Extensions 13.0.0
PrimeReact 9.6.1

sentenced37
Posts: 3
Joined: 10 Sep 2017, 09:20

10 Sep 2017, 21:30

I'm using Primefaces 6.1 and Primefaces Extensions 6.1.0. If I use Primefaces extensions 6.1.1 no map is displayed
Last edited by sentenced37 on 10 Sep 2017, 23:08, edited 1 time in total.

sentenced37
Posts: 3
Joined: 10 Sep 2017, 09:20

10 Sep 2017, 22:59

A update: using 127.0.0.1 instead of localhost let the map working!!! Incredible.
But now when I click on a region I see this exception: com.google.gson.JsonParseException: Expecting array but found object: []
I have updated gson dependency from 1.4 to the latest and everything works fine now.

Melloware
Posts: 3716
Joined: 22 Apr 2013, 15:48

11 Sep 2017, 01:15

OK so I am really surpised that worked. So in PFE 6.1.1 we had to change the way charts get loaded and use a new JS. You can read the bug ticket here: https://github.com/primefaces-extension ... issues/452

So now in 6.1.1 you have to manually add this script to the page because the component no longer loads it.

Code: Select all

<script src="https://www.gstatic.com/charts/loader.js"></script>
But is is interesting you mentioned upgrading the GSON libary helped fix an issue?
PrimeFaces Developer | PrimeFaces Extensions Developer
GitHub Profile: https://github.com/melloware
PrimeFaces Elite 13.0.0 / PF Extensions 13.0.0
PrimeReact 9.6.1

Melloware
Posts: 3716
Joined: 22 Apr 2013, 15:48

11 Sep 2017, 15:49

GSON should have been 2.2.4 included with PFE 6.1. So I am not sure where the 1.4 dependency came from unless you overrode it in your own pom.xml?
PrimeFaces Developer | PrimeFaces Extensions Developer
GitHub Profile: https://github.com/melloware
PrimeFaces Elite 13.0.0 / PF Extensions 13.0.0
PrimeReact 9.6.1

Post Reply

Return to “Extensions”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 6 guests