Should it be possible to use sql data and display it in the

Community Driven Extensions Project
Post Reply
rissloa
Posts: 1
Joined: 02 Jan 2017, 11:21

05 Jan 2017, 10:12

I am using Netbeans 8.2 with Primefaces 5.2 and Primefaces Extensions 4.0. I also have a local glassfish server and a local MySQL server.

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>
Below is the code for the class. I have tried to use @Dependent, RequestScoped,ViewScoped and ApplicationScoped as well. I do not recieve any error messages and the site itself will display with other components in the web-browser.
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;
    }
Thanks for any feedback and let me know if i should clarify anything.

User avatar
Melloware
Posts: 230
Joined: 22 Apr 2013, 15:48

05 Jan 2017, 14:29

This same exact code above works if you point it at a Datatable?

Does your limitTimelineRangeView have @Managed or @Named on it depending on whether you are using straight JSF or CDI?

Have you put logging in the init() method to make sure it is actually being called by your timeline?

Have you taken SQL out of the equation and just created a bean with hard coded values to prove the timeline is working? Then replace with your SQL call?

But to answer your original question this should ABSOLUTELY work whether it is SQL or not, JSF doesn't care how you fill your POJO's.
PrimeFaces Extensions Developer
GitHub Profile: https://github.com/melloware
PrimeFaces 6.1 / PF Extensions 6.1.1

Post Reply
  • Information
  • Who is online

    Users browsing this forum: No registered users and 1 guest