I have succesfully loaded displayed a timeline with data by using the code and xml file here:
http://www.primefaces.org/showcase/ui/d ... ange.xhtml
I can use the data from the database in a sorted datatable as shown here
http://www.primefaces.org/showcase/ui/d ... sort.xhtml
However when i try to load data from my SQL server the timeline component do not display at all and I was wondering if it should be possible to use sql data and display it in the timeline component?
I first tried with Primefaces 6.0 and Primefaces Extensions 4.0 but then the timeline component would not work at all.
My index.xhtml:
Code: Select all
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.org/ui"
xmlns:fn="http://java.sun.com/jsp/jstl/functions"
xmlns:pe="http://primefaces.org/ui/extensions"
>
<h:head>
</h:head>
<h:body style="padding:10px 10px 10px 10px; border-style:solid;">
<pe:timeline value="#{limitTimelineRangeView.model}"
min="#{limitTimelineRangeView.min}"
max="#{limitTimelineRangeView.max}"
zoomMin="#{limitTimelineRangeView.zoomMin}"
zoomMax="#{limitTimelineRangeView.zoomMax}"
height="180px" showNavigation="true"></pe:timeline>
</h:body>
</html>
I use chrome and have tried to display the site in Firefox aswell.
The events get loaded to the timeline and is printed out with it's data in the console as well.
Code: Select all
@PostConstruct
public void init() {
Connection connection =null;
model = new TimelineModel();
try{
System.out.println("Events from Db");
String serverName = "jdbc:mysql://localhost:3306/mysql?zeroDateTimeBehavior=convertToNull";
String mydatabase = serverName;
String url = mydatabase;
String username = "xxxxxx";
String password = "xxxxxx";
Class.forName("com.mysql.jdbc.Driver");
connection =DriverManager.getConnection(url, username, password);
SimpleDateFormat date = new SimpleDateFormat("YYYY");
Statement stmt = connection.createStatement();
String sql = "Select * FROM eventsdb ORDER BY date";
ResultSet set = stmt.executeQuery(sql);
// Loop to get SQL data
while(set.next()){
String title = set.getString("title");
String id = set.getString("id");
String information = set.getString("information");
System.out.println(title);
String dateFromDb = set.getString("date");
Calendar time =Calendar.getInstance();
Date d = date.parse(dateFromDb);
time.setTime(d);
t = new TimelineEvent();
t.setData("Title:"+" "+title+"\n"+"Information:"+" "+information+"\n"+"Id:"+" "+id);
t.setStartDate(d);
t.setEndDate(d);
model.add(new TimelineEvent("Title:"+" "+title+"\n"+"Information:"+" "+information+"\n"+"Id:"+" "+id,time.getTime()));
}
System.out.println("After "+getModel().getEvents());
}
catch (ClassNotFoundException | SQLException | ParseException ex) {
Logger.getLogger(LimitTimelineRangeView.class.getName()).log(Level.SEVERE, null, ex);
}
finally{
try {
connection.close();
} catch (SQLException ex) {
Logger.getLogger(LimitTimelineRangeView.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
public TimelineModel getModel() {
return model;
}