For building a workaround, I'd like to know if it's possible to push/unpush a PD(Push)Button with pdfbox 2.0.12 or later.
PDButton pdButton = (PDButton) field;
pdButton.setValue("pushed");
Is there a certain value that can be used to push/unpush the button?
I'm aware that this should rather be solved with a PDCheckBox, but as most of our PDF-templates use buttons rather than checkboxes to display checkboxes I'd like to ease the migration of those files.
Update 1
As suggested in the comments I tried setting the button to one, but that leads to an IllegalStateException.
Code
PDButton btn = (PDButton) field;
btn.setValue("1");
Exception
Caused by: java.lang.IllegalStateException
at org.apache.pdfbox.pdmodel.interactive.annotation.PDAppearanceEntry.getSubDictionary(PDAppearanceEntry.java:97)
at org.apache.pdfbox.pdmodel.interactive.form.PDButton.getOnValueForWidget(PDButton.java:348)
at org.apache.pdfbox.pdmodel.interactive.form.PDButton.getOnValues(PDButton.java:319)
at org.apache.pdfbox.pdmodel.interactive.form.PDButton.checkValue(PDButton.java:370)
at org.apache.pdfbox.pdmodel.interactive.form.PDButton.setValue(PDButton.java:157)
Update 2
Not possible. Only checkboxes can be checked/unchecked. We'll fix our PDF templates.
Related
Im pretty pretty new to Dynamic-Jasper, but due to work i had to add a new feature to our already implemented solution.
My Problem
The Goal is to add a Column to a report that consists only out of a background-color based on some Information. I managed to do that, but while testing I stumbled upon a Problem. While all my Columns in the html and pdf view had the right color, the Excel one only colored the fields in the last Color.
While debugging i noticed, that the same colored Fields had the same templateId, but while all Views run through mostly the same Code the Excel one showed different behavior and had the same ID in all fields.
My Code where I manipulate the template
for(JRPrintElement elemt : jasperPrint.getPages().get(0).getElements()) {
if(elemt instanceof JRTemplatePrintText) {
JRTemplatePrintText text = (JRTemplatePrintText) elemt;
(...)
if (text.getFullText().startsWith("COLOR_IDENTIFIER")) {
String marker = text.getFullText().substring(text.getFullText().indexOf('#') + 1);
text.setText("ID = " + ((JRTemplatePrintText) elemt).getTemplate().getId());
int rgb = TypeConverter.string2int(Integer.parseInt(marker, 16) + "", 0);
((JRTemplatePrintText) elemt).getTemplate().setBackcolor(new Color(rgb));
}
}
}
The html view
The Excel view
Temporary Conclusion
The same styles uses the same Objects in the background and the JR-Excel export messes something up by assigning the same Object to all the Fields that I manipulated there. If anyone knows of a misstake by me or potential Solutions to change something different to result the same thing please let me know.
Something different I tried earlier, was trying to set the field in an evaluate Method that was called by Jasper. In that method we assign the textvalue of each field. It contained a map with JRFillFields, but unfortunatelly the Map-Implementation denied access to them and just retuned the Value of those. The map was provided by dj and couldn't be switched with a different one.
Edit
We are using JasperReports 6.7.1
I found a Solution, where I replaced each template with a new one that was supposed to look exactly alike. That way every Field has its own ID guaranteed and its not up to chance, how JasperReports handles its Data internaly.
JRTemplateElement custom =
new JRTemplateText(((JRTemplatePrintText) elemt).getTemplate().getOrigin(),
((JRTemplatePrintText) elemt).getTemplate().getDefaultStyleProvider());
custom.setBackcolor(new Color(rgb));
custom.setStyle(((JRTemplatePrintText) elemt).getTemplate().getStyle());
((JRTemplatePrintText) elemt).setTemplate(custom);
I tried to add an overlay plugin. https://vaadin.com/directory/component/overlays
I have a problem with image overlay. Im getting that error:
The type com.vaadin.terminal.Resource cannot be resolved.
It is indirectly referenced from required .class file
problem is with this line:
io.setImage(res);
how can I fix it? I put icon-new.png to the class package folder and added into maven overlays plugin
My code:
final ImageOverlay io = new ImageOverlay(button);
Resource res = new ClassResource(this.getClass(), "../icon-new.png");
io.setImage(res);
io.setComponentAnchor(Alignment.TOP_LEFT); // Top left of the button
io.setOverlayAnchor(Alignment.MIDDLE_CENTER); // Center of the image
io.setClickListener(new OverlayClickListener() {
public void overlayClicked(CustomClickableOverlay overlay) {
Notification.show("ImageOverlay Clicked!");
}
});
layout.addComponent(io);
io.setEnabled(true);
I need to achive that on the button will show up an overlay. If the user clicked on this button and added a new content something like taht show up on the button
That's because it's compatible with Vaadin 6 only as it's indicated in the add-on page:
If you scroll to the comments section, someone is suggesting a fork of the add-on compatible with Vaadin 7, but I could not see anything related to 8:
HI ALL! You can find version 1.1.3 for Vaadin 7.6 here: https://github.com/Haulmont/vaadin-overlays/releases
YURIY ARTAMONOV
Add-ons that are compatible with multiple Vaadin versions, indicate this explicitly, and usually (but not necessarily... dev's choice) have different version numbering, eg: 1.x for Vaadin 6, 2.x For Vaadin 7, 3.x for Vaadin 8, etc:
Either way, clicking on the link for a specific Vaadin version, will select the latest add-on release compatible with it. Or, if you select an add-on release from the drop-down, the Vaadin version compatible with it will be updated accordingly.
Edit after update
You can use a regular button + the predefined BUTTON_ICON_ALIGN_RIGHT Valo style. From the javadoc:
/**
* Align the icon to the right side of the button caption. Can be combined
* with any other Button style.
*/
public static final String BUTTON_ICON_ALIGN_RIGHT = "icon-align-right";
Please note that for the best UI result, I've used 24x24 icons, but depending on your requirements you can tweak your theme for the size you need. Also if you don't have icons and don't want to spend money or time buying or creating your own icons, you can use the existing Vaadin Font Icons (list of icons and matching java enum)
public class ButtonWithIconOnTheRightComponent extends VerticalLayout {
public ButtonWithIconOnTheRightComponent() {
// text filed to specify icon URL
TextField urlField = new TextField("Icon URL", "http://files.softicons.com/download/toolbar-icons/status-icons-set-by-iconleak/png/16x16/30.png");
// button which updates its icon using the URL specified in the text field above
Button button = new Button("Update icon", event -> event.getButton().setIcon(new ExternalResource(urlField.getValue())));
// use valo style to align icon to the right
button.addStyleName(ValoTheme.BUTTON_ICON_ALIGN_RIGHT);
// add components to the UI
addComponents(urlField, button);
setSpacing(true);
}
}
I would like to make .txt-files accessible for my VaadinApp on a GlassfishServer.
Lets say I have a .txt-file, its content is 12345.
Now, when I click a button on my Vaadin StartPage, I would like to show the Data that has been written into this .txt-file.
I know how Java Input/Output is working but I have no clue how to make those files accessible for my VaadinApplication running on Glassfish 4.1.2.
Is there a folder I can put the .txt-file in, or how would I access the file?
Thanks
There is component named Label is available in Vaadin.
So that, the values which needs to be shown on the screen can be set as a caption/value for that object.
This can be done either through constructor or setter in that object.We will set the value through the setter as we need to display the value, once the button is clicked. That can be done like this.
Label sampleLabel = new Label();
sampleLabel.setContentMode(com.vaadin.shared.ui.ContentMode.HTML);
Now we will see how this can be added to the label, when a button is clicked.
Button sampleButton = new Button("Click");
sampleButton.addClickListener(event -> sampleLabel.setValue(<call the method that reads data from the text file>));
I hope this will be helpful.
Note: Basically you can place the file anywhere in the system.
But most preferred way.
If you are using maven to build the project, place the files in the resource folder.(src/main/resources)
I am trying to limit the number of rows that a user can add in an ajaxformloop.
Short example:
For example, the loop found in the tapestry 5 documentation here: http://tapestry.apache.org/5.3/apidocs/org/apache/tapestry5/corelib/components/AjaxFormLoop.html
If for example I would only like the user to be able to enter 3 phone numbers, how can that be done?
What I have tried:
1) I tried returning null from the onAddRow event, this causes an exception and the exception report page to display - these events shouldn't return null I don't think.
2) I tried adding my own add row button like this:
<p:addRow>
<t:addrowlink>Add another</t:addrowlink>
</p:addRow>
And then putting a t:if around it, like this:
<t:if test="canAddMorePhones()">
<p:addRow>
<t:addrowlink>Add another</t:addrowlink>
</p:addRow>
</t:if>
In this case, the "add another" reverts to the default "Add row" button and my add row link doesn't show.
3)I tried moving that t:if inside the , this had similar results.
--------------------------
I am sure that this is a fairly common aim, is there any simple way to do it? Perhaps someone can provide an example, and if possible this can help to go in the documentation as i'm sure i'm not going to be the only one trying to do this.
Note: I did also ask on the T5 users mailing list and had one answer but I can't seem to get it working after the response from Lance (Which I am sure is probably correct, but i'm not sure how to use the AjaxResponseRenderer as per my reply last week, this is probably due to my own technical limitations or understanding of some parts of T5).
http://apache-tapestry-mailing-list-archives.1045711.n5.nabble.com/Ajaxformloop-add-row-link-max-size-tt5730840.html
I also tried using ajaxResponseRenderer.addRender as you did in your mailing list code, but it doesn't work because it seems that Tapestry has some problems dealing with updating a component that's busy updating another component. However, AjaxResponseRenderer also supports execution of JavaScript. Taking this approach on the AjaxFormLoop example in the docs, specify the addrowlink as follows:
<p:addrow>
<t:if test="canAddMorePhones()">
<t:addrowlink id="addRowLink" t:id="addRowLink">Add another</t:addrowlink>
</t:if>
</p:addrow>
Then add the following code right before return phone; in onAddRowFromPhones():
ajaxResponseRenderer.addCallback(new JavaScriptCallback() {
public void run(JavaScriptSupport javascriptSupport) {
if (!canAddMorePhones()) {
javascriptSupport.addScript("document.getElementById('addRowLink').style.display = 'none';");
}
}
});
This example was tested successfully in Tapestry 5.3.7.
Here's the fact : I made a tiny app which consist of a table related to a bar chart (a birt one ... of course), when I modify my table values it automaticaly alter my chart (like Excel but less fancy) ...
Anyway everything works fine ... BUT when I want to make my chart interactive in order to show tooltips (for example) I inform naturaly my
IDeviceRenderer
whit the following command
idr.setProperty( IDeviceRenderer.UPDATE_NOTIFIER, this );
but doing so brings an error when (much later) my code come to
gr.render(idr, gr.build(idr.getDisplayServer(), this.chart, bo, vroum,null));
(Which have never failed before) ...
I feel lost ...
ps:
The error I get are that I get no bars to my chart and receive the following error message :
org.eclipse.birt.chart.exception.ChartException
at org.eclipse.birt.chart.factory.Generator.render(Generator.java:1373)
at clickable.chart.ClickableProto.paintControl(ClickableProto.java:520)
at org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListener.java:217)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1003)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1027)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1012)
at org.eclipse.swt.widgets.Composite.WM_PAINT(Composite.java:1424)
at org.eclipse.swt.widgets.Control.windowProc(Control.java:3842)
at org.eclipse.swt.widgets.Canvas.windowProc(Canvas.java:337)
at org.eclipse.swt.widgets.Display.windowProc(Display.java:4541)
at org.eclipse.swt.internal.win32.OS.DispatchMessageW(Native Method)
at org.eclipse.swt.internal.win32.OS.DispatchMessage(OS.java:2371)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3420)
at clickable.chart.ClickableProto.main(ClickableProto.java:151)
Caused by: java.lang.NullPointerException
at org.eclipse.birt.chart.render.InteractiveRenderer.isColoredByCategories(InteractiveRenderer.java:197)
at org.eclipse.birt.chart.render.InteractiveRenderer.getSource(InteractiveRenderer.java:161)
at org.eclipse.birt.chart.render.InteractiveRenderer.modifyEvent(InteractiveRenderer.java:116)
at org.eclipse.birt.chart.device.swt.SwtRendererImpl.fillPolygon(SwtRendererImpl.java:502)
at org.eclipse.birt.chart.event.PolygonRenderEvent.fill(PolygonRenderEvent.java:156)
at org.eclipse.birt.chart.render.DeferredCache.flushPlanes(DeferredCache.java:499)
at org.eclipse.birt.chart.render.DeferredCache.flushOptions(DeferredCache.java:271)
at org.eclipse.birt.chart.render.DeferredCacheManager.flushOptions(DeferredCacheManager.java:165)
at org.eclipse.birt.chart.render.AxesRenderer.flushClipping(AxesRenderer.java:3416)
at org.eclipse.birt.chart.render.AxesRenderer.restoreClipping(AxesRenderer.java:3401)
at org.eclipse.birt.chart.render.Bar.renderSeries(Bar.java:1533)
at org.eclipse.birt.chart.render.AxesRenderer.renderPlot(AxesRenderer.java:2181)
at org.eclipse.birt.chart.render.AxesRenderer.render(AxesRenderer.java:314)
at org.eclipse.birt.chart.factory.Generator.render(Generator.java:1368)
... 14 more
I am open to any idea !
Finally I managed it on my own ...
So here are some common mistakes not to make when you make a chart on BIRT and wnat it to be interactive ...
1 Implement barely anything which need to be overriden
I personnaly forgot to override
getDesignTimeModel()
and
getRunTimeModel()
comming with the ICallBackNotifier implementation ...
2 Do not nest your chart (or be prepared to nest most of your methods too)
I had my chart not directly on my shell but nested in a bunch of composites widgets, canvas and such ... Therefore my canvas where hidding my shell which was the only one able to react in the way I wanted to my mouse controller.
(Funny fact : I figured this all out when I (for no reason) tried to drag a small part of my shell which was not overlapped by the chart and drop it on my bars ... There the tooltip poped ... ^^ Funny way to understand how things work :p)
3 Do not be me ...
It is to much work and pain for a barely acceptable result ;p
Hope this help, dont hesitate to mail me if you face the same probleme, I'd be glad to help as much as I can ^^