Sunday, December 11, 2011

Ubuntu price

Ubuntu costs no money but it costs time to search for solutions for various issues. And recent releases are full of issues most of which are regressions.
The latest one is that file transfer over Bluetooth does not work - Bug 897995.

Saturday, May 21, 2011

Natty Upgrade

Finally upgraded to Ubuntu 11.04 Natty Narwhal. The upgrade went smooth. Download was faster than the actual package update. It is interesting to see the upgrade running while the old system is still usable. I guess they do the actual switch during the reboot. And Ubuntu upgrade takes only one reboot.

But still there was a glitch after the upgrade. It said something that my display mode is not supported and switched it from 1920x1080 to 1024x768. Even if I try to switch it back, the image gets distorted. Then I noticed that Login screen used the right resolution and the same also for the other account on my PC. But when I login to my account the screen switches to 1024x768. Obviously it is some account-specific configuration. After couple of hours searching around I found the guilty file ~/.config/monitors.xml. After deleting it and re-login the screen resolution is back to normal.

Release 10.10 was pretty buggy. As Tom said once there seems to be a tradition of .10 releases being more unstable. I hope that 11.04 sticks to this tradition and is more reliable than the previous one.

Sunday, April 10, 2011

Queries in Sling

Here is how I use JCR queries in my .esp pages.
The sample below lists all child nodes of the current node sorted by price property.

var sql = "select * from [nt:base] where ischildnode('" + currentNode + "') order by price asc";
var query = currentSession.workspace.queryManager.createQuery(sql, Packages.javax.jcr.query.Query.JCR_SQL2);
var result = query.execute();
var iter = result.nodes;
while (iter.hasNext()) {
var node = iter.nextNode();

// render each node from the result

<% } %>

Notice that when a Node is converted to string its path is used.
Also here you can see how Packages object is used to access static members of Java classes. This is a Rhino feature. You can read more about it here.

Resizing windows in Ubuntu

A major usability paint point in Ubuntu's default theme is that it is very difficult to grab the window border to resize it. The reason is that the borders are very thin, I think just one pixel.
So I have been using Alt-F8 shortcut (see System > Preferences > Keyboard Shortcuts) to resize windows. But this is not very convenient either since you can resize in only one direction. To resize in another direction you have to press Alt-F8 again. Also the direction is chosen from the initial mouse movement after Alt-F8. Well, just try it.
Now I got irritated by this obvious malfunction and did a quick search and found this thread. It turns out you can also resize windows with Alt-(middle mouse button). Well, this is much easier. There is also a link to a bug report where they say this will be addressed in the coming 11.04 release. It seems like there will be 3 pixel wide invisible area around the window edges where you can grab and resize.

Some other useful shortcuts:
  • Alt-F7 - move active window (very convenient to get back a window from a second display/TV which is currently turned off)
  • Alt-(left mouse button) - move window

Friday, March 25, 2011

Log in Sling

The default Sling user is anonymous and it has read-only access to the repository. So if this user attempts to change anything in the repository he gets an error like this

javax.jcr.AccessDeniedException: <path>: not allowed to add or modify item

So in order to change the data they have to login with a user that has proper permissions. But we still want to allow anonymous visitors to read the content of our site (like search engines). We ask them to log in only if they choose to edit the content. One way to do this in Sling is like this:

if (!currentSession.hasPermission(currentNode.path, "set_property"))
    response.sendRedirect(request.requestURL + "?sling:authRequestLogin=BASIC");


Put this code at the beginning of an ESP page that performs content changes.

Wednesday, February 9, 2011

Posting non-ASCII characters in web forms

I just hit this issue. You write some non-ASCII text (e.g. in Cyrillic) in a form and when submitted the text appears garbled on the server side.

It turns out this is a well known glitch in web development especially when done in Java. The main reasons for the mess are
  1. Web browsers do not specify the encoding of posted data
  2. Java Servlet specification says that default request encoding should be ISO-8859-1 in contrast to UTF-8 which is universally used nowadays
You can find a good description of this issue here HTTP Form Character Sets and Related Problems.

Tomcat FAQ recommends creating a filter to set the request encoding.

But when using Wicket there is no such issue as they fix the request encoding to UTF-8 as described in How to change the character encoding.

Unfortunately Sling guys did it in another way (SLING-508) which requires me to put a hidden input named _charset_ with the value UTF-8 in all my forms. So they have adopted the ugly IE hack. :(
This is also described in Sling documentation.

I wish Sling had a way to set this to UTF-8 in one place and get rid of it.

Sometimes web development is so frustrating.

Update: Mar 2nd
After picking up this discussion on Sling mailing list the guys there decided after all to make this configurable, see SLING-1998.
Great! My forms now work without the _charset_ hack.