Jump to content
Changes to the Jaspersoft community edition download ×

label localization in input controls


akossar

Recommended Posts

Is there a possibility to localize input controls attributes (labels descriptions etc) in JasperServer? I looked at the source code and it seems that the model only supports one label and description per input control. Is there any ongoing developement for extension of the model or a workaround to by pass this limitation?
Link to comment
Share on other sites

  • Replies 16
  • Created
  • Last Reply

Top Posters In This Topic

JS 3.0 will include a mechanism to localize input controls labels (as shown in the report input controls form) that uses report message bundles.

 

In JS 2.1, the only solution is to use custom input control JSPs that display localized messages instead of input control labels.

 

Regards,

Lucian

Link to comment
Share on other sites

  • 9 months later...

Localization of the Input control labels can be achieved via the report's resource bundle.

For each report input control/parameter, an entry having net.sf.jasperreports.prompt.label.<name> as key is looked for in the report resource bundle, and if found the corresponding message is used instead of the input control label.

In other words:

  • The JRXML used as main report must specify a resourceBundle attribute.
  • The resource bundles (*.properties files) to which the resourceBundle JRXML attribute resolves must include messages for net.sf.jasperreports.prompt.label.<name> keys, where <name> is the paramete/input control name.

When the report is executed, a resource bundle will be used depending on the current locale, and input controls labels will be taken from the resource bundle.

Regards,

Lucian

Link to comment
Share on other sites

 

Continuing on this discussion

 

Is there any way to support localization other than through resource bundle?

 

For example reading localization data from database and passing that data to JasperServer during execution using scriptlet or some other mechanism?

 

In a large enterprise application it can become nightmare to maintain hundreds of resource bundles




Post Edited by Sam Vijay at 03/25/09 13:21
Link to comment
Share on other sites

 

Thanks Sherman.

 

I think it was a mistake on my part to ask this question in JasperServer forum, rather I should have asked this question in JasperReports forum, because my question was more to do with JasperReports than JasperServer :-)

 

We upload the JRXML files along with related files like resource bundles, images etc…, when report is executed the resource bundles are loaded by JasperServer using the JasperReports method called loadResourceBundle(..) in the net.sf.jasperreports.engine.util.JRResourcesUtil class, I believe this is the default behavior of JasperServer

 

The ReloadableResourceBundleMessageSource bean in applicationContext.xml reads the JasperServer properties not the Report resource bundle data!

 

If my above understanding is correct, now my question is how do we tell the JasperServer/Reports to read property values (related to a report) from say database instead of resource bundle?



Post Edited by Sam Vijay at 03/30/09 09:53
Link to comment
Share on other sites

JasperReports uses the standard java.util.ResourceBundle class to load resource bundles for reports.  If you want to read messages from a DB, you'll have to extend ResourceBundle (which is an abstract class) and implement the required DB lookup code.  Then you can use the class name as the report resourceBundle attribute.  See ResourceBundle's Javadoc, it has some hints on how to write and use custom implementations.

Regards,

Lucian

Link to comment
Share on other sites

 

Thanks Lucian,

Actually I was looking for some magical approach!!!! which does not require modifying the core JasperReport code (like using scriptlet, or config changes etc…).

 

If we extend ResourceBundle then we need to modify the JasperReports code like JRResourcesUtil.java and also we loose the flexibility of using ResourceBundle for few reports, which I want to avoid.

 

Actually I have modified JRFillDataset.java file to read localization data from Database if resourceBundle attribute is not mentioned in JRXML, but I am looking for cleaner and less intrusive approach to get localization data from other than .prop file.

--samvijay



Post Edited by Sam Vijay at 03/30/09 13:55
Link to comment
Share on other sites

samvijay
Wrote:

If we extend ResourceBundle then we need to modify the JasperReports code like JRResourcesUtil.java and also we loose the flexibility of using ResourceBundle for few reports, which I want to avoid.

Using a custom java.util.ResourceBundle implementation does not require any change to the JR code.  JRResourcesUtil calls the ResourceBundle.getBundle method, which is able to load instances of ResourceBundle implementation classes.  As I said in my previous post, all you need to do is to use your ResourceBundle implementation class name as the value of the report resourceBundle attribute.

Regards,

Lucian

Link to comment
Share on other sites

 

Thanks Lucian,

 

 

My basic understating of ResourceBundle class was wrong; I was under the impression that we can pass only the .prop file name as resouceBundle. This indeed is an eye opener for me, this will solve my problem

--samvijay

Link to comment
Share on other sites

  • 1 month later...

Hi Lucianc,

I tried to follow your steps but is not working the jasperserver always display the label's value I defined in the input control form label and not from the resource bundle.

i.e: My input control name is testProperty and the label is net.sf.jasperreports.prompt.label.testProperty.

In the resource bundle file I defined a property net.sf.jasperreports.prompt.label.testProperty=InputName

 

What I'm doing wrong?

 

Thanks for your help

Link to comment
Share on other sites

simonx
Wrote:

Hi Lucianc, I tried to follow your steps but is not working the jasperserver always display the label's value I defined in the input control form label and not from the resource bundle. i.e: My input control name is testProperty and the label is net.sf.jasperreports.prompt.label.testProperty. In the resource bundle file I defined a property net.sf.jasperreports.prompt.label.testProperty=InputName What I'm doing wrong? Thanks for your help

Which JS version are you using?  Do you have a testProperty parameter in the report JRXML?

Regards,

Lucian

Link to comment
Share on other sites

  • 11 months later...

If you have many reports and many input controls to translate, following query can be used on JS MySQL db to print all input control definitions:

Code:
mysql> SELECT DISTINCT    ->   concat('net.sf.jasperreports.prompt.label.', c1.name,'=',c1.label) as input_name    -> FROM    ->   jasperserver.jireportunitinputcontrol a    ->   INNER JOIN jasperserver.jireportunit b    ->  ON a.report_unit_id = b.id    ->   INNER JOIN jasperserver.jiresource c    ->  ON c.id = b.mainReport    ->   INNER JOIN jiresourcefolder rf    ->  ON c.parent_folder = rf.id    ->   INNER JOIN jasperserver.jiresource c1    ->  ON c1.id = A.input_control_id    -> ORDER BY    ->   input_name asc;+-------------------------------------------------------------------------------------------------+| input_name                                                                                      |+-------------------------------------------------------------------------------------------------+                                    || net.sf.jasperreports.prompt.label.ASC_DESC=Ascending/Descending                                 |                                    |                          || net.sf.jasperreports.prompt.label.CONNECTION_TYPE=Connection Type                               || net.sf.jasperreports.prompt.label.CREATION_DATE_FROM=Creation Date from                         || net.sf.jasperreports.prompt.label.CREATION_DATE_TO=Creation Date to                             |                                    || net.sf.jasperreports.prompt.label.DISPLAY_TYPE=Display Type                                     |                                          || net.sf.jasperreports.prompt.label.ERROR_CATEGORY=Error Category                                 |... 
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...