primeFaces select oneMenu Show Cases has select advance .and it has one attribute ( converter ) .
primeFaces Code:
<p:selectOneMenu id="advanced" value="#{selectOneMenuView.theme}" converter="#{themeConverter}" panelStyle="width:180px"
effect="fade" var="t" style="width:160px" filter="true" filterMatchMode="startsWith">
<f:selectItems value="#{selectOneMenuView.themes}" var="theme" itemLabel="#{theme.displayName}" itemValue="#{theme}" />
<p:column style="width:10%">
<h:graphicImage name="showcase/images/themeswitcher/themeswitcher-#{t.name}.png" alt="#{t.name}" styleClass="ui-theme" />
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="Name"/>
</f:facet>
<h:outputText value="#{t.displayName}" />
</p:column>
<f:facet name="footer">
<p:separator />
<h:outputText value="#{selectOneMenuView.themes.size()} themes" style="font-weight:bold;"/>
</f:facet>
</p:selectOneMenu>
i'm looking for where's converter="#{themeConverter}" in the code (page.xhtml and manage Bean , class) i don't find it . they don't mention it(themeConverter) in other class whether annotation or class name or variable.
anybody has idea how use it ?
with example
thank you
ThemeConverter source code is right here:
https://github.com/primefaces/primefaces-showcase/blob/master/src/main/java/org/primefaces/showcase/convert/ThemeConverter.java
package org.primefaces.showcase.convert;
import javax.faces.application.FacesMessage;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import javax.faces.convert.ConverterException;
import javax.faces.convert.FacesConverter;
import javax.inject.Inject;
import javax.inject.Named;
import org.primefaces.showcase.domain.Theme;
import org.primefaces.showcase.service.ThemeService;
#Named
#FacesConverter(value = "themeConverter", managed = true)
public class ThemeConverter implements Converter<Theme> {
#Inject private ThemeService themeService;
#Override
public Theme getAsObject(FacesContext context, UIComponent component, String value) {
if(value != null && value.trim().length() > 0) {
try {
return themeService.getThemes().get(Integer.parseInt(value));
} catch(NumberFormatException e) {
throw new ConverterException(new FacesMessage(FacesMessage.SEVERITY_ERROR, "Conversion Error", "Not a valid theme."));
}
}
else {
return null;
}
}
#Override
public String getAsString(FacesContext context, UIComponent component, Theme value) {
if(value != null) {
return String.valueOf(value.getId());
}
else {
return null;
}
}
}
i have a Java EE setup with JSF and primefaces and i'm trying to generate a selection, based on the chosen entry in a <selectOneMenu>.
My problem is that the selectManyCheckbox (or any other similar ui element) has all items filled in correctly and the items are selectable, but if a selection was made, the action of the commandButton doesn't get called.
I've set a breakpoint on the method. If I don't choose any item, the breakpoint gets hit, if I choose any amount of items greater than zero, the breakpoint doesn't get hit.
I read that one solution could be to define a converter. I tried that and if I set a breakpoint, it correctly converts the items, I chose, but nevertheless the method, defined as action, doesn't get called.
Btw: Sorry for german code, i'm a german and naming the methods and variables in german was set by guideline
The xhtml File:
<h:form>
<p:panelGrid columns="2">
<p:outputLabel for="kennzeichenInput">Kennzeichen: </p:outputLabel>
<p:inputText id="kennzeichenInput"></p:inputText>
<p:outputLabel for="studiengang">Studiengang: </p:outputLabel>
<p:selectOneMenu id="studiengang" value="#{registrationsController.gewaehlterStudiengang}">
<f:selectItem itemValue="#{null}" itemLabel="--Studiengang aussuchen--"/>
<f:selectItems value="#{registrationsController.getAlleStudiengaenge()}"/>
<p:ajax value="valueChange" update="vorlesungenInStudiengang" listener="#{registrationsController.onStudiengangGeaendert}"/>
</p:selectOneMenu>
</p:panelGrid>
<h:selectManyCheckbox id="vorlesungenInStudiengang"
value="#{registrationsController.gewaehlteVorlesungen}"
label="Vorlesungen" converter="de.phwt.parkhwt.domain.converter.vorlesung_converter">
<f:selectItems value="#{registrationsController.vorlesungen}"/>
</h:selectManyCheckbox >
<p:commandButton value="Registrieren" type="submit" action="#{registrationsController.registriereKennzeichen()}"/>
</h:form>
The Bean:
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import javax.enterprise.context.RequestScoped;
import javax.faces.event.AjaxBehaviorEvent;
import javax.inject.Inject;
import javax.inject.Named;
import de.phwt.parkhwt.domain.CollectionKonverter;
import de.phwt.parkhwt.domain.KennzeichenRepository;
import de.phwt.parkhwt.domain.Studiengang;
import de.phwt.parkhwt.domain.Vorlesung;
#RequestScoped
#Named
public class RegistrationsController
{
#Inject
private KennzeichenRepository repository;
private String gewaehlterStudiengang;
private List<Vorlesung> vorlesungen;
private List<Vorlesung> gewaehlteVorlesungen;
public String getGewaehlterStudiengang()
{
return gewaehlterStudiengang;
}
public void setGewaehlterStudiengang(String gewaehlterStudiengang)
{
this.gewaehlterStudiengang = gewaehlterStudiengang;
}
public List<Vorlesung> getVorlesungen()
{
return vorlesungen;
}
public void setVorlesungen(List<Vorlesung> vorlesungen)
{
this.vorlesungen = vorlesungen;
}
public Vorlesung getVorlesung(String name)
{
return this.repository.sucheVorlesung(name);
}
public List<Vorlesung> getGewaehlteVorlesungen()
{
return gewaehlteVorlesungen;
}
public void setGewaehlteVorlesungen(List<Vorlesung> gewählteVorlesungen)
{
this.gewaehlteVorlesungen = gewählteVorlesungen;
}
public Set<Studiengang> getAlleStudiengaenge()
{
return repository.getAlleStudiengaenge();
}
public List<Vorlesung> getVorlesungenDesStudiengangs(String gewaehlterStudiengang)
{
Studiengang studiengang = repository.sucheStudiengang(gewaehlterStudiengang);
return CollectionKonverter.toList(studiengang.getVorlesungen());
}
public String registriereKennzeichen()
{
return "";
}
public void onStudiengangGeaendert(AjaxBehaviorEvent event)
{
if (getGewaehlterStudiengang() != null)
{
setVorlesungen(getVorlesungenDesStudiengangs(getGewaehlterStudiengang()));
}
else
{
setVorlesungen(new ArrayList<Vorlesung>());
}
}
}
The Converter:
import javax.el.ValueExpression;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import javax.faces.convert.FacesConverter;
import javax.inject.Inject;
import de.phwt.parkhwt.controller.RegistrationsController;
#FacesConverter("de.phwt.parkhwt.domain.converter.vorlesung_converter")
public class VorlesungConverter implements Converter
{
#Inject
KennzeichenRepository repository;
#Override
public Object getAsObject(FacesContext context, UIComponent component, String value)
{
ValueExpression vex =
context.getApplication()
.getExpressionFactory()
.createValueExpression(context.getELContext(),
"#{registrationsController}", RegistrationsController.class);
RegistrationsController reg = (RegistrationsController) vex.getValue(context.getELContext());
Vorlesung vorlesung = reg.getVorlesung(value);
return vorlesung;
}
#Override
public String getAsString(FacesContext context, UIComponent component, Object value)
{
if (value.getClass() == new Vorlesung().getClass())
{
Vorlesung v = (Vorlesung) value;
return v.getName();
}
return null;
}
}
Thanks to Mike Balthasar for his comment!
The solution was to add ajax="false" to my commandButton.
For more information, see his comment.
I´m a begginer in Primefaces.... And I tried to make the example DragDrop - Native Primefaces
I´ll posted all the clases and xhtml files involved for this example.
I can drag any columns but it´s not working the droping property....
You can see an image showing the trouble in this link https://lh3.googleusercontent.com/clMOtntqI99ltjXGYpzUGt-8yg4N8ahtQQIBT5leNA=w314-h207-p-no
The fist file is dndColumns.xhtml
<!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://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:p="http://primefaces.org/ui">
<h:head>
<title>dndColumns</title>
</h:head>
<body>
<h:form id="form">
<p:remoteCommand name="updateColumns" actionListener="#{tableBean.onColumnDrop}"
update="cars" oncomplete="initDND()"/>
<p:tree id="tree" value="#{tableBean.availableColumns}" var="column">
<p:treeNode>
<h:outputText value="#{column}" />
</p:treeNode>
<p:treeNode type="column" icon="ui-icon-grip-dotted-vertical">
<h:outputText value="#{column.property}" />
</p:treeNode>
</p:tree>
<p:dataTable id="cars" var="car" value="#{tableBean.carsSmall}">
<p:columns value="#{tableBean.columns}" var="column">
<f:facet name="header">
<h:outputText style="float:left;display:block;height:12px;width:10px;border:0 none;"
styleClass="droppoint dropleft" />
<h:outputText style="float:right;display:block;height:12px;width:10px;border:0 none;"
styleClass="droppoint dropright" />
<h:outputText value="#{column.header}" />
</f:facet>
<h:outputText value="#{car[column.property]}" />
</p:columns>
</p:dataTable>
<script type="text/javascript">
function initDND() {
$('.ui-treenode-leaf').draggable({
helper: 'clone',
scope: 'treetotable',
zIndex: ++PrimeFaces.zindex
});
$('.ui-datatable .droppoint').droppable({
activeClass: 'ui-state-active',
hoverClass: 'ui-state-highlight',
tolerance: 'pointer',
scope: 'treetotable',
drop: function(event, ui) {
var property = ui.draggable.find('.ui-treenode-label').text(),
droppedColumnId = $(this).parents('th:first').attr('id'),
dropPos = $(this).hasClass('dropleft') ? 0 : 1;
treeToTable([
{name: 'property', value: property}
,{name: 'droppedColumnId', value: droppedColumnId}
,{name: 'dropPos', value: dropPos}
]);
}
});
$('.ui-datatable th').draggable({
helper: 'clone',
scope: 'tabletotree',
helper: function() {
var th = $(this);
return th.clone().css('width', th.width());
}
});
$('.ui-tree').droppable({
helper: 'clone',
scope: 'tabletotree',
activeClass: 'ui-state-active',
hoverClass: 'ui-state-highlight',
tolerance: 'touch',
drop: function(event, ui) {
tableToTree([
{name: 'colIndex', value: ui.draggable.index()}
]);
}
});
}
$(function() {
initDND();
});
</script>
<hr/>
<p:menu>
<p:submenu label="Resources">
<p:menuitem value="Demo" url="http://www.primefaces.org/showcase-labs/ui/dndColumns.jsf" />
</p:submenu>
</p:menu>
</h:form>
</body>
</html>
The second file is TableBean.java
package org.sagarpa.src.managedBean;
import java.io.Serializable;
import java.util.Arrays;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.logging.Logger;
import javax.faces.context.FacesContext;
import org.primefaces.model.DefaultTreeNode;
import org.primefaces.model.TreeNode;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
// import org.primefaces.examples.domain.Car;
import org.sagarpa.src.bean.Car;
#ManagedBean
#SessionScoped
public class TableBean implements Serializable {
private final static List<String> VALID_COLUMN_KEYS = Arrays.asList("model", "manufacturer", "year", "color");
private final static String[] colors;
private final static String[] manufacturers;
private String columnTemplate = "model manufacturer year";
static {
colors = new String[10];
colors[0] = "Black";
colors[1] = "White";
colors[2] = "Green";
colors[3] = "Red";
colors[4] = "Blue";
colors[5] = "Orange";
colors[6] = "Silver";
colors[7] = "Yellow";
colors[8] = "Brown";
colors[9] = "Maroon";
manufacturers = new String[10];
manufacturers[0] = "Mercedes";
manufacturers[1] = "BMW";
manufacturers[2] = "Volvo";
manufacturers[3] = "Audi";
manufacturers[4] = "Renault";
manufacturers[5] = "Opel";
manufacturers[6] = "Volkswagen";
manufacturers[7] = "Chrysler";
manufacturers[8] = "Ferrari";
manufacturers[9] = "Ford";
}
private List<Car> carsSmall;
private List<Car> carsLarge;
private List<ColumnModel> columns = new ArrayList<ColumnModel>();
private TreeNode availableColumns;
public TableBean() {
carsSmall = new ArrayList<Car>();
populateRandomCars(carsSmall, 9);
createDynamicColumns();
createAvailableColumns();
}
private void populateRandomCars(List<Car> list, int size) {
for(int i = 0 ; i < size ; i++)
list.add(new Car(getRandomModel(), getRandomYear(), getRandomManufacturer(), getRandomColor()));
}
public List<Car> getCarsSmall() {
return carsSmall;
}
private int getRandomYear() {
return (int) (Math.random() * 50 + 1960);
}
private String getRandomColor() {
return colors[(int) (Math.random() * 10)];
}
private String getRandomManufacturer() {
return manufacturers[(int) (Math.random() * 10)];
}
private String getRandomModel() {
return UUID.randomUUID().toString().substring(0, 8);
}
public List<ColumnModel> getColumns() {
return columns;
}
private void createAvailableColumns() {
availableColumns = new DefaultTreeNode("Root", null);
TreeNode root = new DefaultTreeNode("Columns", availableColumns);
root.setExpanded(true);
TreeNode model = new DefaultTreeNode("column", new ColumnModel("Model", "model"), root);
TreeNode year = new DefaultTreeNode("column", new ColumnModel("Year", "year"), root);
TreeNode manufacturer = new DefaultTreeNode("column", new ColumnModel("Manufacturer", "manufacturer"), root);
TreeNode color = new DefaultTreeNode("column", new ColumnModel("Color", "color"), root);
}
public TreeNode getAvailableColumns() {
return availableColumns;
}
public void createDynamicColumns() {
String[] columnKeys = columnTemplate.split(" ");
columns.clear();
for(String columnKey : columnKeys) {
String key = columnKey.trim();
if(VALID_COLUMN_KEYS.contains(key)) {
columns.add(new ColumnModel(columnKey.toUpperCase(), columnKey));
}
}
}
public void treeToTable() {
Map<String,String> params = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap();
String property = params.get("property");
String droppedColumnId = params.get("droppedColumnId");
String dropPos = params.get("dropPos");
String[] droppedColumnTokens = droppedColumnId.split(":");
int draggedColumnIndex = Integer.parseInt(droppedColumnTokens[droppedColumnTokens.length - 1]);
int dropColumnIndex = draggedColumnIndex + Integer.parseInt(dropPos);
//add to columns
this.columns.add(dropColumnIndex, new ColumnModel(property.toUpperCase(), property));
//remove from nodes
TreeNode root = availableColumns.getChildren().get(0);
for(TreeNode node : root.getChildren()) {
ColumnModel model = (ColumnModel) node.getData();
if(model.getProperty().equals(property)) {
root.getChildren().remove(node);
break;
}
}
}
public void tableToTree() {
Map<String,String> params = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap();
int colIndex = Integer.parseInt(params.get("colIndex"));
//remove from table
ColumnModel model = this.columns.remove(colIndex);
//add to nodes
TreeNode property = new DefaultTreeNode("column", model, availableColumns.getChildren().get(0));
}
static public class ColumnModel implements Serializable {
private String header;
private String property;
public ColumnModel(String header, String property) {
this.header = header;
this.property = property;
}
public String getHeader() {
return header;
}
public String getProperty() {
return property;
}
}
}
And the third and last file is Car.java
package org.sagarpa.src.bean;
// import java.util.Date;
public class Car {
private String model;
private int year;
private String manufacturer;
private String color;
public Car(String model, int year, String manufacturer, String color) {
this.model = model;
this.year = year;
this.manufacturer = manufacturer;
this.color = color;
}
public String getModel() {
return model;
}
public void setModel(String model) {
this.model = model;
}
public int getYear() {
return year;
}
public void setYear(int year) {
this.year = year;
}
public String getManufacturer() {
return manufacturer;
}
public void setManufacturer(String manufacturer) {
this.manufacturer = manufacturer;
}
public String getColor() {
return color;
}
public void setColor(String color) {
this.color = color;
}
}
The problem exists when I want to drag any component because its can´t drop on the table or on the Columns area rectangle.
Please.... Could you help me to complete the code ??? Any sugestion ???
Regards...
I YET solved my problem....
Only make a change into the fist file is dndColumns.xhtml
We need to replace this line:
<p:remoteCommand name="updateColumns" actionListener="#{tableBean.onColumnDrop}" update="cars" oncomplete="initDND()"/>
for other these two lines:
<p:remoteCommand name="treeToTable" actionListener="#{tableBean.treeToTable}" update="tree cars" oncomplete="initDND()"/>
<p:remoteCommand name="tableToTree" actionListener="#{tableBean.tableToTree}" update="tree cars" oncomplete="initDND()"/>
And test it again.....
WONDERFUL....!!!!!!
I'll post the complete dndColumns.xhtml file.
<!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://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:p="http://primefaces.org/ui">
<h:head>
<title>dndColumns</title>
</h:head>
<body>
<h1 class="title ui-widget-header ui-corner-all">DragDrop - Native</h1>
<p>This sample demonstrates how to integrate low level jquery apis with PrimeFaces. Tree component displays the available
columns which are draggable. Column headers have drop targets and dropping a treenode onto one of these adds the related property column to the datatable.
Column headers can also be moved back to the tree.</p>
<h:form id="form">
<p:remoteCommand name="treeToTable" actionListener="#{tableBean.treeToTable}" update="tree cars" oncomplete="initDND()"/>
<p:remoteCommand name="tableToTree" actionListener="#{tableBean.tableToTree}" update="tree cars" oncomplete="initDND()"/>
<p:tree id="tree" value="#{tableBean.availableColumns}" var="column">
<p:treeNode>
<h:outputText value="#{column}" />
</p:treeNode>
<p:treeNode type="column" icon="ui-icon-grip-dotted-vertical">
<h:outputText value="#{column.property}" />
</p:treeNode>
</p:tree>
<br />
<p:dataTable id="cars" var="car" value="#{tableBean.carsSmall}">
<p:columns value="#{tableBean.columns}" var="column">
<f:facet name="header">
<h:outputText style="float:left;display:block;height:20px;width:10px;border:0 none;" styleClass="droppoint dropleft" />
<h:outputText style="float:right;display:block;height:20px;width:10px;border:0 none;" styleClass="droppoint dropright" />
<h:outputText value="#{column.header}" />
</f:facet>
<h:outputText value="#{car[column.property]}" />
</p:columns>
</p:dataTable>
<script type="text/javascript">
function initDND() {
$('.ui-treenode-leaf').draggable({
helper: 'clone',
scope: 'treetotable',
zIndex: ++PrimeFaces.zindex
});
$('.ui-datatable .droppoint').droppable({
activeClass: 'ui-state-active',
hoverClass: 'ui-state-highlight',
tolerance: 'pointer',
scope: 'treetotable',
drop: function(event, ui) {
var property = ui.draggable.find('.ui-treenode-label').text(),
droppedColumnId = $(this).parents('th:first').attr('id'),
dropPos = $(this).hasClass('dropleft') ? 0 : 1;
treeToTable([
{name: 'property', value: property}
,{name: 'droppedColumnId', value: droppedColumnId}
,{name: 'dropPos', value: dropPos}
]);
}
});
$('.ui-datatable th').draggable({
helper: 'clone',
scope: 'tabletotree',
helper: function() {
var th = $(this);
return th.clone().css('width', th.width());
}
});
$('.ui-tree').droppable({
helper: 'clone',
scope: 'tabletotree',
activeClass: 'ui-state-active',
hoverClass: 'ui-state-highlight',
tolerance: 'touch',
drop: function(event, ui) {
tableToTree([
{name: 'colIndex', value: ui.draggable.index()}
]);
}
});
}
$(function() {
initDND();
});
</script>
<hr/>
<p:menu>
<p:submenu label="Resources">
<p:menuitem value="Demo" url="http://www.primefaces.org/showcase-labs/ui/dndColumns.jsf" />
</p:submenu>
</p:menu>
</h:form>
</body>
</html>
How can i create a secondary y axis on primefaces 3.4?
i already read the primefaces manual e googled out there
Google tells that y2axis (from jqplot) is the way
but primefaces manual doesn't mention y2axis at all
my class
package br.com.inmetrics.managedbean;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import org.primefaces.model.chart.CartesianChartModel;
import org.primefaces.model.chart.LineChartSeries;
import javax.faces.event.ComponentSystemEvent;
import br.com.inmetrics.entity.Grafico;
import javax.faces.event.AbortProcessingException;
import br.com.inmetrics.dao.SistemaDAO;
#ManagedBean(name = "chartMB")
#SessionScoped
public class ChartManagedBean implements Serializable {
private static final long serialVersionUID = 1L;
private SistemaDAO apoioDao = new SistemaDAO();
private List<Grafico> graficos = new ArrayList<Grafico>();
private CartesianChartModel categoryModel;
private CartesianChartModel linearModel;
private String sistema;
private String hostname;
private String metrica;
private String alinhamento;
private String funcao;
private int maximo;
public ChartManagedBean() {
}
public CartesianChartModel getCategoryModel() {
return categoryModel;
}
public CartesianChartModel getLinearModel() {
return linearModel;
}
private void createLinearModel() {
try {
graficos = apoioDao.getGrafico(hostname, metrica);
} catch (Exception ex) {
ex.printStackTrace();
}
linearModel = new CartesianChartModel();
LineChartSeries series1 = new LineChartSeries();
this.alinhamento = metrica.equalsIgnoreCase("GBL_LOADAVG") ? "ne" : "e";
this.funcao = metrica.equalsIgnoreCase("GBL_LOADAVG") ? "ext2" : "ext1";
this.maximo = metrica.equalsIgnoreCase("GBL_LOADAVG") ? 1 : 100;
series1.setLabel(metrica);
for (Grafico s : graficos) {
series1.set(s.getData(), s.getValor());
}
LineChartSeries series2 = new LineChartSeries();
series2.setLabel("Threshold");
series2.setMarkerStyle("filledSquare");
for (Grafico t : graficos) {
series2.set(t.getData(), metrica.equalsIgnoreCase("GBL_LOADAVG") ? 0.48 : 80);
}
//teste
LineChartSeries series3 = new LineChartSeries();
series3.setLabel("Threshold");
series3.setMarkerStyle("filledSquare");
for (Grafico t : graficos) {
series3.set(t.getData(), metrica.equalsIgnoreCase("GBL_LOADAVG") ? 0.48 : 90);
}
linearModel.addSeries(series1);
linearModel.addSeries(series2);
//teste
linearModel.addSeries(series3);
}
public String getSistema() {
return sistema;
}
public void setSistema(String sistema) {
this.sistema = sistema;
}
public String getHostname() {
return hostname;
}
public void setHostname(String hostname) {
this.hostname = hostname;
}
public String getMetrica() {
return metrica;
}
public void setMetrica(String metrica) {
this.metrica = metrica;
}
public void push(ComponentSystemEvent evt) throws AbortProcessingException {
createLinearModel();
}
public String getAlinhamento() {
return alinhamento;
}
public void setAlinhamento(String alinhamento) {
this.alinhamento = alinhamento;
}
public int getMaximo() {
return maximo;
}
public void setMaximo(int maximo) {
this.maximo = maximo;
}
public String getFuncao() {
return funcao;
}
public void setFuncao(String funcao) {
this.funcao = funcao;
}
}
my xhtml:
<h:head>
<link rel="shortcut icon" href="images/ico.ico" />
<title>Capacity - Dashboard</title>
<link rel="stylesheet" type="text/css" href="styles.css" />
</h:head>
<h:body>
<h:form>
<script type="text/javascript">
function ext1() {
this.cfg.axes.yaxis.tickOptions = {
formatString : '%d\%'
};
}
function ext2() {
this.cfg.axes.yaxis.tickOptions = {
formatString : '%.2f'
};
}
</script>
<div id="externa_corpo">
<div id="corpo">
<div id="logo">
<img src="images/pt/logo.png" width="200" height="74" />
</div>
<!--logo-->
<div id="titulo-book">
Dashboard <br />
</div>
<div id="logo-cliente">
<img src="images/logoTIM.jpg" width="122" height="53" />
</div>
<br /> <br /> <br /> <br /> <br /> <br /> <br /> <br />
<p:lineChart id="linear" value="#{chartMB.linearModel}"
legendPosition="#{chartMB.alinhamento}"
title="#{chartMB.hostname} - P90" minY="0" maxY="#{chartMB.maximo}"
style="height:450px" animate="true" xaxisAngle="270"
seriesColors="FFFF00, FF0000" extender="#{chartMB.funcao}" showMarkers="true"
zoom="false" />
<f:metadata>
<f:viewParam name="sistema" value="#{chartMB.sistema}" />
<f:viewParam name="hostname" value="#{chartMB.hostname}" />
<f:viewParam name="metrica" value="#{chartMB.metrica}" />
<f:event type="preRenderView" listener="#{chartMB.push}" />
</f:metadata>
</div>
</div>
</h:form>
</h:body>
</html>
Kind Regards and Best Wishes,
Geraldo Netto
I am trying to toggle between a simple "click the row to select" table and a "multi-select Checkbox in the first column table". I have a check box outside the table to change the state of the table. For the simple table (no check boxes in the first column) a selectionMode must be set in the p:datatable tag; either to "single" or "multiple". In this state everything works fine.
If the state is changed so that the multi-select column is rendered, the click event seems to be consumed by selecting the selecting the row. In general when using this multi-select check box table the selectionMode would not be set; hence the mouse event would change the state of the check box.
How do I "unset" the selectionMode. Here are the things that did not work:
table.setSelectionMode(null) - this breaks the selection (so does setting to "")
table.getAttributes().get("javax.faces.component.UIComponentBase.attributesThatAreSet") then removing the selectionMode (it isn't in the set attributes).
My xhtml looks like:
<h:form id="addForm">
<p:panel toggleable="false" closable="false" widgetVar="remarksPanel"
id="remarksPanel" style="margin-bottom:5px; overflow:auto;">
<p:selectBooleanCheckbox value="#{multipleSelectBean.bulkEdit}">
<p:ajax update="addForm:remarksTable"
listener="#{multipleSelectBean.editModeChanged}" />
</p:selectBooleanCheckbox>
<h:outputText value=" Bulk Edit" />
<p:dataTable var="remark" id="remarksTable" rowIndexVar="rowNum"
value="#{multipleSelectBean.remarkList}" rowKey="#{remark.id}"
selectionMode="multiple"
selection="#{multipleSelectBean.selectedRemarks}">
<p:column rendered="#{multipleSelectBean.bulkEdit}"
selectionMode="multiple" style="width:18px" />
<p:column headerText="Remark">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{remark.remark}" />
</f:facet>
<f:facet name="input">
<p:inputText style="width:98%" id="remark"
value="#{remark.remark}" />
</f:facet>
</p:cellEditor>
</p:column>
</p:dataTable>
</p:panel>
</h:form>
My Bean Looks Like:
package gov.gsa.krichards.sandbox;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.Set;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.context.FacesContext;
import org.primefaces.component.datatable.DataTable;
import org.primefaces.event.SelectEvent;
#ManagedBean
#SessionScoped
public class MultipleSelectBean implements Serializable {
private static final long serialVersionUID = 1L;
private final static String[] categoryList;
private List<Remark> remarkList = new ArrayList<Remark>();
private Remark[] selectedRemarks = null;
private String words = "Mauris interdum, turpis nec euismod c aliquet fermentum nisl, in tristique arcu tincidunt nec.";
private boolean bulkEdit = false;
private boolean initialized = false;
static {
categoryList = new String[4];
categoryList[0] = "Cat5";
categoryList[1] = "Cat4";
categoryList[2] = "Cat3-UTP";
categoryList[3] = "BNC";
}
public MultipleSelectBean() {
Random r = new Random();
for (int i = 0; i < 10; i++) {
String cat = categoryList[r.nextInt(4)];
int len = words.length();
int begIndex = r.nextInt(len / 2);
int endIndex = begIndex + r.nextInt(len - begIndex);
Remark rem = new Remark(i, cat, words.substring(begIndex, endIndex));
remarkList.add(rem);
}
}
public void editModeChanged() {
System.out.println("changed to " + bulkEdit);
}
public void setBulkEdit(boolean arg) {
DataTable table = (DataTable) FacesContext.getCurrentInstance()
.getViewRoot().findComponent("addForm:remarksTable");
bulkEdit = arg;
if (bulkEdit) {
table.setSelectionMode("single");
} else {
table.setSelectionMode("multiple");
}
}
public boolean isBulkEdit() {
return bulkEdit;
}
public List<Remark> getRemarkList() {
return remarkList;
}
public void setRemarkList(List<Remark> remarkList) {
this.remarkList = remarkList;
}
public String[] getCategoryList() {
return categoryList;
}
public Remark[] getSelectedRemarks() {
if (selectedRemarks == null || selectedRemarks.length == 0)
return null;
return selectedRemarks;
}
public void setSelectedRemarks(Remark[] selectedRemarks) {
this.selectedRemarks = selectedRemarks;
}
}