I originally wrote a desktop application that uses JasperReports.
In this application the user can dynamically change the locale setting and this change will be reflected in the reports. This works fine.
I have a web application that has the same functionality. Everything works fine except for the currency symbol where I get a ยค instead of the symbol. The date is formatted properly according to the locale and so are the number formats. The only problem is the currency symbol. I do not have this problem in the desktop application even though I am using the exact same jrxml file to generate the reports in both cases. So the problem cannot be from the jrxml file.
Does anyone know how to solve this problem?
UPDATE:
Ok, if I use the command
myLocale = Locale.CANADA;
and then I pass the myLocale variable to the jasper report everything works fine, but since my web application allows the user to choose whichever locale he/she wants I create a loop the following way:
Locale myLocale = Locale.getDefault();
Locale[] locales = Locale.getAvailableLocales();
int localeCount = locales.length;
for (int i = 0; i < localeCount; i++) {
if (locales[i].getDisplayName().equals(##Whatever the user chose##))
myLocale = locales[i];
}
In this case when I pass the variable myLocale to the jasper report I get the above mentioned problem with the currency symbol (but not with number formats and dates). Can someone point out what is wrong with the above code? Thanks.
I have found the solution to the problem. Apparently i needed to drop from the list of locales those that do not satisfy the following condition: myLocale.get(j).getCountry().length() > 0. The code now becomes:
Locale[] locales = Calendar.getAvailableLocales();
//Convert to list in order to remove some elements
List<Locale> locales2 = new ArrayList<Locale>(Arrays.asList(locales));
int localeCount = locales2.size();
for (int j = 0; j < localeCount; j++) {
if (!(locales2.get(j).getCountry().length() > 0)) {
locales2.remove(j);
localeCount--;
}
}
//Now loop over the list in search for the selected locale
for (int i = 0; i < localeCount; i++) {
if (locales2.get(i).getDisplayName().equals(**whatever the user chose**)) {
myLocale = locales2.get(i);
break;
}
}
Now the currency symbol appears properly.
Related
I am trying to develop a simple web application with vaadin, in which I want my the user to enter his name, surname, mail adress and date of birth. Each works fine, except the ComboBox for the date of birth selcetion. Day and Month are allright, but to fill the box for the year, I used the following code:
`for (int i = 1900; i < 2016; i++)
{
year.addItem(i);
}`
(the ComboBox is called 'year'). The result I get is a list from 1.900 to 1.908. What is wrong with my code? Need help soon.
Thx, simon1440
I think converting int to String should help:
for (int i = 1900; i < 2016; i++)
{
year.addItem(String.valueOf(i));
}
Here you can see more examples with combobox. Your case is similar to example#2.
I have sample strings like:
Data Management_Commercial IMS (Information Management System)
Data Management_Non-structured Data Management (Text Documents, Paper Forms, etc.)
I am passing the strings from the jsp page via input-move-boxes. So in the jsp page I have:
List<KeyValuePair> leftDataManagementList = new ArrayList<KeyValuePair>();
List<KeyValuePair> rightDataManagementList = new ArrayList<KeyValuePair>();
rightDataManagementList.add(new KeyValuePair(attribute.getAttributeListName()+"_"+attribute.getAttributeListValue(), attribute.getAttributeListValue()));
leftDataManagementList.add(new KeyValuePair(attributeMaster.getAttributeListName()+"_"+attributeMaster.getAttributeListValue(), attributeMaster.getAttributeListValue()));
The input-move-box in this case is
<liferay-ui:input-move-boxes
leftBoxName="availabledm"
leftTitle="Data Management Available"
leftList="<%=leftDataManagementList %>"
rightBoxName="selecteddm"
rightTitle="Data Management Selected"
rightList="<%= rightDataManagementList%>"
/>
In java class these are retrieved in String[] selecteddm variable.
String[] selecteddm = ParamUtil.getParameterValues(request, "selecteddm");
But I am passing one string at a time.
So when I store the first string Data Management_Commercial IMS (Information Management System) in the variable. I get the expected results.
System.out.println("Length:" +selecteddm.length);//Length:1
System.out.println(Arrays.toString(selecteddm));//[Data Management_Commercial IMS (Information Management System)]
int count = 0;
for(String str:selecteddm){
System.out.println(str);//Data Management_Commercial IMS (Information Management System)
System.out.println(count++);//0
}
Now I get the problem with the second string Data Management_Non-structured Data Management (Text Documents, Paper Forms, etc.), as it is splitting into separate strings after comma. In this case,
System.out.println("Length:" +selecteddm.length);//Length:3
//This print seems fine
System.out.println(Arrays.toString(selecteddm));//[Data Management_Non-structured Data Management (Text Documents, Paper Forms, etc.)]
int count = 0;
for(String str:selecteddm){
System.out.println(str);
System.out.println(count++);
}
The loop in this case prints:
Data Management_Non-structured Data Management (Text Documents
0
Paper Forms
1
etc.)
2
Why is this exactly happening? As a result str.split("_")[1] on the string in second case generates ArrayIndexOutOfBoundsException. How can I avoid this and make it work like the string in the first case?
Has it to do with this bug?
https://issues.liferay.com/browse/LPS-42949
EDIT: after reading update disclosing use of Liferay
The root of the problem is that you are passing the display labels from the form instead of a key to identify them. You should pass form selections by key instead, like this:
List<User> userList = ...
List leftList = new ArrayList();
List rightList = new ArrayList();
for (int k = 0; k < userList.size(); k++) {
User user = (User) userList.get(k);
leftList.add(new KeyValuePair(String.valueOf(user.getUserId()), user.getScreenName()));
}
The second argument of the KeyValuePair is displayed to the user, the first argument is the key which is sent as part of a single, comma separated request parameter (containing all keys of selected items). You are supposed to identify the selection based on the keys, not the display labels.
ParamUtil.getParameterValues is ultimately splitting the value by ",". This explains the behavior your are seeing.
BTW: that bug LPS-42949 seems fixed in the latest Liferay version. In any case it is not the cause of your problems.
The following javascript code will inform all your browser's enabled plugins (yeah, I know it doesn't work on IE, but for IE there's always deployJava):
if ((navigator.plugins) && (navigator.plugins.length)) {
for (var bb = 0, l = navigator.plugins.length; bb < l; bb++) {
var vv = navigator.plugins[bb].name + "<br>";
document.write(vv);
}
}
I have Java 6.22 installed so the relevant line written to the page is this:
Java(TM) Platform SE 6 U22
My question is: how can I complement the above code so that it returns the major version (6) and update (22) found in my (or anyone's) browser?
I think the best way is to work with regular expression, but I am not good with it.
I think the easiest (read: hackiest) solution would be something like this:
var plugin_name = navigator.plugins[bb].name
if (plugin_name.toLowerCase().indexOf("java") != -1) {
var parts = plugin_name.split(" ").reverse();
// if the plugin has an update
if(plugin_name.match(/U[0-9]+/)) {
// grab the end of the plugin name and remove non numeric chars
var update = parts[0].replace(/[^0-9]/, "");
// grab the major version and remove non numeric chars
var major = parts[1].replace(/[^0-9]/, "");
// print the major number and update number
console.log(major);
console.log(update);
} else {
var update = "0";
// grab the major version and remove non numeric chars
var major = parts[0].replace(/[^0-9]/, "");
// print the major number and update number
console.log(major);
console.log(update);
}
}
You can then throw this code in your loop through the plugins and replace the console.log with whatever logic is appropriate given a major and update number.
so from my previous question, Disable specific dates on p:calendar, i know that i can disable specific dates using Javascript like this:
var disabledDays = ["5-15-2013", "6-23-2013"];
function disableAllTheseDays(date) {
var m = date.getMonth(), d = date.getDate(), y = date.getFullYear();
for (i = 0; i < disabledDays.length; i++) {
if($.inArray((m+1) + '-' + d + '-' + y,disabledDays) != -1) {
return [false];
}
}
return [true];
}
with:
<p:calendar id="pfdate" navigator="true" pattern="MM-dd-yyyy"
value="#{day}" BeforeShowDay="disableAllTheseDays" showOn="button"/>
However, my question is that how can i store dates in disabledDays array using EL expressions? I need to do this because the dates that i need to disable varies. Disabling dates needs to be dynamic. If i can't do this with EL expressions, is there anyways to use an array that will have dynamic data?
Thanks
One possibility is just converting the value in a bean (["5-15-2013", "6-23-2013"]), and put it directly in the Javascript code:
var disabledDays = #{myBean.disabledDays};
It's not the cleanest one, but the easiest. Another possibility is just having the list of strings in the bean and use <ui:repeat> to print it as a comma separated list.
I'm developing a custom Adsense report tool using Google Java Client Library for Android. I've successfully authenticated and can make API calls to the server. but now when I receive the response, I don't know how to parse it and correctly show the result to user.
According to the javaDocs, AdsenseReportsGenerateResponse.getRows() generates a List> But I'm kinda lost how to properly parse it to get:
-Today's earnings
-Yesterday's earnings
-Last 7 days
-Last month
-From the beginning of time
Here's part of my code related to the question
Reports.Generate request = adsense.reports().generate(startDate, endDate);
request.setMetric(Arrays.asList("PAGE_VIEWS", "AD_REQUESTS", "AD_REQUESTS_COVERAGE", "CLICKS",
"AD_REQUESTS_CTR", "COST_PER_CLICK", "AD_REQUESTS_RPM", "EARNINGS"));
request.setDimension(Arrays.asList("DATE", "WEEK", "MONTH"));
request.setSort(Arrays.asList("+DATE"));
AdsenseReportsGenerateResponse response = request.execute();
//TODO: Here be dragons
response.getRows();
Edit: Here is the javaDoc which mentions the getRow()
Hmm it seems nobody on this site can help?!
You should find our sample code useful: http://code.google.com/p/google-api-java-client/wiki/APIs#AdSense_Management_API
Namely, this is the file you're interested in: http://code.google.com/p/google-api-java-client/source/browse/adsense-cmdline-sample/src/main/java/com/google/api/services/samples/adsense/cmdline/GenerateReport.java?repo=samples
Here's a snippet of code to print the output. Mind you, this is for a command line application, but should be easily adaptable:
if ((response.getRows() != null) && !response.getRows().isEmpty()) {
// Display headers.
for (AdsenseReportsGenerateResponseHeaders header : response.getHeaders()) {
System.out.printf("%25s", header.getName());
}
System.out.println();
// Display results.
for (List<String> row : response.getRows()) {
for (String column : row) {
System.out.printf("%25s", column);
}
System.out.println();
}
System.out.println();
} else {
System.out.println("No rows returned.");
}
As for getting the data for different periods of time, you should probably be running different reports, not cramming it all into one, as that would take different start dates and end dates. Here's how it works:
Today's earnings: set the start and end dates to today, set the dimension list to just DATE
Yesterday's earnings: set the start and end date to yesterday, set the dimension list to just DATE
Last 7 days: if you want data per day, then you set the start date to 7 days ago, the end date to today, and the dimension list to just DATE. If you want to aggregate the stats, you may need to calculate this yourself, as WEEK and MONTH refer to a calendar week and month, not the last 7 days.
Last month: start date 1st of last month, end date last day of the month, dimension MONTH.
All time: how do you want this aggregated? Per month? Then set the start date to, say, 1980-1-1, end date to today and dimension to MONTH.
This blog post should help with understanding reporting concepts a bit better: http://adsenseapi.blogspot.com/2011/11/adsense-management-api-diving-into.html
Let me know if you need help with anything else!
Its not a List<List> as far as I understand the api. Try this:
String[][] array = response.getRows();
for (int i = 0; i < array.getSize(); i++){
String dimension = array[i][0];
String metric = array[i][1];
//Do what you want with them
}
I am writing this because the API says it has a list of dimensions with one value for the string and one for the metric, as far as I understand.
If you expect several cells on each row (Which I believe the API doesn't work that way), you need to add another for inside and get the size of the current list probably with something like array[i].getSize()
Post back if it doesn't help you.
Edit: I see now. Try this:
List list = response.getRows();
for (int i = 0; i < list.size(); i++){
List<String> list2 = list.get(i);
for (int j = 0; j < list2.size(); j++){
String value = list2.get(j);
//Do what you want
}
}