I have a invoice for which I want to show in preview mode with a watermark. I have integrated the report with my web application (Spring MVC).
Any solution?
EDIT: I want to pick a value from a dataset (Table: invoiceheader), and use that value to decide whether to show /not show the watermark. I am unable to pick that value from Birt script. Can you please please guide..
Sorry .. the customer asked for a different way of identifying the fact rather that from passing the parameter.
Thanks
You need to declare a report parameter in the .rptdesign of the invoice. For example we name it "useWatermark", and we set the datatype to boolean and a default value to true.
Select the report root in the outline view of the designer -> script tab -> beforeFactory
if (!params["useWatermark"].value){
reportContext.getDesignHandle().findMasterPage("Simple MasterPage").setProperty("backgroundImage", "");
}
This script removes the watermark if the parameter is set to false. By default, the master page is named "Simple Masterpage" but if you have renamed it or if there are multiple masterPages defined in the report you should adjust the script consequently.
EDIT: if we need to extract the information from a dataset, then we can't make use of the masterPage, we have to use a grid instead.
Create a grid with one cell, and drop all the content of your page into it
Set your watermark as background-image of the grid
Create a report variable "useWatermark" in the "Outline/variables" branch (see picture below), set default value to true/false as you like
Select dataset invoiceHeader -> script tab -> onFetch, and affect the variable from a boolean dataset column, or from any expression returning true/false:
vars["useWatermark"]=row["myBooleanDatasetColumn"];
This dataset must be used somewhere in the report body, otherwise it won't be triggered and the variable won't be initialized
Select the grid -> script tab -> onRender
if (!vars["useWatermark"]){
this.getStyle().backgroundImage="";
}
Related
I am trying to automate text field using selenium, when I try to inspect the object its not showing in dev tools
-text fields-
Industry : CGS-AGRIBUSINESS,
Client NAME : AB VOLVO
text name(Industry) I can see in dev tools but the text value not visible(CGS-AGRIBUSINESS), I want to verify the text ex : AB VOLVO, whether it is present or not
enter image description here
Open your Chrome devtools, and navigate to a tab called Properties. See the screenshot below.
In that tab, see if there is a property called value. I think you will be able to see the text that you want to verify CGS-AGRIBUSINESS in that value.
Now to retrieve the text from the value attribute, just use the getAttribute method to get the attribute value.
Here is a rough syntax
driver.findElement(your_xpath_or_any_locator_here).getAttribute('value')
This has already been explained in this SO question.
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 am trying to create a small application where I have various file locations stored in a Vaadin grid, the grid currently only shows two columns - ID and File Name, and I would like to see as a notification the file location too whenever I click on a row.
Meaning, every time I click a row from the grid I would like it to show me the location, using Notification.show(), like that:
(Please ignore the <b></b>s, they are irrelevant.)
As my grids selection model is MULTI, per default the click listener cannot register which row it is clicked on and selecting the row via checkbox is not what I want to have the data displayed. Simply, I would like to get the item for every row I click and have the location displayed as a notification.
So far, I found a solution for a similar issue but it deals with columns and the rows in Vaadin grids are rather different from what I am used to.
public static <T> void addColumnClickListener(Grid<T> grid, Consumer<Column<T>> listener)
{
String expression = "function(){const col=element.getEventContext(event).column;return col ? col.id : '';}()";
grid.getElement().addEventListener("click", e ->
{
String colId = e.getEventData().getString(expression);
Optional<Column<T>> column = grid.getColumns().stream().filter(col -> colId.equals(col.getId().get())).findFirst();
column.ifPresent(listener);
}
).addEventData(expression);
}
And I am to call the function like that:
addColumnClickListener(grid, column -> Notification.show("fubar"));
This code snippet is from the Vaadin forums and I do not quite understand it. The string expression seems to be that it contains possible JavaScript code and the rest overrides the type of the column. (I think, I really do not understand this snippet fully)
Is there any way to do something similar to the snippet above but for rows?
You can do this with an ItemClickListener on the Grid:
grid.addItemClickListener(item -> {
Notification.show(String.format("File location: %s", item.getLocation()));
});
how to display value of content in object in Java? I always get something like: org.springframework.ws.soap.security.xwss.XwsSecurityInterceptor#1a28aef12019-10-13
#Bean
public XwsSecurityInterceptor securityInterceptor() {
XwsSecurityInterceptor securityInterceptor = new XwsSecurityInterceptor();
securityInterceptor.setPolicyConfiguration(new ClassPathResource("securityPolicy.xml"));
securityInterceptor.setCallbackHandler(callback());
System.out.print("toStringBean: "+securityInterceptor.toString());
//Security Policy -> securityPolicy.xml
return securityInterceptor;
}
I read that I should use toString() but I get same result. I just need value of properties inside object :)
You cannot read the properties of XwsSecurityInterceptor using toString method as it is not overridden in the class from Object class.If you want to see the value you better put a debug point in the class and inspect the values and run the application in Debug mode.
For Debug in intellij.
click on the bug button in below screenshot. For adding the dubug point just single click on line number. then a red dot appears on the line number. When you run the application. You can see execution stops at the point. Then right click on the variable and select Evaluate Expression and a popup opens. Just click on the evaluate button in the popup and you can see the different value of objects present in the class.
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)