Sunday, January 29, 2006

Mark Occurrences

WARNING: This blog entry was imported from my old blog on blogs.sun.com (which used different blogging software), so formatting and links may not be correct.



Sandip "Plugin" Chitale

has published yet another NetBeans module. This one adds a toggle button to the toolbar, which when enabled, causes occurrences to be highlighted in the editor. For example, if you put the caret on a field, all uses of that field in the file are highlighted. As another example, if you place the caret on a method declaration, then all exit points from that method (return statements, throw statements) are highlighted. And so on and so forth. Read the
full description with screenshots and take it for a spin. Works like a charm with NetBeans 5.0 RC2.



Here's a sample screenshot from his blog showing what happens if you put the caret on a formal parameter in a method declaration (unfortunately the blinking caret didn't show up in the screenshot but imagine that it's on the highlighted parameter):





Friday, January 27, 2006

Creator Flashback

WARNING: This blog entry was imported from my old blog on blogs.sun.com (which used different blogging software), so formatting and links may not be correct.


Since Creator 2 launched on Wednesday, we had a special event on Thursday to celebrate. There were various presentations of cool web apps built with Creator 2.



I did a "walk down memory lane", by showing the original JavaOne 2003 demo bits for Creator - then called Project Rave. This was back when we only had a prototype; it took a year from that point to build a real product and release Creator 1.0 the following JavaOne conference.



The hardest part was actually finding the bits. This was before we were an official product, so we were flying under the radar - our source code didn't live in the release engineering infrastructure, but on a CVS server under a desk in the shared group room (the "Rave Room"). I ended up finding a snapshot build in a random directory on a server that was close enough to the JavaOne build. I fired it up, and ah, the memories!



Here are some screenshots... Most of the current Creator team has joined after the original demo, so this was news (or I guess "olds"?) to everybody.



Here's the splash screen. We had adopted a shark as our mascot, and because of that, subsequent releases have been named after types of shark - hammerhead, reef, thresher, mako, ... and let's not forget the multilingual release after hammerhead, named landshark (after SNL).






(We also featured an animated shark in the deployment progress bar!)


Once the IDE came up you got the original Welcome screen. Notice how the look and feel is different.
We had a custom look and feel based on the Kunststoff L&F. (Click for full size)









Then we created a project, and designed the application in the designer. The application was
Travel Center, a simple application involving travellers, trips, flights, and so on. This
sample application lives on today - it's one of the sample applications available for Creator 2!
(I believe we've modernized it though.)








The JavaOne demo was more involved - for example, we hooked up individual flights in the flight
table to a web service to get itinerary results. And the key thing was that we could build these
things in just 5 minutes!



Amazingly, a lot of stuff in the IDE was real - this was no "flash" prototype. The user actually
built a real web application, that was using JSF, that got deployed to JWSDP, etc. Of course,
the whole "component" model was messy - the designer had special knowledge of the components
and how to paint them, etc. And the two way editing was just starting to get working and was
disabled in the JavaOne builds to prevent booth disasters :)



As I was looking for the JavaOne bits I came across a couple of other possibly interesting
artifacts - two temporary splash screens. The first splash screen is the splash screen we had
in the Rave builds early on, before we got the Shark one right before JavaOne:






The second one was a splash screen some of us used in our builds during the 1.0 cycle just
because we thought it looked cool. (I think it was Marco who found the shark image)





Wednesday, January 25, 2006

Ajax Made Easy

WARNING: This blog entry was imported from my old blog on blogs.sun.com (which used different blogging software), so formatting and links may not be correct.







The
latest episode of the SDN channel deals with AJAX. The show features interviews with Dojo Toolkit Project Lead Alex Russel, Ajaxian.com co-founder Dion Almaer, Servlet Spec and AJAX lead Greg Murray, and myself.



Also be sure to check out the Update Center in Creator 2. The preliminary AJAX component library should be available, and it features some new AJAX enabled components! More on those soon.


Tuesday, January 24, 2006

Creator 2 is OUT!

WARNING: This blog entry was imported from my old blog on blogs.sun.com (which used different blogging software), so formatting and links may not be correct.


Stop the presses - Creator 2 has been launched! Having spent an enormous number of hours on it (and blood, sweat and tears - tears of joy that is), it feels great to finally draw the line in the sand and declare it done. Yes, we have more features to do. Yes, we have more performance work to do. But the product has made a huge leap forwards from Creator 1, and can really make web application development trivial, even for developers completely unfamiliar with J2EE and web programming in general.



I could mention the new stuff in Creator 2 here - but the

Creator web site

has been redesigned for the launch of Creator 2 and is a great resource to take a look at. Be sure to view the flash demo of the product, and read the feature list. I mentioned some awards last week.



Most importantly, download the bits and try the product! It's free!!! Once you do, make sure you look at the Learning part of the web site - there are tons of tutorials and tips that tell you how to do all kinds of things - from navigation to validation to database CRUD to portlets to webservices to AJAX and on and on!



Here's a toast to all who contributed to Creator 2, not just the Creator team and management but all our users, beta testers, reviewers and others who have provided feedback. Cheers! Skål! On to Creator 3!









Available Free!
Sun Java Studio Creator 2 makes visual web application and portlet development easy. » Learn More





Monday, January 23, 2006

Why AJAX was hard

WARNING: This blog entry was imported from my old blog on blogs.sun.com (which used different blogging software), so formatting and links may not be correct.


I just listened to
episode 12
of the Ajaxian podcast, where they interview Thomas Fuchs of Scriptaculous. In it they talk a bit
about how after the AJAX craze started, Microsoft and others came out
and said building AJAX is for rocket scientists. Thomas rejects that and states that it's trivial - it's just a call to a server.
I'm one of the people who came out and said that AJAX is hard - in fact I said it
during the keynote demo at JavaOne where I showed Creator's AJAX
support. So, I thought I'd clarify why I said it since at the time it was clearly true.



AJAX applications typically consist of asynchronous server trips (via XMLHttp), CSS, XML,
and JavaScript. It's the JavaScript which makes AJAX hard. JavaScript itself is easy - the
problem is with the browsers.
Even during the interview, Thomas talks about how Internet Explorer
has issues - they have all kinds of hacks in place for IE, sending a separate CSS stylesheet
to it to deal with quirks and so on.



In my own AJAX work, I quickly discovered that while it was really easy
to get the component to work well on Firefox, getting it to work on
IE was harder. Getting it to work on both was harder still. And then
throw in the fact that Safari has its own quirks. Even Mozilla 1.1 and
Mozilla 1.4 behaved differently in the kind of JavaScript code I was
writing. And when you add a workaround for one you've gotta make sure
it doesn't break the others. On top of that, even if Firefox has a decent
JavaScript debugger, that doesn't help you when the bug only shows up
in IE (or Opera, or Safari, or Konqueror, ...).
You also need to be well versed in browser bugs such that you for example
know to avoid the memory leak issues you can run into with IE.



THIS is what I meant by "AJAX is hard". No, asynchronous is not hard.
XML is not hard. CSS is not hard. It's cross-browser stable, performant
JavaScript that is hard.



So why am I using past tense - "AJAX was hard" as opposed to "AJAX is hard" ?
The reason for that is that a number of great cross-browser JavaScript libraries
are emerging. These have done most of the hard work for you. I still strongly
believe that a library approach to AJAX is not enough - you really want components
that do all the AJAX plumbing for you as well. I'll have more to say about that soon.


NetBeans Extras

WARNING: This blog entry was imported from my old blog on blogs.sun.com (which used different blogging software), so formatting and links may not be correct.


Andrei Badea, Petr Hrebejk, and Trung Duc Tran have set up their own web site,
http://www.nbextras.org, which has one primary feature:


  • It's an Auto Update site for additional plugin modules for NetBeans.

Users can contribute modules for NetBeans, and these are then made available on the update center.
Here's how you can add the update center to your own NetBeans installation.



The thinking behind this is that NetBeans itself tries to provide a very coherent and clean user interface, with all the different parts working seamlessly together. However, there's a growing number of useful plugins that may not yet be ready for inclusion into the standard distribution. This site tries to make it easy to share these. And of course the site also provides a blog interface so it's easy to track new additions, and discuss plugins you're using with others. I've seen lots of useful plugins, and use several myself (such as
this,
this,
this, and others)

that I build from source in the NetBeans source tree's contrib CVS module. Here's to hoping these will all be provided in binary form on the nbextras site soon. (Yeah I know, it's a volunteer effort, perhaps I should upload them myself!)



Go check it out, and contribute in any way you can - with your own plugin modules, or with useful feedback on what's there.


Phew

WARNING: This blog entry was imported from my old blog on blogs.sun.com (which used different blogging software), so formatting and links may not be correct.


It's been nearly two weeks since my last entry. I do apologize; I try to write something at least weekly, but the last month has been very crazy in my personal life. My son had surgery last week (which thankfully went well), and I've had some other very stressful things going on as well, but it's mostly resolved now and I can get back to thinking about work and coding!


Wednesday, January 11, 2006

More Awards

WARNING: This blog entry was imported from my old blog on blogs.sun.com (which used different blogging software), so formatting and links may not be correct.



Creator has recently picked up two nice awards. Creator is the "Java Tool or Add-in of the Year" at Developer.com
(Full Article).



Also, eWEEK Labs has picked Java Studio Creator 2 as the most attractive developer tool for 2005!


The Early Access version gave me the kind of drag-and-drop convenience that developers expect after years of experience with Microsoft's Visual Basic or Borland's JBuilder and Delphi. It not only worked well when used as intended but also resisted my attempts to confuse its cooperating tools.

(Full Article).



Tuesday, January 10, 2006

Creating downloadable files

WARNING: This blog entry was imported from my old blog on blogs.sun.com (which used different blogging software), so formatting and links may not be correct.





My brother has been visiting me this last couple of weeks.
It's been really nice and fun - see the picture on the right for my
recycling bin a couple of days ago...



Last night we took a look at an application he has developed using
Creator 2 (EA2). It's a nice little web application for his company that
lets customers download patches based on privileges, installed
software, etc. It had some weird bugs. So I went looking in the
forums, and sure enough, there's a real Gotcha! with implementing
live file downloading. Several people had tried and the solution
was not posted. So, a blog entry might be in order!



There are many use cases for live file downloading. (By "live file"
I mean that you are not just providing a static hyperlink to a file
you are just deploying with your web application - you instead want
to provide the file to the browser when they click on something, but
the contents of the file might be generated on the fly, or at least
the actual file to be downloaded is determined at runtime).



For example, you may want to let users click to download and view a
PDF report based on current data in the web application, or perhaps
even use something like POI
to generate Excel-formatted spreadsheet files.



The first thing you have to do is write an action handler. This is
invoked when the user clicks the download link or button. Double click
on the component to get a skeleton, then write something like this:


public String button1_action() {
String filename = "foo.pdf"; // Filename suggested in browser Save As dialog
String contentType = "application/pdf"; // For dialog, try application/x-download
byte[] data = ; // File contents to be written. Sorry, YOU have to do this part!

FacesContext fc = FacesContext.getCurrentInstance();
HttpServletResponse response = (HttpServletResponse)fc.getExternalContext().getResponse();
response.setHeader("Content-disposition", "attachment; filename=" + filename);
response.setContentLength(data.length);
response.setContentType(contentType);
ServletOutputStream out = response.getOutputStream();
out.write(data);
fc.responseComplete();

return null;
}



You may have been tempted to add the above code in the action handler for
a hyperlink (or link action). That seems really natural - most "download links" on the
web are just that - actual links. Indeed, that's what my brother
had done.



And that's the gotcha. If you do that, the above code will work, but
as soon as you've clicked the link to download, your web app starts to
act funny - if you click on any other hyperlinks, the download will
be initiated again! It's as if the above code "corrupts" the webapp.



The solution is really simple. Just use a download button instead
of a link!
If you hook the download code up to a button action handler, everything
will work as expected. And having a button rather than a link does make
some sense when what you're doing is asking for something to be
generated (a live file) rather than simply referencing a static
resource.



<speculation range="wild">

JSF jumps through some hoops to make HTML hyperlinks behave like
proper "actions" - via tricks like using an input hidden field
in the form etc. This might be what's causing the weird link
anomaly. I will check with the JSF guys to see if this has been addressed
in newer JSF releases.


</speculation>