Proxy Your Requests With Grunt

Probably you’re already using grunt to serve your local frontend code. Everything is fine, but if you’re developing your backend with something different than JavaScript (Being a Java developer I heard that might happen), you will have problems accessing this backend while running grunt server.
With grunt-connect-proxy there exists a grunt module to help you out. It basically delegates requests that match a given URL to a different backend of your choice. Unfortunately I found it rather difficult to configure, if you are unaware of the connect middleware concept.

Basically you just need to add two things to your Gruntfile.js file:

Firstly add the connect server configuration to your config JSON inside of grunt.initConfig. This example delegates all requests to http://localhost:8000/services to http://localhost:8090/services – keep in mind the grunt server is running on port 8000 and the backend on port 8090:

Secondly register your grunt server task:

then you can call your grunt server with the configured proxy via :
grunt server
from the command line.

Enjoy!

How to detect whether an element is in a scrollable parent

Just think of having an element in a scrollable parent (the CSS property overflow is set to scroll) and you want to test whether the element is visible or not.

Using this little function you can do the trick:

And here’s a small use case – this one scrolls the element into the visible region, if it is not already in the view:

Let the user select an item in a modal dialog

After having used the shiny new YUI3 library for a project, it’s about time to share my YUI3 experiences with you.
For the project I built an item selector: A modal dialog is openend and the user has to select an item. After selection the dialog is closed and the selected item is passed to a callback function.

Here you can find the full source for the item selector. An example to use the selector can be as simple as this:

Just click on the following button, to start the example. Enjoy and let me know your comments.


Using Axis2 services from Javascript (by removing the XML namespaces)

If you want to call an Axis2 service from Javascript you will face the problem that the XML response of an Axis2 service call contains XML namespaces – something Javascript doesn’t like in cross-browser-friendly way.
The idea to fix this issue is to make an XSLT transformation directly from Axis2 that removes the unnecessary namespaces.

First we need an XSLT transformation that will do the job:

Then we’ll need a hand-made Axis2 conform MessageFormatter that uses the standard formatter for XML and performs the XSLT transformation on the result:

(Don’t forget to adjust the path of removeNamespaces.xsl, so the formatter can find the .xsl!)

Finally just put the class of the newly created formatter in WEB-INF/classes of your Axis2 deployment and replace the reference in the axis2.xml configuration file.
For this just exchange the line:

with:

After a restart of your application server you should be able to use your Axis2 services from Javascript – Have fun!