Skip to content

Commit

Permalink
PF 13 fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
melloware committed Jun 22, 2023
1 parent 25106af commit b267419
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 130 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,11 @@
*/
package org.primefaces.showcase.view.chartjs;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import jakarta.annotation.PostConstruct;
import jakarta.enterprise.context.RequestScoped;
import jakarta.faces.application.FacesMessage;
import jakarta.faces.context.FacesContext;
import jakarta.inject.Named;

import org.primefaces.event.ItemSelectEvent;
import org.primefaces.model.charts.ChartData;
import org.primefaces.model.charts.axes.cartesian.CartesianScales;
Expand Down Expand Up @@ -74,6 +68,11 @@
import org.primefaces.model.charts.radar.RadarChartOptions;
import org.primefaces.model.charts.scatter.ScatterChartModel;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

@Named
@RequestScoped
public class ChartJsView implements Serializable {
Expand Down Expand Up @@ -425,7 +424,7 @@ public void createBarModel() {
options.setAnimation(animation);

barModel.setOptions(options);
barModel.setExtender("barChartExtender");
//barModel.setExtender("barChartExtender");
}

public void createBarModel2() {
Expand Down Expand Up @@ -846,7 +845,7 @@ public void createRadarModel2() {
List<List<String>> labels = new ArrayList<>();
labels.add(new ArrayList(Arrays.asList("Process", "Excellence")));
labels.add(new ArrayList(Arrays.asList("Problem", "Solving")));
labels.add(new ArrayList(Arrays.asList("Facilitation")));
labels.add(new ArrayList(List.of("Facilitation")));
labels.add(new ArrayList(Arrays.asList("Project", "Mgmt")));
labels.add(new ArrayList(Arrays.asList("Change", "Mgmt")));
data.setLabels(labels);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,141 +23,59 @@
*/
package org.primefaces.showcase.view.data.dataexporter;

import java.io.IOException;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.Collections;
import java.util.List;

import jakarta.el.MethodExpression;
import jakarta.faces.FacesException;
import jakarta.faces.component.UIComponent;
import jakarta.faces.context.ExternalContext;
import jakarta.faces.context.FacesContext;

import org.primefaces.component.api.DynamicColumn;
import org.primefaces.component.api.UIColumn;
import org.primefaces.component.datatable.DataTable;
import org.primefaces.component.datatable.export.DataTableExporter;
import org.primefaces.component.export.ExportConfiguration;
import org.primefaces.component.export.ExporterOptions;
import org.primefaces.util.ComponentUtils;
import org.primefaces.util.Constants;
import org.primefaces.component.export.ExporterUtils;
import org.primefaces.util.EscapeUtils;

public class TextExporter extends DataTableExporter {

private OutputStreamWriter osw;
private PrintWriter writer;

@Override
protected void preExport(FacesContext context, ExportConfiguration exportConfiguration) throws IOException {
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;
import java.util.Collections;

osw = new OutputStreamWriter(getOutputStream(), exportConfiguration.getEncodingType());
writer = new PrintWriter(osw);
public class TextExporter extends DataTableExporter<PrintWriter, ExporterOptions> {

if (exportConfiguration.getPreProcessor() != null) {
exportConfiguration.getPreProcessor().invoke(context.getELContext(), new Object[]{writer});
}
public TextExporter() {
super(null, Collections.emptySet(), false);
}

@Override
protected void doExport(FacesContext context, DataTable table, ExportConfiguration exportConfiguration, int index) throws IOException {

writer.append("" + table.getId() + "\n");

if (exportConfiguration.isPageOnly()) {
exportPageOnly(context, table, writer);
} else if (exportConfiguration.isSelectionOnly()) {
exportSelectionOnly(context, table, writer);
} else {
exportAll(context, table, writer);
protected PrintWriter createDocument(FacesContext context) throws IOException {
try {
OutputStreamWriter osw = new OutputStreamWriter(os(), exportConfiguration.getEncodingType());
return new PrintWriter(osw);
} catch (UnsupportedEncodingException e) {
throw new FacesException(e);
}

writer.append("" + table.getId() + "");

table.setRowIndex(-1);
}

@Override
protected void postExport(FacesContext context, ExportConfiguration exportConfiguration) throws IOException {

if (exportConfiguration.getPostProcessor() != null) {
exportConfiguration.getPostProcessor().invoke(context.getELContext(), new Object[]{writer});
}
protected void exportTable(FacesContext context, DataTable table, int index) throws IOException {
document.append("").append(table.getId()).append("\n");

writer.flush();
writer.close();
writer = null;
super.exportTable(context, table, index);

osw.close();
osw = null;
document.append("").append(table.getId());
}

@Override
protected void preRowExport(DataTable table, Object document) {
((PrintWriter) document).append("\t" + table.getVar() + "\n");
protected void preRowExport(FacesContext context, DataTable table) {
(document).append("\t").append(table.getVar()).append("\n");
}

@Override
protected void postRowExport(DataTable table, Object document) {
((PrintWriter) document).append("\t" + table.getVar() + "\n");
}

@Override
protected void exportCells(DataTable table, Object document) {
PrintWriter writer = (PrintWriter) document;
for (UIColumn col : table.getColumns()) {
if (col instanceof DynamicColumn) {
((DynamicColumn) col).applyStatelessModel();
}

if (col.isRendered() && col.isExportable()) {
String columnTag = getColumnTag(col);
addColumnValue(writer, col.getChildren(), columnTag, col);
}
}
}

protected String getColumnTag(UIColumn column) {
String headerText = (column.getExportHeaderValue() != null) ? column.getExportHeaderValue() : column.getHeaderText();
UIComponent facet = column.getFacet("header");
String columnTag;

if (headerText != null) {
columnTag = headerText.toLowerCase();
}
else if (facet != null) {
columnTag = exportValue(FacesContext.getCurrentInstance(), facet).toLowerCase();
}
else {
throw new FacesException("No suitable xml tag found for " + column);
}

return EscapeUtils.forXmlTag(columnTag);
}

protected void addColumnValue(PrintWriter writer, List<UIComponent> components, String tag, UIColumn column) {
FacesContext context = FacesContext.getCurrentInstance();

writer.append("\t\t" + tag + "");

if (column.getExportFunction() != null) {
writer.append(EscapeUtils.forXml(exportColumnByFunction(context, column)));
}
else {
for (UIComponent component : components) {
if (component.isRendered()) {
String value = exportValue(context, component);
if (value != null) {
writer.append(EscapeUtils.forXml(value));
}
}
}
}

writer.append("" + tag + "\n");
protected void exportCellValue(FacesContext context, DataTable table, UIColumn col, String text, int index) {
String columnTag = ExporterUtils.getColumnExportTag(context, col);
document.append("\t\t")
.append(columnTag)
.append(": ")
.append(EscapeUtils.forXml(text))
.append("\n");
}

@Override
Expand All @@ -169,5 +87,4 @@ public String getContentType() {
public String getFileExtension() {
return ".txt";
}

}
}
25 changes: 15 additions & 10 deletions src/main/java/org/primefaces/showcase/view/panel/DashboardView.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,24 +23,29 @@
*/
package org.primefaces.showcase.view.panel;

import java.io.Serializable;
import java.util.Arrays;

import jakarta.annotation.PostConstruct;
import jakarta.faces.application.FacesMessage;
import jakarta.faces.context.FacesContext;
import jakarta.faces.view.ViewScoped;
import jakarta.inject.Named;

import org.primefaces.event.CloseEvent;
import org.primefaces.event.DashboardReorderEvent;
import org.primefaces.event.ToggleEvent;
import org.primefaces.model.dashboard.*;
import org.primefaces.model.dashboard.DashboardModel;
import org.primefaces.model.dashboard.DashboardWidget;
import org.primefaces.model.dashboard.DefaultDashboardModel;
import org.primefaces.model.dashboard.DefaultDashboardWidget;

import java.io.Serial;
import java.io.Serializable;
import java.util.Arrays;
import java.util.List;

@Named
@ViewScoped
public class DashboardView implements Serializable {

@Serial
private static final long serialVersionUID = 1L;
private static final String RESPONSIVE_CLASS = "col-12 lg:col-6 xl:col-6";

Expand All @@ -58,17 +63,17 @@ public void init() {

// legacy
legacyModel = new DefaultDashboardModel();
legacyModel.addColumn(new DefaultDashboardColumn(Arrays.asList("sports", "finance")));
legacyModel.addColumn(new DefaultDashboardColumn(Arrays.asList("lifestyle", "weather")));
legacyModel.addColumn(new DefaultDashboardColumn(Arrays.asList("politics")));
legacyModel.addWidget(new DefaultDashboardWidget(Arrays.asList("sports", "finance")));
legacyModel.addWidget(new DefaultDashboardWidget(Arrays.asList("lifestyle", "weather")));
legacyModel.addWidget(new DefaultDashboardWidget(List.of("politics")));
}

public void handleReorder(DashboardReorderEvent event) {
FacesMessage message = new FacesMessage();
message.setSeverity(FacesMessage.SEVERITY_INFO);
message.setSummary("Reordered: " + event.getWidgetId());
String result = String.format("Dragged index: %d, Dropped Index: %d, Widget Index: %d",
event.getSenderColumnIndex(), event.getColumnIndex(), event.getItemIndex());
event.getSenderColumnIndex(), event.getColumnIndex(), event.getItemIndex());
message.setDetail(result);

addMessage(message);
Expand All @@ -92,7 +97,7 @@ public void handleToggle(ToggleEvent event) {
* Dashboard panel has been resized.
*
* @param widget the DashboardPanel
* @param size the new size CSS
* @param size the new size CSS
*/
public void onDashboardResize(final String widget, final String size) {
final DashboardWidget dashboard = responsiveModel.getWidget(widget);
Expand Down

0 comments on commit b267419

Please sign in to comment.