Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions dashboard-parent/dashboard-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@
<name>Wicketstuff Dashboard Core</name>

<dependencies>
<!-- Gson (json for java) -->
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
</dependency>

<!-- Xstream -->
<dependency>
<groupId>com.thoughtworks.xstream</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
requires org.apache.wicket.request;
requires org.apache.wicket.util;
requires xstream;
requires com.github.openjson;
requires com.google.gson;
requires de.agilecoders.wicket.webjars;
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@
import org.apache.wicket.ajax.attributes.AjaxRequestAttributes;
import org.wicketstuff.dashboard.WidgetLocation;

import com.github.openjson.JSONArray;
import com.github.openjson.JSONObject;
import com.google.gson.Gson;

/**
* @author Decebal Suiu
Expand All @@ -38,21 +37,54 @@ public abstract class SortableAjaxBehavior extends AbstractDefaultAjaxBehavior {
protected void updateAjaxAttributes(AjaxRequestAttributes attributes) {
super.updateAjaxAttributes(attributes);

attributes.getDynamicExtraParameters()
.add("var data = serializeWidgetLocations();" +
"return {'" + JSON_DATA + "': data};");
StringBuilder buffer = new StringBuilder();
buffer.append("var data = serializeWidgetLocations();");
buffer.append("return {'" + JSON_DATA + "': data};");

attributes.getDynamicExtraParameters().add(buffer);
}

@Override
protected void respond(AjaxRequestTarget target) {
Map<String, WidgetLocation> locations = new HashMap<String, WidgetLocation>();
String jsonData = getComponent().getRequest().getRequestParameters().getParameterValue(JSON_DATA).toString();
JSONArray arr = new JSONArray(jsonData);
for (int i = 0; i < arr.length(); ++i) {
JSONObject obj = arr.getJSONObject(i);
locations.put(obj.getString("widget"),
new WidgetLocation(obj.getInt("column"), obj.getInt("sortIndex")));
Item[] items = getItems(jsonData);
Map<String, WidgetLocation> locations = new HashMap<String, WidgetLocation>();
for (Item item : items) {
WidgetLocation location = new WidgetLocation(item.column, item.sortIndex);
locations.put(item.widget, location);
}

onSort(target, locations);
}

private Item[] getItems(String jsonData) {
Gson gson = new Gson();
Item[] items = gson.fromJson(jsonData, Item[].class);
/*
System.out.println(items.length);
for (Item item : items) {
System.out.println(item);
}
*/

return items;
}

static class Item {
public int column;
public String widget;
public int sortIndex;

@Override
public String toString() {
StringBuffer buffer = new StringBuffer();
buffer.append("Item[");
buffer.append("column = ").append(column);
buffer.append(" widget = ").append(widget);
buffer.append(" sortIndex = ").append(sortIndex);
buffer.append("]");

return buffer.toString();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import org.wicketstuff.dashboard.web.DashboardPanel;
import org.wicketstuff.dashboard.web.WidgetView;

class AbstractWidgetTest {
public class AbstractWidgetTest {
private static final String MARKUP = "<html><body><div wicket:id=\"dashboard\"></div></body></html>";
private WicketTester browser;

Expand Down Expand Up @@ -96,12 +96,12 @@ public WidgetView createView(String viewId) {
}

@BeforeEach
void setup() {
public void setup() {
browser = new WicketTester(new WebApp());
}

@Test
void canExposeConfigurationAsString() {
public void canExposeConfigurationAsString() {
Dashboard dashboard = Application.get().getMetaData(DASHBOARD_KEY);
browser.startComponentInPage(new DashboardPanel("dashboard", Model.<Dashboard> of(dashboard)), Markup.of(MARKUP));
browser.assertNoErrorMessage();
Expand Down
20 changes: 18 additions & 2 deletions jasperreports-parent/jasperreports-examples/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<description>JasperReports integration components and resources for Wicket.</description>

<properties>
<jasperreports.outputDirectory>${project.build.sourceDirectory}/../webapp/reports</jasperreports.outputDirectory>
<jasperreportsDirectory>${project.build.directory}/reports</jasperreportsDirectory>
<javadoc.disabled>true</javadoc.disabled>
<deployment.disabled>true</deployment.disabled>
<sources.disabled>true</sources.disabled>
Expand Down Expand Up @@ -62,6 +62,22 @@
<groupId>org.slf4j</groupId>
<artifactId>slf4j-reload4j</artifactId>
</dependency>

</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<configuration>
<systemProperties>
<jasperreportsDirectory>${jasperreportsDirectory}</jasperreportsDirectory>
</systemProperties>
<resourceBases>
<resourceBase>src/main/webapp</resourceBase>
<resourceBase>${jasperreportsDirectory}</resourceBase>
</resourceBases>
</configuration>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
/*
* $Id$
* $Revision$ $Date$
*
*
* ==================================================================== Licensed
* under the Apache License, Version 2.0 (the "License"); you may not use this
* file except in compliance with the License. You may obtain a copy of the
* License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
Expand All @@ -17,40 +17,61 @@
*/
package org.wicketstuff.jasperreports.examples;

import java.io.File;
import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.StandardCopyOption;
import java.time.Duration;

import org.apache.wicket.Page;
import org.apache.wicket.protocol.http.WebApplication;

/**
* Wicket application class for jasper reports example.
*
*
* @author Eelco Hillenius
*/
public class JasperReportsApplication extends WebApplication
{
public class JasperReportsApplication extends WebApplication {
/**
* Constructor.
*/
public JasperReportsApplication()
{
public JasperReportsApplication() {
}

/**
* @see org.apache.wicket.protocol.http.WebApplication#init()
*/
@Override
protected void init()
{
protected void init() {
getCspSettings().blocking().disabled();
getResourceSettings().setResourcePollFrequency(Duration.ofSeconds(1));

final File base = new File(System.getProperty("jasperreportsDirectory"));
final File reportFile = new File(base, "WebappReport.jasper");
try {
if (!base.exists()) {
base.mkdirs();
}
try (InputStream rep = getClass().getResourceAsStream("/jasperreports/WebappReport.jasper")) {
Files.copy(rep, reportFile.toPath(), StandardCopyOption.REPLACE_EXISTING);
}
final File images = new File(base, "../images");
if (!images.exists()) {
images.mkdirs();
}
try (InputStream rep = getClass().getResourceAsStream("/jasperreports/jasperreports.gif")) {
Files.copy(rep, new File(images, "jasperreports.gif").toPath(), StandardCopyOption.REPLACE_EXISTING);
}
} catch (Exception e) {
throw new RuntimeException(e);
}
}

/**
* @see org.apache.wicket.Application#getHomePage()
*/
@Override
public Class<? extends Page> getHomePage()
{
public Class<? extends Page> getHomePage() {
return Index.class;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
<li>
<a href="#" wicket:id="linkToCsv">display CSV report</a>
</li>
<li>
<a href="#" wicket:id="linkToXls">display XLS report</a>
</li>
</ul>
</div>
<div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,11 @@
*/
package org.wicketstuff.jasperreports.examples;

import jakarta.servlet.ServletContext;

import java.io.File;
import java.util.HashMap;
import java.util.Map;

import org.apache.wicket.markup.html.WebPage;
import org.apache.wicket.markup.html.link.ResourceLink;
import org.apache.wicket.protocol.http.WebApplication;
import org.wicketstuff.jasperreports.JRConcreteResource;
import org.wicketstuff.jasperreports.JRImageResource;
import org.wicketstuff.jasperreports.JRResource;
Expand All @@ -29,63 +25,65 @@
import org.wicketstuff.jasperreports.handlers.PdfResourceHandler;
import org.wicketstuff.jasperreports.handlers.RtfResourceHandler;
import org.wicketstuff.jasperreports.handlers.TextResourceHandler;
import org.wicketstuff.jasperreports.handlers.XlsResourceHandler;

/**
* Simple Jasper reports example with PDF output and a jasper reports panel..
*
*
* @author Eelco Hillenius
*/
public class ReportLinksPage extends WebPage
{
public class ReportLinksPage extends WebPage {
private static final long serialVersionUID = 1L;

/**
* Constructor.
*/
public ReportLinksPage()
{
ServletContext context = ((WebApplication)getApplication()).getServletContext();
final File reportFile = new File(context.getRealPath("/reports/WebappReport.jasper"));
public ReportLinksPage() {
final File base = new File(System.getProperty("jasperreportsDirectory"));
final File reportFile = new File(base, "WebappReport.jasper");

final Map<String, Object> parameters = new HashMap<String, Object>();
parameters.put("BaseDir", new File(context.getRealPath("/reports")));
final Map<String, Object> parameters = Map.of("BaseDir", base);

JRResource pdfResource = new JRConcreteResource<PdfResourceHandler>(reportFile,
new PdfResourceHandler()).setReportParameters(parameters).setReportDataSource(
new WebappDataSource());
new PdfResourceHandler()).setReportParameters(parameters).setReportDataSource(
new WebappDataSource());
add(new ResourceLink<Void>("linkToPdf", pdfResource));

JRResource rtfResource = new JRConcreteResource<RtfResourceHandler>(reportFile,
new RtfResourceHandler()).setReportParameters(parameters).setReportDataSource(
new WebappDataSource());
new RtfResourceHandler()).setReportParameters(parameters).setReportDataSource(
new WebappDataSource());
add(new ResourceLink<Void>("linkToRtf", rtfResource));

JRResource htmlResource = new JRConcreteResource<HtmlResourceHandler>(reportFile,
new HtmlResourceHandler()).setReportParameters(parameters).setReportDataSource(
new WebappDataSource());
new HtmlResourceHandler()).setReportParameters(parameters).setReportDataSource(
new WebappDataSource());
add(new ResourceLink<Void>("linkToHtml", htmlResource));

JRResource textResource = new JRConcreteResource<TextResourceHandler>(reportFile,
new TextResourceHandler()).setReportParameters(parameters).setReportDataSource(
new WebappDataSource());
new TextResourceHandler()).setReportParameters(parameters).setReportDataSource(
new WebappDataSource());
add(new ResourceLink<Void>("linkToText", textResource));

JRResource imageResource = new JRImageResource(reportFile).setReportParameters(parameters)
.setReportDataSource(new WebappDataSource());
.setReportDataSource(new WebappDataSource());
add(new ResourceLink<Void>("linkToImage", imageResource));

JRResource csvResource = new JRConcreteResource<CsvResourceHandler>(reportFile,
new CsvResourceHandler()).setReportParameters(parameters).setReportDataSource(
new WebappDataSource());
new CsvResourceHandler()).setReportParameters(parameters).setReportDataSource(
new WebappDataSource());
add(new ResourceLink<Void>("linkToCsv", csvResource));

JRResource xlsResource = new JRConcreteResource<XlsResourceHandler>(reportFile,
new XlsResourceHandler()).setReportParameters(parameters).setReportDataSource(
new WebappDataSource());
add(new ResourceLink<Void>("linkToXls", xlsResource));
}

/**
* @see org.apache.wicket.Component#isVersioned()
*/
@Override
public boolean isVersioned()
{
public boolean isVersioned() {
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,19 @@
xml:lang="en" lang="en">
<head>
<title>WicketStuff JasperReports Integration - Embedded PDF</title>
<style>
object {
width: 85vw;
height: 85vh;
display: block;
}
</style>
</head>
<body>
<div>
Before
<br />

<object wicket:id="report" height="60%" width="80%"></object>

<object wicket:id="report"></object>
<br />
After
</div>
Expand Down
Loading