13
votes

I tried to use java.util.Calendar in my GWT application as following:

Calendar cal = Calendar.getInstance();

then i got this error:

No source code is available for type java.util.Calendar; did you forget to inherit a required module?

anyone know what's wrong with it?

6
Since you have some responses below that seem to answer your question, please consider marking one of them as ‘Accepted’ by clicking on the tickmark below their vote count (see How do you accept an answer?). This shows which answer helped you most, and it assigns reputation points to the author of the answer (and to you!).Martin Schröder

6 Answers

11
votes

The relevant bug is logged in GWT since GWT version 1.3 and you can find it here - http://code.google.com/p/google-web-toolkit/issues/detail?id=603

1) The Calendar class support for GWT is a long pending request from GWT User community.

2) Unfortunately GWT team has decided we can do without it.

You can find all possible discussions on Google GWT forum. There are other alternatives which you look up in the forum and the issue discussion thread runs into a few pages.

Essentially we decided to do away with any client side code using Calendar and just handle the stuff on server side.

7
votes

The Calendar class depends on a lot of Java classes that GWT cannot possibly convert to Javascript. If it fits your needs, you could simply do new Date() on the client side. See here for more details.

You could also try the gwt-calendar project.

4
votes

Calender class is not supported from GWT, You must use Date class instead of Calender.

3
votes

java.util.Date will still work, and you can use com.google.gwt.i18n.client.DateTimeFormat to do any date formatting you need to do.

Check that link for full example code.

-3
votes

I would not have thought you would need the source code although I've never used SWT. But at no time when using any one of a wide range of Java apis have I ever had this message just trying to use a class from them. So I think it's either an incorrect message or you have done something in the IDE that is trying to show you the source code. You can find a zip of the source on the JDKs directories. Id's such as Eclipse have the ability to associate source code zips with jars so that they can automatically look up source when you trigger that action.