Posts

Showing posts from September, 2009

Eclipse Resource Filtering

Today i found a solution to the single most irritating thing with Eclipse. To not be able to filter away resources from the Open Resource dialog. This was of course possible but I've never even thought about it until a coworker passed me this link . I quote: The trick is to open the "Navigator" view, right click on the folder to be ignored, and check the "Derived" property. This option informs Eclipse that this folder consists of generated resources that should not be directly edited. Once this is done, the "Open Resource..." view will only show matches that would be relevant to the developer.

Getting a FacesContext from a GWT service

I'm working on a project where we needed to integrate JSF and GWT. To be more specific, we needed to have access to JSF beans in the GWT services. Because I missed the methods getThreadLocalRequest() and getThreadLocalResponse() in RemoteServiceServlet, I had to search quite a bit before i found an answer to this problem. So to save others some time i post the class i came up with. Most of the code is taken from an article at ocpsoft.com which also points out how important it is to release the context when you're done with it. The big difference are the lines, UIViewRoot view = facesContext.getApplication().getViewHandler().createView(facesContext, "gwtViewID"); facesContext.setViewRoot(view); , which sets the view root. If no view root is set you can't use, for instance MessageBundles. The getBean methods are only convenience methods for retrieving beans by name. /** * A substitute for RemoteServiceServlet that has access to the FacesContext. */ @Sup...

How to create a jQuery plugin

I tend to write everything i do in JavaScript as a jQuery plugin. Even if it's mostly useless, i think it's a convenient way to encapsulate the code. In this post I'll show how to make a simple plugin that replaces the background color of an element when the mouse hovers over it. In real life you would probably want to do this with CSS pseudo-classes . Step 1 - Get ready All plugins i write always starts with the same template: (function($){ $.fn.backgroundHover = function(options) { return this.each(function () { // Code goes here }); }; })(jQuery); Line 1 and 7 are only there to protect from $-function overloading by using variable scoping . On line 2 the plugin function is defined in the prototype of jQuery. fn is just an alias for prototype . Since a plugin can be applied to many DOM nodes in one call, we must loop through every element on line 3. Step 2 - Get Set Now we just need to write the actual code for the plugin. First we gonna a...