Search This Blog

Wednesday, September 29, 2010

JRebel rocks!

Today I installed JRebel because I was tired of all the Republish stuff when working with JBoss in Eclipse. I am glad I did! I am not sure how much time it saved me exactly (when working for 4 hours) but looking at the JBoss server.log showed the following:

Maybe a little too optimistic, but a republish costs one minute at minimum. At 40 redeploys, this saves me about 45 minutes. This is 1.5 hour for a full work day!

Monday, September 27, 2010

Flex4 DateField bug when using locale nl_NL

When porting a Flex 3 application to Flex 4 (4.1 SDK), I had a little issue with my DateField components. The selected date in the DateField component did not have any formatting applied to it and when accessing the selectedData property in Actionscript returned null. For example selecting 7th September 2010 resulted in '0709092010' but it should be '07/09/2010'.

Some searching revealed that this is a known bug which is hopefully resolved in SDK4.5. See http://forums.adobe.com/message/2834803 for more details.

A quick workaround is to specify the formatString explicitly in the DateField component as in the following example:
<mx:DateField id="date" formatString="DD/MM/YYYY"/>
<s:Button click="trace(date.selectedDate);"/>

Friday, September 24, 2010

FlexCamp presentation

Wednesday 22nd of September, I gave a presentation for the Dutch Flex User Group at FlexCamp at Adobe in Amsterdam. You can find this presentation below:

Friday, September 3, 2010

Printing in Vaadin

In one of my recent projects for one of our clients, I have used the Vaadin framework to develop the application. One of the requirements of this application was to print certain content. I basically evaluated three possible solutions to implement this functionality:

  1. Create a new window with content specifically designed for printing and use the JavaScript print() method to print the contents of this window;
  2. Create a PDF with the printable contents and open this PDF in a new browser window;
  3. Create a PDF with the printable contents and use the Embedded and Window components to display the PDF.

I found option 1 not compatible and consistent enough between browsers. To create a consistent look&feel of the printable contents I used PDF. One way to display this PDF to the end-user is to open a new browser window. Unfortunately this was hindered by popup blockers which is not acceptable to end-users of the application.

Option 3 involved using an Embedded component to display the PDF inside a native Vaadin popup window (which is a regular div). This way, the printable contents are always consistent (because PDF is used) and the popup with the PDF contents is not hindered by browser popup blockers because the popup is just a regular div. By using this method, the print window also integrated nicely with the visual appearance of the rest of the application. The following code demonstrates how to implement this functionality:
/**
* This class creates a PDF with the iText library. This class implements
* the StreamSource interface which defines the getStream method.
*/
public class Pdf implements StreamSource {
private final ByteArrayOutputStream os = new ByteArrayOutputStream();

public Pdf() {
Document document = null;

try {
document = new Document(PageSize.A4, 50, 50, 50, 50);
PdfWriter.getInstance(document, os);
document.open();

document.add(new Paragraph("This is some content for the sample PDF!"));
} catch (Exception e) {
e.printStackTrace();
} finally {
if (document != null) {
document.close();
}
}
}

@Override
public InputStream getStream() {
// Here we return the pdf contents as a byte-array
return new ByteArrayInputStream(os.toByteArray());
}
}


And the code for displaying a popup with the actual PDF viewer:
Window window = new Window();
((VerticalLayout) window.getContent()).setSizeFull();
window.setResizable(true);
window.setWidth("800");
window.setHeight("600");
window.center();
Embedded e = new Embedded();
e.setSizeFull();
e.setType(Embedded.TYPE_BROWSER);

// Here we create a new StreamResource which downloads our StreamSource,
// which is our pdf.
StreamResource resource = new StreamResource(new Pdf(), "test.pdf?" + System.currentTimeMillis(), this);
// Set the right mime type
resource.setMIMEType("application/pdf");

e.setSource(resource);
window.addComponent(e);
getMainWindow().addWindow(window);


A full, working example including PDF generation, can be found here. The example project demonstrates displaying the PDF with and without a popup.

What is your experience with printable content in a Vaadin application?

FlashBuilderCamp

On September 22nd, the Dutch Flex User Group organizes FlashBuilderCamp at Adobe in Amsterdam, The Netherlands. I will be giving a session about presentation patterns and how to implement these patterns with the Swiz framework. Swiz is a micro-architecture and dependency injection framework for structuring Flex applications which I used in a couple of major Flex application.

Make sure you attend the conference. Entrance and dinner is free. More information can be found at Flugr.

Thursday, August 5, 2010

Stream erorr 2032 in Flex using HttpService

Lately I developed an application for a workshop I was giving. The application was a Flex application which communicated with a SpringMVC 3.0 annonation based based web application using Xstream as XML serialization library. All seemed well until in specific browsers and operation systems I got a 'Error #2032: Streamfault'. I did not found a solution on the Internet other than verifying that my URL was correct and disable HTTP caching on the server. None of these solutions worked.

When I executed this specific request in the browser, I got a HTTP 406 status code. The 406 status code says:
The resource identified by this request is only capable of generating responses with characteristics not acceptable according to the request "accept" headers ().
Inspecting the request the browser sent, showed an accept-header of '*/*'. I compared this to the accept-header FireFox sent which was: 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8'.

The solution turned out to set the accept-header explicitly on the HttpService. I used the following code for this:

var httpService:HTTPService = new HTTPService();
httpService.url = url + "/tasks";
httpService.requestTimeout = 10;
// Set the content type expected by the server
httpService.contentType = "application/xml";
// Explicitly set the accept header
httpService.headers = { accept: "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8" };
httpService.resultFormat = "e4x";

As a sidenote, to disable HTTP caching on the server, you can use the following code:

response.addHeader("Pragma", "no-cache");
response.addHeader("Cache-Control", "no-cache");
response.addHeader("Cache-Control", "no-store");
response.addHeader("Cache-Control", "must-revalidate");
response.addHeader("Expires", "Mon, 8 Aug 2006 10:00:00 GMT");

Monday, May 10, 2010

Flex workshop

At Wednesday the 2nd of June I will be giving a Flex/Swiz workshop. During this workshop I will show you how to develop a Flex application with the Swiz framework. Swiz is a micro architecture and dependency injection framework for Flex. Swiz does not restrict you in any way which enables you to use Swiz in almost any application. by using Swiz and, for example the MVCS pattern, the application becomes better testable and maintainable.

The application we are building is a simple contact/task management application based on experiences from clients when building complex Flex applications. The application communicates with a Java backend using BlazeDS and XML/HTTP. The full workshop contents are presented on a VMWare image. The only prerequisite from the attendee is a laptop with VMWare player and at least 8 GB of free hard disk space.

Agenda:
June 2nd, 2010
15:00 – 15:30 Welcome and introduction
15:30 – 18:30 workshop
18:30 – 19:00 Conclusion and dinner

Location:
QNH Business Integration
Driebergseweg 2
3708 JB Zeist

There are still seats available so be quick!

See you there!

Thursday, February 25, 2010

Flex Camp 2010

Update: The presentations are online and can be found here.

The first Flex Camp 2010 is a fact and was a great success. Flex Camp is organized by the Dutch Flex User Group (FLUGR) and is a half-day Flex event with a variety of speakers and subjects. This time, the location of the event was Amsterdam. The following sessions were given:

Designer/Developer workflow with Flash Catalyst and Flash Builder

This session was all about how Flash Catalyst and Flash Builder approach the designer /developer workflow. In a traditional development environment a design usually takes the form of a Photoshop document which is sliced by the developer and incorporated in the Flex application. Flash Catalyst takes a new approach in that this product is able to import and slice the design itself. When imported, Flash Catalyst is able to convert individual elements to read-to-use Flex components.

One thing that is not incorporated in the product yet, is an iterative design/development cycle although this can partly be accomplished with the use of libraries.

Set your code on fire

Flex developers with a Java background are always disappointed by the lack of features of Flex Builder compared to working with Java editors. Luckily there are alternatives for Flex Builder and one of the alternatives is FDT from Powerflasher. During the session, an application was developed to show a lot of the capabilities of FDT. Very impressive. Some of FDT’s features are:


  • Rename and move refactoring

  • Extended use of code templates and quick fixes to:


    • Generate classes

    • Generate functions

    • Generate fields with getters and setters

    • Loop over arrays

    • Etc.


  • Superb code navigation possibilities like type hierarchy, dependency structure, outline view with search capabilities.

  • Debugger


Version 4 of FDT, which is coming in 2010, has even more features like a memory and performance profiler. To learn more about version 4 goto http://fdt.powerflasher.de/fdt4comfort

Flex Builder action script projects

Flex Builder is not only good in Flex projects but also suitable for Action script only projects. The speaker showed how he developed a pure Action script only website with Flex Builder. During the session a lot of practical tips were given which he encountered during the development of the website. Unfortunately, the site is not yet live at the time of writing. To be continued.

Flex in a JEE environment

In this session the speaker demonstrated a Flex application which is used to display information about geographical locations. The application integrates with the backend using web services and Blazeds and is deployed on a JBoss application server. The speaker showed how Maven is used to build and distribute the application and how the Flex application can be configured using server side services. It was a very practical and good session, especially for Java and Flex developers.

When all presentations are online, I will post the link to these presentations here.

Conclusion
Flex Camp 2010 was a big success. The subjects of the sessions were diverse enough to please everyone who attended Flex Camp. From Flex designer/developer to hardcore Java developer. On to the next Flex Camp!