I want to display two charts in PrimeFaces.
I am using Bootstrap 1.0.10, PrimeFaces 5.3 and Tomcat 7.
The strange thing is, that the chart is rendered, but the user isn't able to see it.
stats.xhtml
<ui:define name="content">
<div>
<p:panel id="panel" header="Statistik"
style="margin: 20px;">
<p:chart type="pie" model="#{statistikBean.chartModel1}"
style="width:400px; height:300px" />
<p:chart type="metergauge"
model="#{statistikBean.chartModel2}"
style="width:400px; height:250px" />
</p:panel>
</div>
</ui:define>
StatistikBean.java
....
private PieChartModel chartModel1;
private MeterGaugeChartModel chartModel2;
#PostConstruct
public void init() {
doModels();
}
private void doModels() {
this.chartModel1 = new PieChartModel();
// chartModel1
this.chartModel1.set("Fach 1", 10);
this.chartModel1.set("Fach 2", 20);
this.chartModel1.set("Fach 3", 30);
this.chartModel1.set("Fach 4", 40);
this.chartModel1.setTitle("Verteilung der Facher");
this.chartModel1.setLegendPosition("w");
// chartModel2
List<Number> intervall = new ArrayList<Number>(){{
add(50);
add(75);
add(85);
add(95);
}};
this.chartModel2 = new MeterGaugeChartModel(75, intervall);
this.chartModel2.setTitle("Fortschritt");
this.chartModel2.setSeriesColors("cc6666,E7E658,93b75f,66cc66");
this.chartModel2.setGaugeLabel("%");
}
.....
Rendered Output :
<div>
<div id="panel"
class="ui-panel ui-widget ui-widget-content ui-corner-all"
style="margin: 20px;"
data-widget="widget_panel">
<div id="panel_header" class="ui-panel-titlebar ui-widget-header ui-helper-clearfix ui-corner-all">
<span class="ui-panel-title">Statistik</span>
</div>
<div id="panel_content" class="ui-panel-content ui-widget-content">
<div id="j_idt17" style="width:400px; height:300px"></div>
<script id="j_idt17_s" type="text/javascript">
$(function () {
PrimeFaces.cw('Chart', 'widget_j_idt17', {
id: 'j_idt17',
type: 'pie',
data: [[["Fach 1", 10], ["Fach 2", 20], ["Fach 3", 30], ["Fach 4", 40]]],
title: "Verteilung der Facher",
legendPosition: "w",
datatip: true,
datatipFormat: "%s - %d"}, 'charts');
});
</script>
<div id="j_idt18" style="width:400px; height:250px"></div>
<script id="j_idt18_s" type="text/javascript">
$(function () {
PrimeFaces.cw('Chart', 'widget_j_idt18', {
id: 'j_idt18',
type: 'metergauge',
data: [[75]],
title: "Fortschritt",
seriesColors: ["#cc6666", "#E7E658", "#93b75f", "#66cc66"],
intervals: [50, 75, 85, 95],
gaugeLabel: "%",
gaugeLabelPosition: "inside",
showTickLabels: true,
labelHeightAdjust: -25}, 'charts');
});
</script>
</div>
</div>
<script id="panel_s" type="text/javascript">
PrimeFaces.cw("Panel", "widget_panel", {id: "panel"});
</script>
</div>
Tested it in Chrome and FireFox. The area where the chart(s) should be is just white.
Ok, I found the problem. I accidentally included jQuery two times.
One time in the JSF-template (with bootstrap), the second time with Primefaces.
I removed it from the JSF-template and it now works.
Related
Trying to create a dynamic dashboard with drag/drop and resize functionality. I want to add ASP server controls to 'grid-stack-item-content' and update them through Ajax after every 10 seconds.
https://jsfiddle.net/kLeu7y0h/
<html lang="en">
<head>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/css/bootstrap.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/gridstack.js/0.4.0/gridstack.css" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.11.0/jquery-ui.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/js/bootstrap.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.0/lodash.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/gridstack.js/0.4.0/gridstack.all.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jqueryui-touch-punch/0.2.3/jquery.ui.touch-punch.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.5.0/Chart.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-cookie/1.4.1/jquery.cookie.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/bigslide.js/0.12.0/bigSlide.min.js"></script>
<style type="text/css">
.grid-stack {
background: lightgoldenrodyellow;
}
.grid-stack-item-content {
color: #2c3e50;
text-align: center;
background-color: #18bc9c;
margin: 10px;
}
</style>
</head>
<body>
<div class="container-fluid">
<div>
<a class="btn btn-default" id="save-grid" href="#">Save</a>
<a class="btn btn-default" id="load-grid" href="#">Load</a>
<a class="btn btn-default" id="clear-grid" href="#">Clear</a>
<input type="hidden" id="saved-data">
</div>
<br/>
<div class="grid-stack">
</div>
<div class="grid-stack-item" id="moni1">
<div class="grid-stack-item-content">
<p>ASP Panel A</p>
</div>
</div>
<div class="grid-stack-item" id="moni2">
<div class="grid-stack-item-content">
<p>ASP Panel B</p>
</div>
</div>
<div class="grid-stack-item" id="moni3">
<div class="grid-stack-item-content">
<p>ASP Panel C</p>
</div>
</div>
<div class="grid-stack-item" id="moni4">
<div class="grid-stack-item-content">
<p>ASP Panel D</p>
</div>
</div>
</div>
<script>
$(function () {
var options = {
};
$('.grid-stack').gridstack(options);
new function () {
this.serializedData = [
{ x: 0, y: 0, width: 2, height: 2, id: moni1 },
{ x: 0, y: 1, width: 2, height: 2, id: moni2 },
{ x: 0, y: 2, width: 2, height: 2, id: moni3 },
{ x: 0, y: 3, width: 2, height: 2, id: moni4 },
];
var grid = $('.grid-stack').data('gridstack');
this.loadGrid = function () {
grid.removeAll();
var items = GridStackUI.Utils.sort(this.serializedData);
_.each(items, function (node) {
grid.addWidget(node.id,
node.x, node.y, node.width, node.height);
}, this);
return false;
}.bind(this);
this.saveGrid = function () {
this.serializedData = _.map($('.grid-stack > .grid-stack-item:visible'), function (el) {
el = $(el);
var node = el.data('_gridstack_node');
return {
x: node.x,
y: node.y,
width: node.width,
height: node.height,
id: node.id
};
}, this);
$('#saved-data').val(JSON.stringify(this.serializedData, null, ' '));
return false;
}.bind(this);
this.clearGrid = function () {
grid.removeAll();
return false;
}.bind(this);
$('#save-grid').click(this.saveGrid);
$('#load-grid').click(this.loadGrid);
$('#clear-grid').click(this.clearGrid);
this.loadGrid();
};
});
</script>
</body>
</html>
I need to load elements from JSON retrieved from database to form a layout. But every time I click on 'Load' button, maximum call stack size error displayed.
I created a CRUD operation with JSF and PrimeFaces 6 and EJB 3.1. The findAll() method works very fine because I can see the the fetched data List on the PrimeFaces DataTable. But when i click on Add, the popup shows up, but submiting the data to the managedbean does not work, i can see that, the command button does not seem to communicate with the bean. But the same code is working in another module of the same project. I keep wondering why this problem is occurring. I have tried all solutions such as Ajax="false", I have tried process="#this", I have also tried immediate="true", but nothing seems working. I have been stranded and need a solution. Thanks
THIS IS THE XHTML FILE
<?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">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:p="http://primefaces.org/ui"
xmlns:f="http://xmlns.jcp.org/jsf/core">
<h:body>
<div>
<h:form id="subjectTopForm">
<p:growl id="growl" life="2000" />
<p:commandLink id="ajax" update="growl" onclick="PF('subjectAddDialog').show();">
<span class="btn waves-effect waves-light indigo">
<h:outputText value="Add new Subject"/>
</span>
</p:commandLink>
<!-- <BEGINNING OF SAVE POPUP DIALOG>-->
<p:dialog header="Add New Subject" widgetVar="subjectAddDialog" modal="true" height="auto" width="420" styleClass="customDialog">
<f:view>
<p:panelGrid columns="2">
<p:outputLabel value="SubjectName:" for="subjectName" class="table-row-height" />
<p:inputText id="subjectName" value="#{subject.sub.subjectName}" title="SubjectName" required="true" requiredMessage="The SubjectName field is required." />
<p:outputLabel/>
<p:commandButton process="#this" immediate="true" action="#{subject.addSubject()}" value="Add Subject" update=":subjectForm">
<f:ajax execute="subjectForm" render="subjectForm:subjectDataTable" />
<p:resetInput target=":subjectForm"/>
</p:commandButton>
</p:panelGrid>
</f:view>
</p:dialog>
<!-- END OF SAVE POPUP DIALOG-->
</h:form>
</div>
<div>
<h:form id="editSubjectPopupDialog">
<!-- UPDATE FORM DIALOG-->
<p:dialog header="Edit Subject" widgetVar="subjectEditDiaglog" modal="true" height="auto" width="420" styleClass="customDialog">
<f:view>
<p:panelGrid columns="2">
<p:outputLabel value="SubjectName:" for="subjectName" class="table-row-height" />
<p:inputText id="subjectName" value="#{subject.sub.subjectName}" title="SubjectName" required="true" requiredMessage="The SubjectName field is required." />
<p:outputLabel/>
<p:commandButton action="#{subject.editSubject()}" value="Save Changes" update=":editSubjectPopupDialog">
<f:ajax execute="subjectForm" render="subjectForm:subjectDataTable" />
<p:resetInput target=":editSubjectPopupDialog"/>
</p:commandButton>
</p:panelGrid>
</f:view>
</p:dialog>
<!--END OF UPDATE FORM DIALOG-->
</h:form>
</div>
<div>
<f:view>
<h:form id="subjectForm">
<h:dataTable value="#{subject.findAll()}" var="item" id="subjectDataTable">
<h:column>
<f:facet name="header">
<h:outputText value="SubjectName"/>
</f:facet>
<h:outputText value="#{item.subjectName}"/>
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="Edit"/>
</f:facet>
<p:commandLink action="#{subject.setSub(item)}" oncomplete="PF('subjectEditDiaglog').show()" update=":editSubjectPopupDialog">
<i class="mdi-editor-mode-edit">
</i>
</p:commandLink>
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="Delete"/>
</f:facet>
<h:commandLink action="#{subject.delete(item)}" onclick="return confirm('Are you sure?')">
<i class="mdi-action-delete">
</i>
<f:ajax render="subjectForm:subjectDataTable" />
</h:commandLink>
</h:column>
</h:dataTable>
</h:form>
</f:view>
</div>
<div>
<p>
</p>
<p>
</p>
</div>
</h:body>
</html>
BELOW IS THE JSF MANAGED BEAN
package com.nan.app.controller;
import com.nan.app.crud.entityclasses.Subjects;
import com.nan.app.crud.sessionbeans.SubjectService;
import javax.enterprise.context.SessionScoped;
import java.io.Serializable;
import java.util.List;
import javax.ejb.EJB;
import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.context.FacesContext;
/**
*
* #author Nandom
*/
#ManagedBean(name = "subject")
#SessionScoped
public class SubjectController implements Serializable {
#EJB
SubjectService service;
private Subjects sub = new Subjects();
public Subjects getSub() {
return sub;
}
public void setSub(Subjects sub) {
this.sub = sub;
}
public void addSubject() {
service.create(sub);
service.findAll();
FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_INFO, sub.getSubjectName(), null);
FacesContext.getCurrentInstance().addMessage(null, message);
sub = new Subjects();
}
public void editSubject() {
service.edit(sub);
service.findAll();
FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_INFO, "Update Executed Successfully", null);
FacesContext.getCurrentInstance().addMessage(null, message);
sub = new Subjects();
}
public void delete(Subjects entity) {
service.remove(entity);
service.findAll();
FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_INFO, "Deleted Successfully", null);
FacesContext.getCurrentInstance().addMessage(null, message);
}
public Subjects find(Object id) {
return service.find(id);
}
public List<Subjects> findAll() {
return service.findAll();
}
}
Pls NOTE: I have a side navigation in my mail-layout.xhtml which the links are controlled by the navigation bean as shown below.
Main Application UI with Side Navigation
THE CODE FOR THIS LAYOUT IS BELOW
<?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">
<html xmlns="http://www.w3.org/1999/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">
<h:head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<!-- <h:outputStylesheet name="./css/default.css"/>
<h:outputStylesheet name="./css/cssLayout.css"/>-->
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1.0, user-scalable=no"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge"/>
<meta name="msapplication-tap-highlight" content="no"/>
<meta name="description" content="Materialize is a Material Design Admin Template,It's modern, responsive and based on Material Design by Google. "/>
<meta name="keywords" content="materialize, admin template, dashboard template, flat admin template, responsive admin template,"/>
<title>School Management System</title>
<!-- Favicons-->
<link rel="icon" href="#{resource['images/favicon/favicon-32x32.png']}" sizes="32x32"/>
<!-- Favicons-->
<link rel="apple-touch-icon-precomposed" href="#{resource['images/favicon/apple-touch-icon-152x152.png']}"/>
<!-- For iPhone -->
<meta name="msapplication-TileColor" content="#00bcd4"/>
<meta name="msapplication-TileImage" content="#{resource['images/favicon/mstile-144x144.png']}"/>
<!-- For Windows Phone -->
<link href="#{resource['css/widget.css']}" type="text/css" rel="stylesheet" media="screen,projection"/>
<!-- CORE CSS-->
<link href="#{resource['css/materialize.min.css']}" type="text/css" rel="stylesheet" media="screen,projection"/>
<link href="#{resource['css/style.min.css']}" type="text/css" rel="stylesheet" media="screen,projection"/>
<!-- Custome CSS-->
<link href="#{resource['css/custom/custom.min.css']}" type="text/css" rel="stylesheet" media="screen,projection"/>
<!-- INCLUDED PLUGIN CSS ON THIS PAGE -->
<link href="#{resource['js/plugins/prism/prism.css']}" type="text/css" rel="stylesheet" media="screen,projection"/>
<link href="#{resource['js/plugins/perfect-scrollbar/perfect-scrollbar.css']}" type="text/css" rel="stylesheet" media="screen,projection"/>
<link href="#{resource['js/plugins/chartist-js/chartist.min.css']}" type="text/css" rel="stylesheet" media="screen,projection"/>
<link href="#{resource['js/plugins/data-tables/css/jquery.dataTables.min.css']}" type="text/css" rel="stylesheet" media="screen,projection"/>
<style>
.mdi-action-delete {
font-size: 25px;
}
.mdi-editor-mode-edit {
font-size: 25px;
}
.addForm {
display:inline-block;
width: 300px;
text-wrap:none;
white-space:nowrap;
overflow:hidden;
text-overflow:ellipsis;
}
.table-row-height {
height:30px;
}
</style>
</h:head>
<h:body>
<!-- Start Page Loading -->
<div id="loader-wrapper">
<div id="loader"></div>
<div class="loader-section section-left"></div>
<div class="loader-section section-right"></div>
</div>
<!-- End Page Loading -->
<!-- //////////////////////////////////////////////////////////////////////////// -->
<!-- START HEADER -->
<header id="header" class="page-topbar">
<!-- start header nav-->
<div class="navbar-fixed">
<nav class="navbar-color">
<div class="nav-wrapper">
<ul class="left">
<li><h1 class="logo-wrapper"><img src="#{resource['images/materialize-logo.png']}" alt="materialize logo"/> <span class="logo-text">Materialize</span></h1></li>
</ul>
<div class="header-search-wrapper hide-on-med-and-down">
<i class="mdi-action-search"></i>
<input type="text" name="Search" class="header-search-input z-depth-2" placeholder="Explore Materialize"/>
</div>
<ul class="right hide-on-med-and-down">
<li><img src="#{resource['images/flag-icons/United-States.png']}" alt="USA" />
</li>
<li><i class="mdi-action-settings-overscan"></i>
</li>
<li><a href="javascript:void(0);" class="waves-effect waves-block waves-light notification-button" data-activates="notifications-dropdown"><i class="mdi-social-notifications"><small class="notification-badge">5</small></i>
</a>
</li>
<li><i class="mdi-communication-chat"></i>
</li>
</ul>
<!-- translation-button -->
<ul id="translation-dropdown" class="dropdown-content">
<li>
<img src=" #{resource['images/flag-icons/United-States.png']}" alt="English" /> <span class="language-select">English</span>
</li>
</ul>
<!-- notifications-dropdown -->
<ul id="notifications-dropdown" class="dropdown-content">
<li>
<h5>NOTIFICATIONS <span class="new badge">5</span></h5>
</li>
<li class="divider"></li>
<li>
<i class="mdi-action-add-shopping-cart"></i> A new order has been placed!
<time class="media-meta" datetime="2015-06-12T20:50:48+08:00">2 hours ago</time>
</li>
</ul>
</div>
</nav>
</div>
<!-- end header nav-->
</header>
<!-- END HEADER -->
<!-- //////////////////////////////////////////////////////////////////////////// -->
<!-- START MAIN -->
<div id="main">
<!-- START WRAPPER -->
<div class="wrapper">
<!-- START LEFT SIDEBAR NAV-->
<aside id="left-sidebar-nav">
<ul id="slide-out" class="side-nav fixed leftside-navigation">
<li class="user-details cyan darken-2">
<div class="row">
<div class="col col s4 m4 l4">
<img src="images/avatar.jpg" alt="" class="circle responsive-img valign profile-image"/>
</div>
<div class="col col s8 m8 l8">
<ul id="profile-dropdown" class="dropdown-content">
<li><i class="mdi-action-face-unlock"></i> Profile
</li>
<li><i class="mdi-hardware-keyboard-tab"></i> Logout
</li>
</ul>
<a class="btn-flat dropdown-button waves-effect waves-light white-text profile-btn" href="#" data-activates="profile-dropdown">John Doe<i class="mdi-navigation-arrow-drop-down right"></i></a>
<p class="user-roal">Administrator</p>
</div>
</div>
</li>
<li class="bold"><i class="mdi-action-dashboard"></i> Dashboard
</li>
<li class="no-padding">
<ul class="collapsible collapsible-accordion">
<li class="bold"><a class="collapsible-header waves-effect waves-cyan"><i class="mdi-action-view-carousel"></i> Settings</a>
<div class="collapsible-body">
<ul>
<h:form style="width:400px; margin-left:-20px;">
<f:ajax render=":content" >
<li><h:commandLink value="Register Classes" action="#{navigation.setPage('/pages/RegisterClasses.xhtml')}" class="mdi-action-dashboard" /></li>
<li><h:commandLink value="Register Subjects" action="#{navigation.setPage('/pages/RegisterSubjects.xhtml')}" class="mdi-action-dashboard" /></li>
<li><h:commandLink value="Register Teachers" action="#{navigation.setPage('/pages/RegisterTeachers.xhtml')}" class="mdi-action-dashboard" /></li>
<li><h:commandLink value="Assign Form Teachers" action="#{navigation.setPage('/pages/AssignFormTeachers.xhtml')}" class="mdi-action-dashboard" /></li>
<li><h:commandLink value="Assign Subject Teachers" action="#{navigation.setPage('/pages/AssignSubjectTeachers.xhtml')}" class="mdi-action-dashboard" /></li>
</f:ajax>
</h:form>
</ul>
</div>
</li>
</ul>
</li>
</ul>
<i class="mdi-navigation-menu"></i>
</aside>
<!-- END LEFT SIDEBAR NAV-->
<!-- //////////////////////////////////////////////////////////////////////////// -->
<!-- START CONTENT -->
<section>
<!--start container-->
<div class="container">
<div class="divider"></div>
<ui:insert name="content">
</ui:insert>
<!-- Floating Action Button -->
<div class="fixed-action-btn" style="bottom: 50px; right: 19px;">
<a class="btn-floating btn-large">
<i class="mdi-action-stars"></i>
</a>
<ul>
<li><i class="large mdi-communication-live-help"></i></li>
<li><i class="large mdi-device-now-widgets"></i></li>
<li><i class="large mdi-editor-insert-invitation"></i></li>
<li><i class="large mdi-communication-email"></i></li>
</ul>
</div>
<!-- Floating Action Button -->
</div>
<!--end container-->
</section>
<!-- END CONTENT -->
<!-- //////////////////////////////////////////////////////////////////////////// -->
<!-- START RIGHT SIDEBAR NAV-->
<aside id="right-sidebar-nav">
<ul id="chat-out" class="side-nav rightside-navigation">
<li class="li-hover">
<i class="mdi-navigation-close"></i>
<div id="right-search" class="row">
<form class="col s12">
<div class="input-field">
<i class="mdi-action-search prefix"></i>
<input id="icon_prefix" type="text" class="validate"/>
<label for="icon_prefix">Search</label>
</div>
</form>
</div>
</li>
</ul>
</aside>
<!-- LEFT RIGHT SIDEBAR NAV-->
</div>
<!-- END WRAPPER -->
</div>
<!-- END MAIN -->
<!-- //////////////////////////////////////////////////////////////////////////// -->
<!-- START FOOTER -->
<footer class="page-footer">
<div class="footer-copyright">
<div class="container">
<span>Copyright © 2015 <a class="grey-text text-lighten-4" href="" target="_blank">Nandom Gusen</a> All rights reserved.</span>
<span class="right"> Design and Developed by <a class="grey-text text-lighten-4" href="">Nandom Gusen</a></span>
</div>
</div>
</footer>
<!-- END FOOTER -->
<!-- ================================================
Scripts
================================================ -->
<!-- jQuery Library -->
<!-- <script type="text/javascript" src="#{resource['js/plugins/jquery-1.11.2.min.js']}"></script> -->
<!--materialize js-->
<script type="text/javascript" src="#{resource['js/materialize.min.js']}"></script>
<!--prism-->
<script type="text/javascript" src=" #{resource['js/plugins/prism/prism.js']}"></script>
<!--scrollbar-->
<script type="text/javascript" src="#{resource['js/plugins/perfect-scrollbar/perfect-scrollbar.min.js']}"></script>
<!-- chartist -->
<script type="text/javascript" src="#{resource['js/plugins/chartist-js/chartist.min.js']}"></script>
<!--plugins.js - Some Specific JS codes for Plugin Settings-->
<script type="text/javascript" src="#{resource['js/plugins.min.js']}"></script>
<!--custom-script.js - Add your own theme custom JS-->
<script type="text/javascript" src="#{resource['js/custom-script.js']}"></script>
<script type="text/javascript" src=" #{resource['js/plugins/data-tables/js/jquery.dataTables.min.js']}"></script>
<script type="text/javascript" src="#{resource['js/plugins/data-tables/data-tables-script.js']}"></script>
<script type="text/javascript">
/*Show entries on click hide*/
$(document).ready(function () {
$(".dropdown-content.select-dropdown li").on("click", function () {
var that = this;
setTimeout(function () {
if ($(that).parent().hasClass('active')) {
$(that).parent().removeClass('active');
$(that).parent().hide();
}
}, 100);
});
});
</script>
</h:body>
</html>
BELOW IS THE NAGIVATION BEAN
package com.nan.app.navigation;
import java.io.Serializable;
import javax.annotation.PostConstruct;
import javax.faces.bean.ManagedBean;
/**
*
* #author Nandom
*/
#ManagedBean(name = "navigation")
public class NavigationBean implements Serializable {
public static final long serialVersionUID = 1L;
public String page;
#PostConstruct
public void init() {
page = "/pages/RegisterClasses.xhtml"; // Default include.
// page = "/template/default/content-layout.xhtml?";
}
public String getPage() {
return page;
}
public void setPage(String page) {
this.page = page;
}
}
This application works well, but the first view(RegisterClassex.xhtml) is the view that will work well. Other views like RegisterSubject.xhtml will not be able to communicate with its own bean.
What could be the problem?
Thanks #Kukeltje for your contributions towards the success of this application and for helping me to solve a major error that has hindered my progress for many days. I have figured out the problem. I added the annotaion #SessionScoped to my navigation bean and it solved the problem. Below is the code that solved the problem
package com.nan.app.navigation;
import java.io.Serializable;
import javax.annotation.PostConstruct;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
/**
*
* #author Nandom
*/
//#Named("navigation")
#ManagedBean(name = "navigation", eager = true)
#SessionScoped
public class NavigationBean implements Serializable {
public static final long serialVersionUID = 1L;
public String page;
#PostConstruct
public void init() {
page = "/pages/RegisterSubjects.xhtml"; // Default include.
// page = "/template/default/content-layout.xhtml?";
}
public String getPage() {
return page;
}
public void setPage(String page) {
this.page = page;
}
}
But i noticed another problem. whenever i navigate to a new view page, the Popup Dialog doesnt come up with the first click, i have to click the button the second time before the popup Dialog comes up. What could probably be the cause of this problem?
I have a page in JSF:
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
xmlns:f="http://xmlns.jcp.org/jsf/core">
<ui:param name="navLinkActive" value="poiAdder"/>
<ui:define name="content">
<h:outputStylesheet library="clock" name="clockpicker.css"/>
<h:outputScript library="clock" name="clockpicker.js"/>
<script src="https://maps.googleapis.com/maps/api/js?v=3.exp"></script>
<div class="col-md-12">
<ui:include src="/WEB-INF/lego/leftMenu.xhtml"/>
<div class="col-md-10">
<h:form id="poiForm" prependId="false" enctype="multipart/form-data">
<div class="col-md-6">
<h:outputLabel for="address"
value="Adres"/>
<h:inputText id="address"
styleClass="col-md-10"
value="#{poiAdderBean.poi.address}"
requiredMessage="#{msg.fieldRequired}"
required="true"/>
<input type="button"
class="btn btn-default"
value="#{msg.findAddress}"
onclick="codeAddress()"/>
<h:message for="address" style="display: block; color:red"/>
<h:outputLabel for="longitude"
value="Współrzędne (automatycznie)"/>
<h:outputLabel for="latitude"
styleClass="descriptionLabel"
value="podaj adres, a potem wybierz dokładną lokalizację na mapie, jeśli potrzebne"/>
<div class="col-md-12">
<h:inputText id="longitude"
styleClass="col-md-4 col-md-offset-2"
required="true"
requiredMessage="#{msg.fieldRequired}"
value="#{poiAdderBean.poi.longitude}"
converter="javax.faces.Double">
</h:inputText>
<h:inputText id="latitude"
styleClass="col-md-4"
required="true"
requiredMessage="#{msg.fieldRequired}"
value="#{poiAdderBean.poi.latitude}"
converter="javax.faces.Double">
</h:inputText>
</div>
<h:message for="latitude" style="display: block; color:red"/>
<h:message for="longitude" style="display: block; color:red"/>
<h:outputLabel for="poiTypeSelector"
value="Wybierz kategorię POI"/>
<h:selectOneMenu id="poiTypeSelector"
styleClass="btn"
value="#{poiAdderBean.poi.poiCategory}">
<f:selectItems value="#{poiAdderBean.poiCategoryList}"
var="poiCat"
itemLabel="#{msg['poi'.concat(poiCat)]}"
itemValue="#{poiCat}"/>
</h:selectOneMenu>
<h:outputLabel for="phoneNumber"
value="#{msg.phoneNumber}"/>
<h:inputText id="phoneNumber"
style="width: 350px"
value="#{poiAdderBean.poi.phone}"
validator="#{PhoneValidator.validate}">
</h:inputText>
<h:message for="phoneNumber" style="display: block; color:red"/>
<h:outputLabel for="linkwww1"
value="Link www #1"/>
<h:inputText id="linkwww1"
style="width: 350px"
value="#{poiAdderBean.poi.link}">
<f:validator validatorId="linkValidator"/>
<f:attribute name="linkDescritpion" value="#{description1}"/>
</h:inputText>
<h:message for="linkwww1" style="display: block; color:red"/>
<h:outputLabel for="linkwww1Description"
value="Opis #1"/>
<h:inputText id="linkwww1Description"
binding="#{description1}"
style="width: 350px"
value="#{poiAdderBean.poi.linkDescription}">
</h:inputText>
<h:message for="linkwww1Description" style="display: block; color:red"/>
<h:outputLabel for="linkwww2"
value="Link www #2"/>
<h:inputText id="linkwww2"
style="width: 350px"
value="#{poiAdderBean.poi.link2}">
<f:validator validatorId="linkValidator"/>
<f:attribute name="linkDescritpion" value="#{description2}"/>
</h:inputText>
<h:message for="linkwww2" style="display: block; color:red"/>
<h:outputLabel for="linkwww2Description"
value="Opis #2"/>
<h:inputText id="linkwww2Description"
binding="#{description2}"
style="width: 350px"
value="#{poiAdderBean.poi.link2Description}">
</h:inputText>
<h:message for="linkwww2Description" style="display: block; color:red"/>
<h:outputLabel value="#{msg.openingHours}"/>
<div class="col-md-12">
<div class="col-md-6">
<div class="input-group clockpicker">
<span class="input-group-addon" id="from">DO</span>
<h:inputText styleClass="form-control"
id="clockInputStart"
value="#{poiAdderBean.poi.openHoursStart}">
</h:inputText>
<span class="input-group-addon" id="timeFrom">
<span class="glyphicon glyphicon-time"></span>
</span>
</div>
</div>
<div class="col-md-6">
<div class="input-group clockpicker">
<span class="input-group-addon" id="to">DO</span>
<h:inputText styleClass="form-control"
id="clockInputStop"
value="#{poiAdderBean.poi.openHoursStop}">
</h:inputText>
<span class="input-group-addon" id="timeTo">
<span class="glyphicon glyphicon-time"></span>
</span>
</div>
</div>
</div>
<div class="col-md-12">
<h:outputLabel for="disableAccess"
value="#{msg.disableAccess}"/>
<h:selectBooleanCheckbox id="disableAccess"
value="#{poiAdderBean.poi.disableAccess}">
</h:selectBooleanCheckbox>
</div>
<div class="col-md-6">
<h:outputLabel for="titlePl" value="#{msg.polishTitle}"/>
<h:inputText id="titlePl"
value="#{poiAdderBean.polish.title}"
required="true"
requiredMessage="#{msg.fieldRequired}"/>
<h:message for="titlePl" style="display: block; color:red"/>
</div>
<div class="col-md-6">
<h:outputLabel for="titleEng" value="#{msg.englishTitle}"/>
<h:inputText id="titleEng"
value="#{poiAdderBean.english.title}"
required="true"
requiredMessage="#{msg.fieldRequired}"/>
<h:message for="titleEng" style="display: block; color:red"/>
</div>
<div class="col-md-6">
<h:outputLabel for="descriptionPl" value="#{msg.descriptionPl}"/>
<h:inputTextarea id="descriptionPl"
value="#{poiAdderBean.polish.description}"
style="resize: none"
required="true"
styleClass="form-control"
rows="4"
requiredMessage="#{msg.fieldRequired}"/>
<h:message for="descriptionPl" style="display: block; color:red"/>
</div>
<div class="col-md-6">
<h:outputLabel for="descriptionEng" value="#{msg.descriptionEn}"/>
<h:inputTextarea id="descriptionEng"
value="#{poiAdderBean.english.description}"
required="true"
style="resize: none"
styleClass="form-control"
rows="4"
requiredMessage="#{msg.description}"/>
<h:message for="descriptionEng" style="display: block; color:red"/>
</div>
<div class="col-md-6">
<h:inputFile styleClass="btn btn-default" id="file" value="#{poiAdderBean.uploadedFile}">
<f:ajax listener="#{poiAdderBean.uploadFile()}" execute="#this"/>
</h:inputFile>
</div>
</div>
<div class="col-md-6">
<div id="map-canvas" style="height: 600px;"></div>
</div>
<div class="col-md-12 loginSubmit">
<h:commandButton styleClass="btnDefault"
style="margin-top: 50px"
value="#{msg.add}"
action="#{poiAdderBean.createPoi}">
</h:commandButton>
</div>
</h:form>
</div>
</div>
<script type="text/javascript">
// <![CDATA[
$('.clockpicker').clockpicker({
placement: 'bottom',
align: 'left',
autoclose: true,
'default': 'now'
});
var map;
var marker;
var geocoder;
google.maps.event.addDomListener(window, 'load', initialize);
function initialize() {
geocoder = new google.maps.Geocoder();
var mapOptions = {
zoom: 13,
center: new google.maps.LatLng(50.05923273190915, 19.92233544588089)
};
map = new google.maps.Map(document.getElementById('map-canvas'),
mapOptions);
google.maps.event.addListener(map, 'click', function (event) {
setLatLong(event.latLng);
makeMarker(map, event.latLng);
codeLatLng(event.latLng);
}); //end addListener
}
function makeMarker(map, latLong) {
if (marker != null) {
marker.setMap(null);
}
marker = new google.maps.Marker({
position: latLong,
map: map
});
}
function codeAddress() {
var address = document.getElementById("address").value;
if (address != null && address != "") {
geocoder.geocode({'address': address}, function (results, status) {
if (status == google.maps.GeocoderStatus.OK) {
var location = results[0].geometry.location;
map.setCenter(location);
map.setZoom(18);
makeMarker(map, location);
setLatLong(location);
}
else {
alert("Geocode was not successful for the following reason: " + status);
}
});
} else {
alert("Nie podano adresu");
}
}
function codeLatLng(latLng) {
geocoder.geocode({
'latLng': latLng
}, function (results, status) {
if (status === google.maps.GeocoderStatus.OK) {
if (results[0]) {
document.getElementById("address").value = results[0].formatted_address;
console.log(results[0]);
} else {
alert('No results found');
}
} else {
alert('Geocoder failed due to: ' + status);
}
});
}
function setLatLong(location) {
document.getElementById("longitude").value = location.lng();
document.getElementById("latitude").value = location.lat();
}
//]]>
</script>
</ui:define>
</ui:composition>
and bean for this page:
import javax.annotation.PostConstruct;
import javax.enterprise.context.SessionScoped;
import javax.enterprise.event.Event;
import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;
import javax.inject.Inject;
import javax.inject.Named;
import javax.servlet.http.Part;
import java.io.*;
#Named("poiAdderBean")
#SessionScoped
public class PoiAdderBean implements Serializable {
#Inject
PrincipalBean principalBean;
#Inject
#Created
Event<Poi> poiCreated;
private Poi poi;
private Translation polish;
private Translation english;
private Part uploadedFile;
private Image image;
public void uploadFile() {
image = new Image();
byte[] bytes = new byte[0];
if (uploadedFile!= null) {
try {
InputStream is = uploadedFile.getInputStream();
if (is != null) {
bytes = IOUtils.toByteArray(is);
is.close();
}
} catch (IOException e) {
FacesMessage msg = new FacesMessage(FacesMessage.SEVERITY_ERROR,
"error uploading file",
null);
FacesContext.getCurrentInstance().addMessage(null, msg);
}
}
image.setContent(bytes);
image.setContentType(uploadedFile.getContentType());
}
public Part getUploadedFile() {
return uploadedFile;
}
public void setUploadedFile(Part uploadedFile) {
this.uploadedFile = uploadedFile;
}
public Poi getPoi() {
return poi;
}
public void setPoi(Poi poi) {
this.poi = poi;
}
public Translation getPolish() {
return polish;
}
public void setPolish(Translation polish) {
this.polish = polish;
}
public Translation getEnglish() {
return english;
}
public void setEnglish(Translation english) {
this.english = english;
}
public PoiCategory[] getPoiCategoryList(){
return PoiCategory.values();
}
#PostConstruct
public void init(){
poi = new Poi();
polish = new Translation(Language.PL, Status.READY);
english = new Translation(Language.EN, Status.READY);
}
public String createPoi(){
english.setAuthor(principalBean.getLoggedUser());
polish.setAuthor(principalBean.getLoggedUser());
poi.addTranslation(polish);
poi.addTranslation(english);
polish.setPoi(poi);
english.setPoi(poi);
if(image != null){
poi.setImage(principalBean.getDataAccess().mergeEntity(image));
}
principalBean.getDataAccess().mergeEntity(poi);
poiCreated.fire(poi);
return "/secure/poiTranslator.xhtml?faces-redirect=true";
}
}
For some completely strange and unknown to me reason, there is always error message on a bottom of a page that says:
#ViewScoped beans are not supported on stateless views
but this is clearly #SessionScoped bean. I can't find source of this error, that's why I posted entire code.
PLUS - when I don't upload a file - validation works just fine, and after successfully writing Poi object in database, page is redirected to poiTranslator page, just like it should. BUT when I add image - validation don't work, and page is not redirected - but objects are stored correctly in database.
Thanks for any help
Thanks to #Gimby I found small error in my template file.
Like in post from BalusC blog he posted, in my template was line that was enabling statelessness - which was not wanted in first place.
Thanks for help.
link to BalusC artickle
JSF 2.1
I am attempting to build some div tags conditionally.
The div tags must have the following format for their DOM id -
jquery_jplayer_# // where # is an integer
Additional requirements:
The resultant HTML should look like this -
<div id="jquery_jplayer_1" class="jp-jplayer" style="width: 0px; height: 0px;">
.
.
.
</div>
<div id="jquery_jplayer_2" class="jp-jplayer" style="width: 0px; height: 0px;">
.
.
.
</div>
Here is what my current code that is attempting to do this looks like:
<ui:repeat value="#{accessibilityTagging.previewTagsOrderByCurrentlySelectedOrderType}" var="currentTag" varStatus="loop_1">
<ui:repeat value="#{accessibilityTagging.accessibilityElements}" var="accessibilityElement" varStatus="loop_2">
<ui:repeat value="#{accessibilityElement.featureList}" var="feature" varStatus="loop_3">
<h:panelGroup rendered="#{feature.feature eq 1">
<!-- some irrelevant stuff happening here -->
</h:panelGroup>
<h:panelGroup rendered="#{feature.feature eq 2}">
<!-- relevant stuff happens here! -->
<div id="jquery_jplayer_#{loop_1.index + loop_2.index + loop_3.index + 1}" class="jp-jplayer"></div>
<div id="jp_container_#{loop_1.index + loop_2.index + loop_3.index + 1}" class="jp-audio">
<div class="jp-type-single">
<div class="jp-gui jp-interface">
<ul class="jp-controls">
<li>play</li>
<li>pause</li>
<li>stop</li>
<li>mute</li>
<li>unmute</li>
<li>max volume</li>
</ul>
<div class="jp-progress">
<div class="jp-seek-bar">
<div class="jp-play-bar"></div>
</div>
</div>
<div class="jp-volume-bar">
<div class="jp-volume-bar-value"></div>
</div>
<script type="text/javascript">
//<![CDATA[
$(document).ready(function(){
$("#jquery_jplayer_#{loop_1.index + loop_2.index + loop_3.index + 1}").jPlayer({
ready: function (event) {
$(this).jPlayer("setMedia", {
mp3: "#{ttsManager.serverURL}/TTSServlet?text="+encodeURI('#{feature.info}')
});
},
swfPath: "/common/js",
supplied: "mp3, m4a, oga",
wmode: "window",
smoothPlayBar: true,
keyEnabled: true,
remainingDuration: false,
toggleDuration: false,
errorAlerts: true
});
});
//]]>
</script>
</h:panelGroup>
</ui:repeat>
</ui:repeat>
</ui:repeat>
There are two problems a with what I have:
The innermost loop resets the varStatus back to 0 after it finishes iterating.
The varStatus index value starts with 0. I need it to start at 1.
Any suggestions on how to tackle this problem?
(Is there a way that I store the current counter in a variable or hidden field?)
I do not want to use JSTL (e.g. <c:set> as this will mix JSF components with JSP).
I have a portlet in which there is a pop up .The content of the popup does not change but instead shows the same page from where it is clicked.When i click the notify button the popup shows but with the content of view.jsp.
All the code is present in view.jsp
<%#page import="com.mvantage.contract.model.Contract"%>
<%# include file="/init.jsp" %>
<portlet:defineObjects />
<%
PortletURL actionURL1=renderResponse.createActionURL();
actionURL1.setParameter(ActionRequest.ACTION_NAME,"navigateDashboard");
ArrayList<Contract> contractParameterList= (ArrayList<Contract>)renderRequest.getAttribute("contract");%>
<portlet:renderURL var="contractURL" windowState="<%= LiferayWindowState.POP_UP.toString()%>">
<portlet:param name="jspPage" value="/html/popup.jsp" />
</portlet:renderURL>
<script type="text/javascript">
alert("Inside new popup");
function showPopup() {
AUI().use('aui-dialog', 'aui-io', 'event', 'event-custom', function(A) {
var dialog = new A.Dialog({
title: 'Pop Up',
centered: true,
draggable: true,
modal: true,
width: 500,
height: 500,
}).plug(A.Plugin.IO, {uri: '<%= contractURL %>'}).render();
dialog.show();
});
}
<div id="container">
<table cellpadding="0" cellspacing="0" border="0" class="display" id="example4">
<thead>
<tr>
<th>a</th>
<th>b/th>
<th>c</th>
<th>d</th>
<th>e</th>
<th>f</th>
<th>g</th>
</tr>
</thead>
<tbody>
<%for(int i=0; i<contractParameterList.size(); i++ ){
Contract contractParameter = new Contract();
contractParameter = (Contract)contractParameterList.get(i);
%>
<tr class="odd gradeX">
<td><%=contractParameter.getAssetName()%></td>
<%actionURL1.setParameter("assetId",contractParameter.getAssetID());%>
<td><%=contractParameter.getAssetID()%></td>
<td><%=contractParameter.getCustomerName()%></td>
<td><%=contractParameter.getLocation()%></td>
<td><%=contractParameter.getRiskType()%></td>
<td><%=contractParameter.getContractNotificationTrigger()%></td>
<td><input class="notify" type="button" value="Notify" onclick="showPopup('<%=contractURL.toString()%>')"></td></tr> <%} %></tbody></table> <div style="clear:both;"></div></div>
The way you are using the A.Dialog it's not the best for me.
Try to use this way: http://alloyui.com/versions/1.7.x/examples/dialog/real-world/
Hi you can try below simplified code :
<aui:button value="Pop Up" icon="av-icon" iconAlign="left"
type="button" onClick="displayPopUp()" cssClass="notify" />
<script type="text/javascript">
function displayPopUp(){
Liferay.Util.openWindow({dialog: {width: 500,height: 500,destroyOnHide: true}, title: 'Pop Up', uri: '<%=contractURL%>
'
});
}
</script>