Why Primefaces donutChart is not working? - charts

I tried to use donut chart from primefaces cause I used primefaces but the chart won't working.
So this is my XHTML
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
template="/WEB-INF/templates/new-dashbord-landing-page.xhtml"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:p="http://primefaces.org/ui"
xmlns:f="http://xmlns.jcp.org/jsf/core">
<ui:define name="postMetadata">
</ui:define>
<ui:define name="content">
<div class="chart-donut">
<p:donutChart model="#{bean.donutModel}"/>
</div>
</ui:define>
</ui:composition>
for p:donutChart in my case I cannot use it, I don't know why
and this is my java
import org.apache.poi.ss.usermodel.charts.ChartData;
import org.primefaces.model.chart.DonutChartModel;
import javax.annotation.PostConstruct;
import java.util.ArrayList;
import java.util.List;
public class Bean {
private DonutChartModel donutModel;
#PostConstruct
public void init() {
donutModel = new DonutChartModel();
ChartData data = new ChartData();
DonutChartDataSet dataSet = new DonutChartDataSet();
List<Number> values = new ArrayList<>();
values.add(300);
values.add(50);
values.add(100);
dataSet.setData(values);
List<String> bgColors = new ArrayList<>();
bgColors.add("rgb(255, 99, 132)");
bgColors.add("rgb(54, 162, 235)");
bgColors.add("rgb(255, 205, 86)");
dataSet.setBackgroundColor(bgColors);
data.addChartDataSet(dataSet);
List<String> labels = new ArrayList<>();
labels.add("Red");
labels.add("Blue");
labels.add("Yellow");
data.setLabels(labels);
donutModel.setData(data);
}
public DonutChartModel getDonutModel() {
return donutModel;
}
}
and I use the same code like on primefaces documentation. I just want use the chart :(

The problem is the import for DonutChartModel. You're picking up the older version used for p:chart components. For the Charts.js based components the correct package name is:
org.primefaces.model.charts.donut.DonutChartModel
Slightly off topic, the bean also needs annotating. e.g. #Named and #RequestScoped.

Related

Adobe CQ: Injecting services via #Reference returns null

I'm trying to inject a service into the component via #Reference annotation in Adobe CQ5, but after deployment it always returns null to me instead of service instance.
#Component(immediate = true)
#Service(value = GoodbyeWorldService.class)
public class GoodbyeWorldService {
#Reference
protected Scheduler scheduler;
private final static Logger LOGGER = LoggerFactory.getLogger(GoodbyeWorldService.class);
public void get() {
LOGGER.info("Scheduler is " + this.scheduler);
}
}
The JSP:
<%# include file="/apps/cqblueprints-example/components/global.jspx" %>
<jsp:directive.page contentType="text/html" pageEncoding="UTF-8"/>
<jsp:useBean id="goodbye" class="com.cqblueprints.example.services.GoodbyeWorldService" scope="page" />
<% goodbye.get(); %>
In the log I get:
2014-04-02 12:24:09.999 INFO [com.cqblueprints.example.services.GoodbyeWorldService] Scheduler is null
I've tested other simple print methods from this bean. They are working like charm.
What am I missing?
In order to have #Reference fields injected by the OSGi, you can't treat your service as a Java bean. Use SlingScriptHelper available as the sling object in the JSP files to get the service in a proper way:
<% GoodbyeWorldService service = sling.getService(GoodbyeWorldService.class); %>
<%= service.get() %>
Full example:
<%#page session="false" import="your.package.GoodbyeWorldService"
%><%#taglib prefix="sling" uri="http://sling.apache.org/taglibs/sling/1.0"
%><sling:defineObjects/><%
GoodbyeWorldService service = sling.getService(GoodbyeWorldService.class);
%><%= service.get() %>
The problem is solved! I have just updated the version of maven-scr-plugin from 1.7.4 to 1.9.0 and it started to work! Now I am retrieving my instances via #Reference annotations and I see my service in "Services" and "Components" tabs in Felix OSGi Console. Thanks to all who replied here!

setting xml Doctype using jdom

Can any one help me in setting [ Doctype and xml:lang="en" ] while creating XML using JDOM?
The xml:lang attribute can be set on any Element with the following:
public static void main(String[] args) throws IOException {
Element root = new Element("root");
DocType dtype = new DocType(root.getName());
Document doc = new Document(root, dtype);
root.setAttribute("lang", "en", Namespace.XML_NAMESPACE);
new XMLOutputter(Format.getPrettyFormat()).output(doc, System.out);
}
Here I have also created a DocType, but it is pretty empty. You can change it to suite your needs by reading the documentation
The code above produces:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE root>
<root xml:lang="en" />

Code is Working Properly in NetBeans but not in Eclipse

I have tried the following jsp file in both IDEs. It is working good in NetBeans, but it is not working in Eclipse. The program is to get the time from a NTP server.
Code is as follows
<%--
Document : GetNTP
Created on : May 21, 2013, 2:21:29 PM
Author : Maximin
--%>
<%#page import="java.net.InetAddress"%>
<%#page import="java.text.SimpleDateFormat"%>
<%#page import ="java.util.Date"%>
<%#page import="org.apache.commons.net.ntp.NTPUDPClient"%>
<%#page import="org.apache.commons.net.ntp.TimeInfo"%>
<%#page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<h1><%
String TIME_SERVER = "time.nist.gov";
NTPUDPClient timeClient = new NTPUDPClient();
InetAddress inetAddress = InetAddress.getByName(TIME_SERVER);
TimeInfo timeInfo = timeClient.getTime(inetAddress);
long returnTime = timeInfo.getReturnTime();
Date time = new Date(returnTime);
SimpleDateFormat sdf= new SimpleDateFormat("dd-MM-yyyy");
out.println(sdf.format(time));
%></h1>
</body>
</html>
When i run this in eclipse I get as
org.apache.jasper.JasperException: Unable to compile class for JSP:
An error occurred at line: 17 in the generated java file
Only a type can be imported. org.apache.commons.net.ntp.NTPUDPClient resolves to a package
An error occurred at line: 18 in the generated java file
Only a type can be imported. org.apache.commons.net.ntp.TimeInfo resolves to a package
An error occurred at line: 18 in the jsp file: /GetTime.jsp
NTPUDPClient cannot be resolved to a type
15: <body>
16: <h1><%
17: String TIME_SERVER = "time.nist.gov";
18: NTPUDPClient timeClient = new NTPUDPClient();
19: InetAddress inetAddress = InetAddress.getByName(TIME_SERVER);
20: TimeInfo timeInfo = timeClient.getTime(inetAddress);
21: long returnTime = timeInfo.getReturnTime();
Why is it so?
What should I do to make it run on Eclipse?
Worked for me:
"Right click on your project and choose Properties (it's at the bottom...probably). Deployment Assembly is one of the pages. If the jar with the NTP classes is not in WebContent/WEB-INF/lib or otherwise on the server, make sure it is on this page."
Answered by nitind

How to import a custom class into mxml file in Flex? (Actionscript 3)

i need to import my own class to the mxml file, but allways comes an error that classes cant be nested. I dont know how to use my classes (example: NetConn.as). Can you help me?
<!--language:actionscript3>
<?xml version="1.0" encoding="utf-8"?>
<s:ViewNavigatorApplication xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark" firstView="views.eazyRadioHomeView">
<fx:Style source="eazyRadio.css"/>
<fx:Script>
<![CDATA[
include "NetConn.as";
import myNetConn;
var easy=new NetConnectionEx();
]]>
</fx:Script>
<fx:Declarations>
<!-- Platzieren Sie nichtvisuelle Elemente (z. B. Dienste, Wertobjekte) hier -->
</fx:Declarations>
</s:ViewNavigatorApplication>
-->
You need
import com.yournamespace.NetConn;
instead of
include "NetConn.as"

Inserting into cassandra using hector on Glassfish 3.1

Im trying to insert a keyspace into cassandra using hector and the SchemaManipulation example given from the hector wiki.
package net.zanity.live;
import java.util.Arrays;
import java.util.List;
import me.prettyprint.cassandra.model.BasicColumnDefinition;
import me.prettyprint.cassandra.model.BasicColumnFamilyDefinition;
import me.prettyprint.cassandra.serializers.StringSerializer;
import me.prettyprint.cassandra.service.ThriftCfDef;
import me.prettyprint.hector.api.Cluster;
import me.prettyprint.hector.api.ddl.*;
import me.prettyprint.hector.api.exceptions.HectorException;
import me.prettyprint.hector.api.factory.HFactory;
/**
*
* #author zznate
*
*/
public class SchemaManipulation {
private static final String DYN_KEYSPACE = "YOUWantToSeeThis";
private static final String DYN_CF = "DynamicCf";
private static final String CF_SUPER = "SuperCf";
private static StringSerializer stringSerializer = StringSerializer.get();
public static void main(String[] args) throws Exception {
Cluster cluster = HFactory.getOrCreateCluster("TestCluster", "localhost:9160");
try {
if ( cluster.describeKeyspace(DYN_KEYSPACE) != null ) {
cluster.dropKeyspace(DYN_KEYSPACE);
}
BasicColumnDefinition columnDefinition = new BasicColumnDefinition();
columnDefinition.setName(stringSerializer.toByteBuffer("birthdate"));
columnDefinition.setIndexName("birthdate_idx");
columnDefinition.setIndexType(ColumnIndexType.KEYS);
columnDefinition.setValidationClass(ComparatorType.LONGTYPE.getClassName());
BasicColumnFamilyDefinition columnFamilyDefinition = new BasicColumnFamilyDefinition();
columnFamilyDefinition.setKeyspaceName(DYN_KEYSPACE);
columnFamilyDefinition.setName(DYN_CF);
columnFamilyDefinition.addColumnDefinition(columnDefinition);
BasicColumnFamilyDefinition superCfDefinition = new BasicColumnFamilyDefinition();
superCfDefinition.setKeyspaceName(DYN_KEYSPACE);
superCfDefinition.setName(CF_SUPER);
superCfDefinition.setColumnType(ColumnType.SUPER);
ColumnFamilyDefinition cfDefStandard = new ThriftCfDef(columnFamilyDefinition);
ColumnFamilyDefinition cfDefSuper = new ThriftCfDef(superCfDefinition);
KeyspaceDefinition keyspaceDefinition =
HFactory.createKeyspaceDefinition(DYN_KEYSPACE, "org.apache.cassandra.locator.SimpleStrategy",
1, Arrays.asList(cfDefStandard, cfDefSuper));
cluster.addKeyspace(keyspaceDefinition);
// insert some data
List<KeyspaceDefinition> keyspaces = cluster.describeKeyspaces();
for (KeyspaceDefinition kd : keyspaces) {
if ( kd.getName().equals(DYN_KEYSPACE) ) {
System.out.println("Name: " +kd.getName());
System.out.println("RF: " +kd.getReplicationFactor());
System.out.println("strategy class: " +kd.getStrategyClass());
List<ColumnFamilyDefinition> cfDefs = kd.getCfDefs();
for (ColumnFamilyDefinition def : cfDefs) {
System.out.println(" CF Type: " +def.getColumnType());
System.out.println(" CF Name: " +def.getName());
System.out.println(" CF Metadata: " +def.getColumnMetadata());
}
}
}
} catch (HectorException he) {
he.printStackTrace();
}
cluster.getConnectionManager().shutdown();
}
}
The jsp code:
<%#page language="java" import="net.zanity.live.*" contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>GlassFish JSP Page</title>
</head>
<body>
<% out.println("CAKrE"); Test test = new Test(); out.println("sting displayed here: " + test.Testt()); %>
After this text loads the cassandra schema test will run and prolly crash the webapp
<% SchemaManipulation cI = new SchemaManipulation(); SchemaManipulation.main(new String [0]); %>
</body>
</html>
Im running this code in Eclipse 3.7.1 Indigo and the code when executed as a java application works and inserts into cassandra, but when i run it on the server it does not.
Cassandra is running on its default port as a local host and glasfish is also running on a local host on port 8080.
I think the issue is im not placing the hector jars in the correct place, the hector jars are already added to the buildpath but im not sure if that has added them to the server as well.
Any help would be appreciated as I'm failing to find useful documentation for cassandra.
EDIT: i have added the jar's to the server that was not the problem, issue is still unresolved.
Stack Trace of errors:
WARNING: StandardWrapperValve[jsp]: PWC1406: Servlet.service() for servlet jsp threw exception
java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory
at me.prettyprint.cassandra.service.AbstractCluster.<init>(AbstractCluster.java:44)
at me.prettyprint.cassandra.service.ThriftCluster.<init>(ThriftCluster.java:21)
at me.prettyprint.hector.api.factory.HFactory.createCluster(HFactory.java:192)
at me.prettyprint.hector.api.factory.HFactory.getOrCreateCluster(HFactory.java:139)
at me.prettyprint.hector.api.factory.HFactory.getOrCreateCluster(HFactory.java:128)
at net.zanity.live.SchemaManipulation.main(SchemaManipulation.java:36)
at org.apache.jsp.index_jsp._jspService(index_jsp.java:61)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:111)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:848)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:403)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:492)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:378)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:848)
at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1534)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:281)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:655)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:595)
at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:98)
at com.sun.enterprise.web.PESessionLockingStandardPipeline.invoke(PESessionLockingStandardPipeline.java:91)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:162)
at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:326)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:227)
at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:170)
at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:822)
at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:719)
at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1013)
at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:225)
at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:137)
at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:104)
at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:90)
at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:79)
at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:54)
at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:59)
at com.sun.grizzly.ContextTask.run(ContextTask.java:71)
at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:532)
at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:513)
at java.lang.Thread.run(Thread.java:722)
I think you just forgot to add also the slf4j jar.
That should solve the problem.
In fact the stack trace says it cannot find the class org.slf4j.LoggerFactory which is included in the slf4j jar.
This jar is needed for hector, and indeed hector rises the exception.