Tuesday, 8 March 2011

Why doesn't EL work in my JSPs ... answered

So, you're working away on a relatively legacy application ... and you decide that as you're running the application in a new-ish (think Tomcat 6 level) servlet container, you might as well actually use some JSTL.

Makes sense right ? Course it does !

So you go and add it, all good. Then you pre-compile your jsps and deploy, and your met with:

${user.name}

in your jsp ... Hmmmm what could be the matter ?!?!? (actually it was more WTF, but hey)

Well, it turns out that, the DTD referenced in the application web.xml was out of date (was referencing 2.3), and hence none of the EL functionality is enabled by default !!

The solution is to either update your web.xml to reflect your container, OR if you can't follow the directions in the link below to add EL support.

Frankly, the mapping of servlet containers to JSP and JSTL versions, and associated jars, is not trivial. Fortunately, someone else has done a fantastic job of pulling all the information together:

http://tech.zhenhua.info/2009/01/version-matching-of-jsp-jstl-and.html

Thank you Gerald !

Friday, 21 January 2011

Wildcards in Struts2 actions

Wildcards, and their possible applications in Struts2 action mapping are both diverse and powerful. More so than a lot of the content out there give them credit for, and more than I thought the were.

Rather thatn attempt to explain it all here, just go read the article here: https://cwiki.apache.org/WW/wildcard-mappings.html

there is also an article on what to do about ambiguous matches here: http://stackoverflow.com/questions/1742076/what-can-i-do-about-ambigous-wildcard-patterns-in-struts

Wednesday, 19 January 2011

Help debugging Struts 2

They say you learn something everyday, but today I genuinely did !

It turns out that there is a plugin included in the Struts 2 distributation that lets you browse the loaded configuration. This includes:

  • Configuration settings
  • Loaded jars
  • Namespaces
  • Mapped actions for each namespace
  • Interceptor stacks
  • Validation hooks 
  • and many other useful things.

So, to make it work, you simply drop struts-config-browser-plugin-2.x.x.jar into your application path, and restart your app. You can then go visit: http://yourhost/yourapp/config-browser/index and there it is !

NB: If you are using sitemesh or equivalent with a global /* decorator, you may see some odd rendering. I had to change my config around a bit to prevent sitemesh decorating these pages.

Warning: This may seem obvious, but ... make sure you don't put this out into production (or even QA for that matter).

The full details on how this works can be found here: http://struts.apache.org/2.2.1/docs/debugging-struts.html

Monday, 17 January 2011

Taming the Spring JavaMailSender / GMail beastie

Programatically sending email in Spring (I'm talking about Spring 3.0.x here) really isn't too hard, you just wire up the JavaMailSenderImpl and off you go, right ?

Well, yes ... except when you want to use a GMail type account.

It's not that it's hard, it's just that there's a lot of examples out there that nearly work .... so here's the defintive guide that worked for me.

We'll get onto the spring configuration in a minute, but first a word on jars. To make this work you really need the latest and greatest JavaMail (1.4.3), and (if you don't have it JAF (1.1.1)). Go here for mail goodness: http://www.oracle.com/technetwork/java/index-jsp-139225.html

Now, onto the configuration. NB: This is only the spring config, I'm not going into any detail about how to use the MailSender, if you need help with that, go google.

There are two different configurations, depending on the google mail type you are using. If you are using Google Apps mail (think http://mail.google.com/a/yourdomain.co.uk), then this is for you:


     
    
    
    
    
    
        
            true
            true
        
    



If you are using good ol' GMail, then this is for you:


     
    
    
    
    
    
        
            true
            true
        
    


Oh, and here's a final nugget to keep you going ... If it's all going south, and you need to peek under the proverbial, then add this to the javaMailProperties section, and you'll get protocol level debug to STDOUT - which can be really helpful.


    
        ...
        true
        ...
    

Tuesday, 11 January 2011

Syntax Highlighting in Blog posts

I wanted to know how/if I could apply some pretty syntax formatting and highlighting to code snippets in blog posts.

If you want to know how, go look here: http://www.craftyfella.com/2010/01/syntax-highlighting-with-blogger-engine.html

Making NOT NULL columns nullable again in Firebird

I came across the need to make a NOT NULL column nullable again recently, and was somewhat suprised to find that it's actually a little harder than you might think in Firebird SQL.

take the following ficticious example:

CREATE TABLE pointless
(
    widget VARCHAR(40) NOT NULL
);

now, in, say Oracle, I would simply do this:

ALTER TABLE pointless MODIFY COLUMN widget VARCHAR(40);

et voila !!

Turns out you can't do that in Firebird, so I had to do a little digging. It turns out that Firebird internally handles NOT NULL columns as constraints, and you have to drop the constraint to remove the not null clause.

The full explanation of what to do, and why is here: http://www.firebirdsql.org/manual/nullguide-alter-pop-tables.html#nullguide-make-column-nullable but for those of you masses that just can't wait, try this:

SELECT rc.rdb$constraint_name
FROM rdb$relation_constraints rc
JOIN rdb$check_constraints cc
ON rc.rdb$constraint_name = cc.rdb$constraint_name
WHERE rc.rdb$constraint_type = 'NOT NULL'
AND rc.rdb$relation_name = 'tablename'
AND cc.rdb$trigger_name = 'fieldname'

Substituting the table and column names as appropriate. The resulting row will give you the internal constraint name that you can simply drop as follows:

ALTER TABLE tablename DROP CONSTRAINT constraintname

Job done !

Sunday, 2 January 2011

XSRF protection using Struts 2

I was recently ferretting around for different ways to handle XSRF protection in Struts 2.
(an explanation of this can be found here)

I was curious to see what other people are doing around this, but it seems that (as I expected) the general best practice still seems to be around unique token submission - which is fine.

At the same time. it dawned on me that I've not come across too much on how to do this with Struts 2.
But, fear not faithful readers, this blog entry here http://nickcoblentz.blogspot.com/2008/11/csrf-prevention-in-struts-2.html sums it up nicely.

Incidently, this guy also deals with several other Struts 2 topics in his blog, worth a look.

Thursday, 2 September 2010

ASCII escaping UTF-8 character encoded files.

Every now and again, I need to convert UTF-8 encoded files into their ASCII-escaped equivalents, and then I find myself reaching for the search engine to try to remember what it was that i used last time. So I'm writing it down this time ....

Specifically, I'm talking about converting natively encoded translations into ASCII encoded that that can be used as Java resource bundles.

There are lots of ways to do this, you can even roll your own code, but the simplest is to use the tool that ships with the JDK ! It's called native2ascii

For a full description of how the tool is used, go here: http://download.oracle.com/javase/1.5.0/docs/tooldocs/windows/native2ascii.html

As a quick reference, you just do this (assuming the $YOUR_JDK_HOME/bin is on your path):

native2ascii -encoding utf-8 translated_ru.txt messages_ru.properties

Sunday, 13 June 2010

Developing for the iPhone ... HTML5 or ... the App Store ?

We've been looking at developing mobile interfaces for some existing apps recently.

Obviously the ususl questions come up - which platform(s) ? / market coverage ?, and as ever there is no simple answer.

When you inevitably talk about the iPhone as a platform, you have to consider that it has a closed delivery system (the App Store). Is the investment in buiding the application (which could be rejected !) is worth it ?

The iPhone is, however, unique amongst other platforms in so much as it offers html extensions that produce a native looking widget set. One of my colleagues found this link that succinctly describes how to use the power of HTML 5 to do more thsn you might think possible.

Go have a look at - http://sixrevisions.com/web-development/html5-iphone-app/

Monday, 29 March 2010

Debugging Custom Install4j Screens

Install4J is a great bit of, Java based, installer software from a company called EJ Technologies (who also happen to publish the fanstastic JProfiler profiling tool) .

As part of the install process, you can create custom Java 'screens' that allow for the addition of non-standard functionality. These work really well, but what if you ever need to debug a screen in your IDE ?

Fortunately, there's a relatively simple way to do this, see here: http://resources.ej-technologies.com/install4j/help/api/