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.
Related
For a Java Schoolproject I would like to have a table from witch you can select a Item that then shows up on a new window. In that window you can change things like ComboBoxes and others. My only problem is, that I dont know how to select the Item of the ComboBox I need. All the ComboBoxItems are Objects and I dont know how to handle this.
My ComboBoxItem looks like this:
Apprentice [person=Person, DB ID: 9, Kappa Kappa, Kappastrasse 21,
CityID: 4521, kappa.kappa#kappa.ch, idpersonen=9,
vertragsstart=2020-01-02, ausbildungsct=2, id=6]
Now, my Question is, how do I select the ComboBoxitem where the id=6, all the things I found needed the whole Object to select a special Item. How would you guys go at this problem?
Good luck and thanks for the Help.
Bono
All I had to do was a really simple while with a for and a if.
int trys = 0;
while (0 == apprenticeComboBoxZeugnis.getItemCount() && trys < 10000) {
System.out.println(apprenticeComboBoxZeugnis.getItemCount());
for (int i = 0; i < apprenticeComboBoxZeugnis.getItemCount(); i++) {
apprenticeComboBoxZeugnis.setSelectedIndex(i - 1);
int spacko = getApprenticeCombo();
if (spacko == lehrlingsid) {
TableFilterListenerZeugnis tableFilterListenerZeugnis = new TableFilterListenerZeugnis(
this);
tableFilterListenerZeugnis.updateNoten();
break;
}
}
trys++;
}
This first trys until the number of Objects is not = 0 and after that looks at every object, cuts out the id with getApprenticeCombo() and compares it with my id I allready have. If they match it breaks out and is done with it.
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.
Hello. I want to create a function that generates ascending numbers.
For example, if today's date is June 21st, 2013 then the numbers will be 130621001.
The last three digits are ascending numbers, and it'll reset back to 001 on each date.
I can figure out on how to make the date digits, but I'm stuck with those last three digits.
Thank you in advance.
try this, good luck
public static String NextNumber(String currentNumber) {
//assume yymmddnnn
String sDateNum = currentNumber.substring(0, 6);
String sCurrentNum = currentNumber.substring(6,9);
int i = Integer.valueOf("1" + sCurrentNum);
i++;
return sDateNum + String.valueOf(i).substring(1, 4);
}
System.out.println(NextNumber("130621001"));
The real question is how you know what your previous answer was.
today = myDateFormatter(System.currentTimeMillis());
if (today.equals(oldDay)) count++;
else count == 0;
oldDay = today;
If this is a long running process, oldDay and count can be simple fields in your class. If the process exits and restarts, you will need to get your old answers from somewhere and set them to the largest value.
Hi there how to show allow ui date picker for time field using 24 hours format?
I'f I'm using
[code]
<%
Calendar dob = CalendarFactoryUtil.getCalendar();
dob.setTime(new Date());
%>
<aui:input name="schedule_msg" model="<%= Message_Schedule.class %>"
bean="<%= msch %>" value="<%= now %>" label="Schedule Time"/>
[/code]
it shows in am/PM mode...or if using AM/PM mode how to get the value??normally if i want to get value in my Portlet Class just like this
[code]
int day = ParamUtil.getInteger(request, "schedule_msgDay");
int month = ParamUtil.getInteger(request, "schedule_msgMonth");
int year = ParamUtil.getInteger(request, "schedule_msgYear");
int hour = ParamUtil.getInteger(request, "schedule_msgHour");
int min = ParamUtil.getInteger(request, "schedule_msgMinute");
try
{
msgSchedule.setSchedule_msg(PortalUtil.getDate(month, day, year, hour, min, new PortalException()));
}catch(Exception e)
{
msgSchedule.setSchedule_msg(new Date());
}
[/code]
any idea how to get that value??
example in the picture it show 4:54: PM so it means in 24 hours it become 16:54:00 .... Please any help
Thank's
Regards
Danial
The aui:input taglib (which in turn uses the liferay-ui:input-date and liferay-ui:input-time taglibs) shows the AM/PM select box if the time format for the current locale requires it. In Liferay 6.1.1, have a look at row 36 in html/taglib/ui/input_time/page.jsp.
So you should definitely keep the built-in behavior, which shows the AM/PM select box depending on the current locale.
In order to get the date properly in your portlet class, you can draw inspiration from the EditEventAction class, which is the Struts action called when you add, update or delete an event in the Calendar portlet. Something like this:
int startDateMonth = ParamUtil.getInteger(actionRequest, "startDateMonth");
int startDateDay = ParamUtil.getInteger(actionRequest, "startDateDay");
int startDateYear = ParamUtil.getInteger(actionRequest, "startDateYear");
int startDateHour = ParamUtil.getInteger(actionRequest, "startDateHour");
int startDateMinute = ParamUtil.getInteger(actionRequest, "startDateMinute");
int startDateAmPm = ParamUtil.getInteger(actionRequest, "startDateAmPm");
if (startDateAmPm == Calendar.PM) {
startDateHour += 12;
}
After that, if you want to get a Date object from these values, it's important to decide whether these values represent a date in UTC, in the current user's timezone or whatever. Have a look at the addEvent method in CalEventLocalServiceImpl class to know how to do it: basically, you have to create a Calendar object with the CalendarFactoryUtil.getCalendar method, passing a locale and a timezone, and then you can set the various values.
Liferay UI part is poorly documented, here is the attributes I found, http://docs.liferay.com/portal/6.2/taglibs/liferay-ui/input-time.html, but it never describe how to use these attributes, what are the values of these attributes.
I wasted too much time on googling and experimenting, and I decided to use JQuery datetime pick instead.
Another way is don't use liferay-ui:input-time, just to use your own hours and mins select input.
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
}
}