Java, Software, Web Applications

Learning Struts 2

I have been trying to get to grips with Struts 2 recently. Lesson one: very little of your Struts 1 knowledge will carry over. Lesson two: documentation is skimpy and much less coherent that Struts 1.

My first experience was an hour and a half of bafflement until I saw that I had put the config file (called struts.xml now to avoid clashing with the original framework I suppose) under the web application initialisation folder instead of the root of the classpath (i.e. under WEB_INF rather than WEB_INF/classes). Because Struts 2 is all about the defaults I could not see any issue with what I was deploying until I realised that my application would generate the same error message (Action not in namespace) whether my xml config was valid or not.

This is a problem with XML-driven configuration in general but is also a specific defaulting issue. If the framework is defaulting it should say so rather than just silently defaulting everything. The alternative is to explicitly say what packages are being loaded from config but I think not finding a config file is more likely to be an error situation, after all what application is going to be deployed in the default state if you cannot interact with it? Even if the config file is empty you are still expecting there to be one…

Like most web frameworks the learning curve on Struts 2 is initially smooth as you put together Hello World before hitting a vertical climb when you want to do anything serious. Struts 2 relies a lot on injection via marker interfaces and interceptors in stacks; none of which really map to the Struts 1 world.

The goal of Struts 2 is to have a POJO based framework that is more unit-testable and less linked to the Servlet spec. I think it is successful in this and it is what has kept me perserving with the framework. However to do so it has made a lot of things very abstract and in terms of testing there is has been some headscratching as again a lot of Struts 1 testing strategies (which focus on mocking the various objects) do not really apply.

For example when trying to test whether an Action was correctly setting something in the Session Context I was stumped for a while and ended up using Action Context (something that the documentation on the web described as preferred and depreciated in different sources).

This solution didn’t sit well; after a bit of rethinking I finally got to the point where I decided to implement the SessionAware interface (which provides a Map parameterised setSession method) which worked when deployed but failed unit testing because I couldn’t figure out how to access the value of the session on the exit of the Action’s execute method.

The answer is easy, trivial almost but reflects the different way of thinking the new methodology requires. Since the injection engine will add the Session Context attribute map what goes into the setSession method is actually the container’s Session bound variables. Therefore when unit testing you just create a suitable map (Struts 2 doesn’t seem Generics aware but I presume the type is <String, ? extends Object>) pass it to the action via setSession but then retain a reference and test the content of the Map after the execute method of the Action has been called. It is easy but it is not easy to start thinking like this after Struts 1.

Standard
Software, Web Applications

Highrise

Highrise is the new product from 37signals. I use Tada List and that’s pretty good; Backpack is also good but a bit clunky to use and doesn’t generally wow people.

Highrise though is in a whole new league, on the face of it it is just a nifty web-based PIM that allows you to organise contact information. Useful and a slick as all 37Signals stuff is. However recently I started using it to keep track of the tasks and calls that I have to make as part of moving house. Suddenly the application isn’t just nifty it’s indispensable! Each note is properly dated and related to the contact information. It instantly answers the questions like: when did I call the broker about the mortgage? who do I need to follow up about income guarantees?

Another genius product!

Standard
Java, Web Applications

JSP EL

If there is one thing (and there isn’t; there is so much in J2EE 1.4 that is new on the web front) that has changed in-between the last two years since I worked on JSPs and web applications then it is EL. And hurrah for that.

Combined with JSTL EL provides a really clean syntax for writing JSPs that I feel takes away a lot of the criticism that scriptlet style JSP programming received from fans of, say, templating systems. EL is all you really need if you are doing proper views (of MVC) and compared to the Struts Bean taglib it is much more legible and maintenable. Of course as an addition to the core package this is only befitting. Struts pointed the way but EL is an excellent implementation of the principle.

Standard
Java, Web Applications, Work

Configuration Woes

I’ve had two big problems recently that both stemmed from configuration files. During my first weeks at my new job I just couldn’t get JSP Expression Language (commonly known just as EL) to work. Despite following the examples and the tutorial to the letter the results were always garbled and never quite what was described. However when I generated a new web application and deployed it the EL worked fine.

The answer turned out to be the servlet version specified in the web.xml (which is generated by XDoclet rather than being a single file that could have been checked immediately). Specifying version 2.3 in a version 2.4 container apparently just results in flaky rather than disabled behaviour.

Failing at the time to get EL to work I decided to stick with the Struts Tag Libraries as while I was no more familiar with them than the new JSP functionality, it is more likely that an entirely container-independent solution will work across platforms and containers.

However Struts gave me my second problem with the issue of having a 1.1 Struts jar but a DTD specifying 1.0. What I noticed about both problems is that there was no clear kind of error message or clue as to what was going wrong. I only noticed the issue with the Struts config when I had a clear example of 1.1 compliant behaviour that was not present in the app. With EL it was almost entirely random as I was actually looking at the construction of the Security element of the Descriptor.

My latest example of configuration creating as many headaches as it can solve come from a very simple source. I forgot one word (“jsp”, if you are curious) from the URI of a Tag Library and as a result wasted an afternoon trying to get something as simple as Number formatting to work. Apparently JSTL 1.0 didn’t allow you to specify an EL expression as a value to format. Which is both silly and confusing. The syntax for both was identical and because I was using a 1.1 implementation the code introspection implied I had the whole tag correct, it just threw a massive exception trail at runtime.

In all these cases what I found frustrating was that there was no issue at all during the build and development of the application. All the issues were found at runtime with a need for the whole system to be configured and functioning before I could test whether I could locate a variable or not. The other is that there was no real error message that conveyed the fact that I was trying to do something that was illegal for the version declared but possible for at least one of the versions available. Instead the developer has to have a strong knowledge of the feature set of each standard version and the way each feature is configured in either the container or the application.

Configuration of application runtime via XML is a powerful tool but without a way of validating that what you are specifying is correct prior to actually using the application it is actually a massive hindrance.

Standard
Java, Web Applications

Learning Struts

In my new job I have been having to catch up on a lot of web tier technology that quite frankly I have not had much to do with for the last two years of Swing and EJB. I looked at Struts two years ago while doing an intranet application and thought that it was very heavyweight and would add to the development not subtract. However I did adopt the Front Controller idea along with the idea of views (although I think I may have munged the Models, I can’t remember now).

My first experiences with Struts was very poor, it was everything I feared it would be. Heavyweight, huge learning curve, lots of coding, all the code having to be completed up front before you could test things like the URL mapping. Everything you try to avoid in web programming these days!

In addition all the books and documentation I have been reading give a very poor idea of how to implement basic web applications with Struts. They present a very particular view of how Struts should be used and instead of focussing on the Front Controller pattern and the decoupling of components they tend to focus on gathering up and validating user input.

However today I felt like I had a breakthrough. I was trying to get a DynaBeanForm to work and I suddenly noticed that my MyEclipse XML editor was not presenting the options I was expecting from the documentation. A sudden brainwave and I was checking the DTD definition. Sure enough someone had upgraded the Struts code to Version 1.1 but left the DTD at 1.0. Cue much misery on my part trying to figure out how things were meant to be put together.

With DynaBeans and DispatchActions up and running I probably found myself being more productive in the last 12 hours than I was in the previous week.

The jury is still out on Struts for me but I have realised that I can’t take too much from just one experience of a product, particularly in an installation you haven’t been involved with.

Standard
Macbook, Software, Web Applications

MacBook Word Processing Part Two

Well now, hold the line, since writing my last post Writely finally opened for registrations again, NeoOffice posted Beta 2 and I also decided to give Mariner Write a go.

So then, first impressions? Well first of all NeoOffice Beta 2 is a big jump up. Performance is much better and the whole thing looks a lot slicker while retaining the great OpenOffice functionality I know and love. This is such an improvement that I am not sure I need to use something lighter like AbiWord.

Writely is something I have been waiting a long time to use as I only heard of it after the Google buyout when they closed registrations. So does it live up to such long held expectations? Well the short answer is yes in that I am not disappointed by it in the least at the moment. Naturally as a web-based word processor it has its strengths and limitations. I certainly like being able to snatch a moment at work to write something up and not have the hassle of working with a USB drive or anything similar. I haven’t tried the ODT export yet but if it works as advertised then the integration with OpenOffice is going to be a big win for me as it will allow me to mix the applications while keeping the data consistent.

So far Write just isn’t getting a look in although I did download the Mariner MacJournal software at the same time and that looks quite good.

Standard
Swing, Web Applications

Todo Lists Todone

While having a look around at some functionality to help define my proposed Swing Todo List application I discovered Tada Lists from 37 Signals.

What a totally awesome app! Almost immediately my desire to get coding on my application died a death as I was no longer “scratching my itch”. In fact there is still some point to doing a lightweight ToDo list application I can take around with me on a pen drive but I have to say for most of my day to day stuff I have switched to using Tada. After all almost any work situation is going to find you connected to the web for other reasons.

Standard
Blogging, Web Applications

WordPress versus Blogger

Blogger may be the original but even after a short period using WordPress I am starting to feel it is far from the best. The first thing to impress was that WordPress actually seems to generate decent HTML rather than Blogger’s colossal fudge of a single paragraph with line breaks in. This extends to the editor which I think is far easier to use than Blogger’s equivalent purely because it is closely linked to valid HTML which allows things like the Path bar to tell you exactly where you are from a syntax point of view and allowing to avoid formatting issues due to tag soup.

WordPress’s idea of using categories to divide a single blog rather than Blogger’s multiple blogs per account is a less clearcut idea. On the one hand it is really convenient because the tags serve multiple purposes as they help categorise but they also help publicise your posts. On the other hand I would like some threads to actually exist in a separate blog with different templates and settings (say) but which I could still control through the same dashboard.

One feature that really surprised me was that WordPress offers far better searching information both about people visiting your blog and which posts were popular. This is really Google’s bread and butter but Analytics is way overkill for just running a blog.

Another thing that surprised me is that far more people visit and read my WordPress blog than my blogspot ones. Checking with a few searches seemed to tell me why. The Categories first of all drive a certain amount of traffic but the real answer is that Google’s PageRank does not seem to do all that well with blogs at the moment. If you look at most of the blogging search sites then they tend to work on the basis of returning everything about the keywords you’re using, matching them as closely as possible rather than trying to make a judgement about how popular they are.

With the Blogspot searches going off how many links there are to a post it skews the searches to the more popular blogs or listings and not those that match your interest most closely. Until someone introduces a Digg style way of rating blog posts popularity in terms of linking does not seem a good judge of whether the posting is relevant or not. If I want to search for posts on say Tube station names then I want to see posts actually about names before, say, a popular blog about Tube Stations in general.

Anyway the upshot is that WordPress is currently my fave of the blogging tools and has a distinct edge on its rivals in all areas not just a couple. Google really needs to give Blogger a kick up the arse because as a company it is way behind the standard the other Google purchases are at.

Standard