iReport and external objects - java

I am trying to use an external objects in my report.
I added the jar file with external objects to iReport classpath (in settings)
The static text (with I18n)
msg($R{pdf.invoice.finalTitle}, $P{invoice.number})
I have added such definitions into xml:
<import value="crm.object.objects.Invoice"/>
<parameter name="invoice" class="crm.object.objects.Invoice" isForPrompting="false">
<property name="number" value=""/>
<defaultValueExpression><![CDATA[]]></defaultValueExpression>
</parameter>
...
But still it fails during compilation with error: net.sf.jasperreports.engine.design.JRValidationException: Report design not valid :       1. Parameter not found : invoice.number
What I am doing wrong?
Thank you

The parameter you have defined is "invoice", not "invoice.number". So, it should be $P{invoice}. You can then access it's variable, if it has enough access privileges...or by it's getter, as $P{invoice}.getNumber()

Related

javax.validation.ValidationException: %class% has already be configured in xml

There's a bean validation in a project's jar which validation.xml contains field-level validation of Address bean.
The other project uses Address class and needs to have specific Address validation. So extended-validation.xml was created with class-level validation of Address bean.
As a result, during the app deployment, ValidationException occures: javax.validation.ValidationException: my.base.datatypes.Address has already be configured in xml..
Here are two validation xml files with basic validation and "extended validation".
validation.xml
<bean class="my.base.datatypes.Address" ignore-annotations="true">
<getter name="country">
<constraint annotation="my.imp.services.validation.ValidCode">
<message>{msg01}</message>
<groups>
<value>my.imp.services.validation.ImportGroup</value>
</groups>
<element name="name">Country</element>
</constraint>
</getter>
</bean>
extended-validation.xml
<bean class="my.base.datatypes.Address" ignore-annotations="true">
<class ignore-annotations="true">
<constraint annotation="my.extended.imp.services.validation.ValidAddress">
<message>ERROR DURING ADDRESS VALIDATION</message>
<groups>
<value>my.imp.services.validation.ImportGroup</value>
</groups>
</constraint>
</class>
</bean>
Is it possible to extend already existing validation?
The solution appears to be very simple and trivial. If you want to extend validation rules, use different validator which will load extended-validation.xml constraints configuration. In this case, base validator validates data according to validation.xml config, and another validator validates data according to extended-validation.xml config. So no more config collisions occur.

How to set VM parameters from Spring with value from .properties? [duplicate]

One of our team has implemented loading properties this way (see pseudo code below) and advises this approach is right as the client application using this is free to keep the properties in any file. Contrary to the widely used propertyplaceholderconfigurer.
application-context.xml
<bean class="com.mypackage.Myclass">
<property name="xml" value="classpath:"{com.myapp.myproperty1}"> </property>
</bean>
config.properties
com.myapp.myproperty1=data.xml
edit: I should have added it is data.properties and not data.xml. We want to load a property file (this property file is given in the config.properties as a "property".
com.myapp.myproperty1=data.properties
java class
import org.springframework.core.io.Resource;
public class Myclass {
private Resource xmlField;
// setter & getter methods..
}
Is it right to use spring core.io.Resource?
Another reason is the client application wants to load a environment specific configuration. I suggested use the propertyconfigurer and use maven profiles to generate the environment specific build
Can you please advise which one suits which case? and if it differs in different scenarios, please help me point out them?
thanks
You can put the properties in any file and still use PropertyPlaceholderConfigurer. Here's an example that satisfies both your coworker's concerns and your desire for environment specific stuff:
<bean id="propertyPlaceholderConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<!-- default settings -->
<value>classpath:MyCompany.properties</value>
<!-- environment-specific settings -->
<value>classpath:MyCompany.${mycompany.env:dev}.properties</value>
<!-- keep your coworker happy -->
<value>classpath:${mycoworker}</value>
<!-- allows emergency reconfiguration via the local file system -->
<value>file:///${user.home}/MyCompany.properties</value>
</list>
</property>
<property name="systemPropertiesModeName" value="SYSTEM_PROPERTIES_MODE_OVERRIDE"/>
<property name="ignoreResourceNotFound" value="true" />
<!-- should be validated separately, in case users of the library load additional properties -->
<property name="ignoreUnresolvablePlaceholders" value="false"/>
</bean>
If you pass in no -D arguments, then you'll pick up the following properties files, where properties in the later files overwrite previously determined values.
MyCompany.properties off the classpath
MyCompany.dev.properties off the classpath
$HOME/MyCompany.properties if it exists
To swap in a production config for #2, just pass -Dmycompany.env=prod to java. Similarly your coworker can pass -Dmycoworker=/some/path/config.properties if he/she wants.
I'm not sure why a PropertyPlaceholderConfigurator wouldn't have been the correct choice.
I've almost always handled environment-specific configs via a customized PPC that can either (a) get a -D parameter on startup, and/or (b) use the machine name, to decide which property file to load.
For me, this is more convenient than bundling the information in via Maven, since I can more easily test arbitrary configurations from whatever machine I'm on (using a -D property).
+1 for Dave's suggestion. You should be using PropertyPlaceholderConfigurer for loading\reading properties. Here is the example i just pulled out from my previous project if you wonder how to use this. This example is for loading multiple properties files but the concept is same. Good luck.
<bean id="projectProperties" class="org.springframework.beans.factory.config.PropertiesFactoryBean">
<property name="locations">
<list>
<value>classpath:config.properties</value>
</list>
</property>
</bean>
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="properties" ref="projectProperties" />
</bean>
<bean id="uniqueAssetIdRetriever" class="com.mypackage.Myclass">
<property name="xml" value="${com.myapp.myproperty1}" />
</bean>

Entity unable to generate within component tag of hibernate

The code is as follows:
I want to generate an entity class TermData which is present within the component class, but I'm unable to do that. TermData isn't generated.
<component name="term_" class="Term">
<meta attribute="generated-class" inherit="false">TermData</meta>
<meta attribute="extends">Entity</meta>
<meta attribute="scope-set" inherit="false">protected</meta>
<property name="duration_" column="DURATION" type="int" />
<property name="durationUnits_" column="DURATION_UNITS" type="string" length="64" />
</component>
I'm using hibernate-3.2.6.GA.jar, hibernate-tools-3.2.3.GA.jar with Java 8 and Ant 1.9
Got the problem...there was other component of class class="Term" written in different hbm file which was causing the problem as the genearted-class for that was "Dummy"...so once i changed generated-class at both places as same...it fixed my problem...may be it was due to the order in which it was being processed....as it already generated a component of same class , so it didn't generate the other one.

How to use a Glade UI (.glade file) in a Java Gnome/GTK program?

I've did a research on the Internet looking for tutorials/documentations to explain me how to use a UI designed in Glade in a Java Gnome project, but no luck. I already know how to create a UI from the code using the Java Gnome/GTK. Anyway, I'd like to use a Glade UI that I've created in a Java Gnome/Gtk project, but I have no idea from where to start. Please tell me:
which packages I need to install;
how to integrate the UI I've create with Glade (the .glade file) with my Java Gnome/Gtk project (specifically in Eclipse);
and give an example.
Thanks in advance.
That's how my Glade UI looks (Just click the image to see it bigger):
This is the XML code of the UI above:
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<!-- interface-requires gtk+ 3.0 -->
<object class="GtkWindow" id="window1">
<property name="can_focus">False</property>
<property name="window_position">center</property>
<child>
<object class="GtkFixed" id="fixed1">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<object class="GtkEntry" id="entry1">
<property name="width_request">162</property>
<property name="height_request">25</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="halign">start</property>
<property name="valign">end</property>
<property name="invisible_char">•</property>
</object>
<packing>
<property name="x">11</property>
<property name="y">49</property>
</packing>
</child>
<child>
<object class="GtkEntry" id="entry2">
<property name="width_request">162</property>
<property name="height_request">25</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="halign">start</property>
<property name="valign">end</property>
<property name="invisible_char">•</property>
<property name="invisible_char_set">True</property>
</object>
<packing>
<property name="x">271</property>
<property name="y">49</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="label">
<property name="height_request">25</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">*</property>
</object>
<packing>
<property name="x">216</property>
<property name="y">49</property>
</packing>
</child>
<child>
<object class="GtkButton" id="button">
<property name="label" translatable="yes">Calculate!!!</property>
<property name="use_action_appearance">False</property>
<property name="width_request">84</property>
<property name="height_request">27</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="use_action_appearance">False</property>
</object>
<packing>
<property name="x">181</property>
<property name="y">93</property>
</packing>
</child>
</object>
</child>
</object>
</interface>
Ok, you need to:
Init GTK library
Create a Builder object
Retrieve the window widget
Display the window widget
I assume you have already installed the java-gnome library in your Linux system and imported the jar in your eclipse project (project properties - java build path - add external jars - /usr/share/java/gtk.jar).
A sample code:
Gtk.init(args); //Init library
Builder b = new Builder(); //Create builder
b.addFromFile("filename.glade"); //Load layout from file
Window w = (Window) b.getObject("myWindowName"); //Retrieve an object
w.showAll(); //Show window
Gtk.main();
This is the way it should work. If you want to set a listener on an object, e.g. a button, you retrieve the oject by name as seen before with the window and then:
button.connect(new Clicked() {
#Override
public void onClicked(Button arg0) {
// Do what you want
}
});
Is it working for you? Well, it's not for me.
The problem was my code was throwing an exception when calling Builder.addFromFile(filename)
java.text.ParseException: Invalid object type `GtkLabel'
The error is about the first element in the tree.
After a deep research I found that, due to a known bug never fixed, you need to pre-define every widget before using it: in this case just call
new Label();
before creating the builder.
This is, obviously, not intended to work in this way, and will be fixed in the future.
More info on this issue:
Thread on java-gnome-developer mailing list
Thread on Java-gnome-hackers mailing list
Hope this can help...
You're supposed to use the Builder class (available since java-gnome 4.0.20). Create it, call the addFromFile method to give it your glade file. Then just call getObject with the name of the object as entered in the Glade UI to get that object. The only thing I see as missing is the signal connection stuff. The original GtkBuilder class (in C) provides much more, especially signals connection features (gtk_builder_connect_signals for example). So you may need to connect signals by hand if these features are not available in the Java bindings. This means setting in glade in the "signals" tab the signal you want to connect, and setting the name of the callback this signal will call. You can have a good guess of the basics by seeing how it's done in python:
http://python-gtk-3-tutorial.readthedocs.org/en/latest/builder.html
Just browse the web for "glade tutorial" or "glade gtkbuilder" for the rest.

Solr CoreAware FilterFactory

I need to write a custom solr FilterFactory which needs information about core against which it is registered (I assume multicore environment). For some reason I'm disallowed to implement SolrCoreAware from FilterFactory. Is it somehow possible to obtain the core from constructor/init method of the factory?
Thanks in advance!
I think you could use the ResourceLoader object:
#Override
public void inform(ResourceLoader loader) {
Properties coreProperties = ((SolrResourceLoader) loader).getCoreProperties();
System.out.println("SolrCoreName= " + coreProperties.getProperty("name"));
}
To get this working you need to set up the property on your solr.xml file:
<solr persistent="true" sharedLib="../lib">
<cores adminPath="/admin/cores">
<core name="item" instanceDir="item">
<property name="name" value="item" />
<property name="dataDir" value="/data" />
</core>
</cores>
</solr>

Categories

Resources