Thursday, April 19, 2007

Rethinking the back buton

Rethinking the back button problem

There are a host of problems when dealing with web browsers that implement a corporate intranet application and not just browsing static content or simple applications like blogs. Here are some typical problems:

- Double clicking and submitting several times the same form.
- Using the back button once or several times and then the user resubmits the form with a warning from the browser.
- Using the back button and then clicking on a link. The link relied on information stored in the user session on the server which is no longer there.
- The refresh button or F5 problem.
- The several navigator windows problem. (Ctrl-n)

There are different ways of solving these problems some more elegant than others. For example a typical way of dealing with the back button is by expiring the page. This works but is not very user friendly. The user ends up either going back again or forward and gets lost quickly.

Another way is to eliminate the back and forward buttons altogether by putting the entire application in another window without the menu items and then providing “internal” back buttons. Well putting an application in another window is clunky; what do you do with the original window? Also the user can always use the backspace and F5 buttons.

A secure and surefire way of dealing with back, refresh, and double clicks is with a synchronizing token. Each form has a unique generated token from the server and only a submission with the same token is allowed. Once a token has been used it cannot be reused. This works real well, but the user is left with a page saying that operation has already been treated. Where does the user go now? It’s not elegant.

Most of these strategies revolve around suppressing the use of these buttons. But there is a possibly a better way! In several of my recent projects instead of restricting things I’ve actually embraced the use of these buttons. Yes it sounds frightening but in the end the users are happier because the browser behaves like the rest of the web and thus there are less user experience problems.

Here’s the basic strategy:

1. Stop double clicks on action buttons with a simple javascript
2. Let users repost if they want to, no token. This could even be a feature. Create 10 things really fast. Submit, back, submit, back, etc.
3. All other links (requests) should contain the entire context in the URL. If context is too big use class serialization and then compression and then post instead of get. This actually works.
4. Redirect on the client and not on the server after creation, modification, or deletion. This eliminates the refresh problem.
5. For things that you really don’t want to resubmit use a token. From a business perspective there might not be that many.

I can write howtos if anyone is interested. Just leave me a comment.

Monday, April 02, 2007

How to log a class with JBoss and log4j.xml

Here's an example of how to log just one class in JBoss.

First in the Java class you want to log com.mycompany.MyClass.java:

if(log.isDebugEnabled()){
log.debug(System.currentTimeMillis());
}


Then in the log4j.xml do not add a threshold parameter to the appenders. I think it overrides all other categories. Instead add a priority value in the root logger.

<appender name="CONSOLE" class="org.apache.log4j.ConsoleAppender">
<errorHandler class="org.jboss.logging.util.OnlyOnceErrorHandler"/>
<param name="Target" value="System.out"/>

<layout class="org.apache.log4j.PatternLayout">
<!-- The default pattern: Date Priority [Category] Message\n -->
<param name="ConversionPattern" value="%d{ABSOLUTE} %-5p [%c{1}] %m%n"/>
</layout>
</appender>

<category name="com.mycompany.MyClass">
<appender-ref ref="CONSOLE"/>
<priority value="DEBUG" />
</category>

<root>
<appender-ref ref="CONSOLE"/>
<appender-ref ref="FILE"/>
<priority value="INFO" />
</root>

Thursday, March 29, 2007

How to always force a download of a file

Here's a way in Java of how to force a file to download instead of opening it up with the associated program. Firefox is OK, the problem usually shows up in IE. The main thing is setting the right header Content-Disposition and content type. Also included is a workaround for a weird bug found in IE if you're in https.


/* patch for IE SSL mode. */
SimpleDateFormat formatter = new SimpleDateFormat ("EEE, dd MMM yyyyHH:mm:ss zzz");
Calendar objDate = GregorianCalendar.getInstance();
objDate.add(objDate.MINUTE,1);
String dateString = formatter.format(objDate.getTime());

res.setHeader("Expires", dateString);
res.setHeader("Cache-Control","store, cache");
res.setHeader("Pragma","cache");
/* end patch */

res.setContentType("application/octet-stream");
res.setHeader("Content-Disposition", "attachment;filename="+filename+";");

Tuesday, January 16, 2007

Why Maven? (continued)

...A little more time has passed with Maven2. Here are more observations.
One of the added values I do see is that Maven2 generates a project site for you with links to the reports of the different goals executed. It's nice to have all of that in one place instead of having to roll your own. Perhaps there is a way to integrate just that part from an ant script?

Oh well, back to limitations that I've found. We've been integrating Maven2 with CruiseControl. So one of the first things we do is unit tests. Great Maven has a goal for that called "test"! Okay, so the first thing we want to do is do an update on the whole project then we want to create the database. Well there must be a Maven goal that does that. Dohhhh!! There isn't. Hmm maybe I can sneak it into one of the other build lifecycle phases via an ant script. Which one? not compile, not generate-source, hmm process-resources? Yeah but that's gonna launch a whole bunch of other stuff that I don't care about. I just want to create the database. And then maybe I want to insert some reference data, and then eventually drop it. It would be nice to do those independently. Yikes! Maven doesn't have these concepts in the build cycle. I guess it's back to ant for the db. That sucks I don't like having two build systems. The developers are already confused enough as it is. In fact when there's a bug the developers want to import the test data the QA team was using.
>mvn ?

...darn ...alright then

>ant db.import.testdata

ahhh, that works!!

The thing I'm getting at is how can a project "pre-define" all the requirements of a software team? It's risky business since things change. Now things are test-driven, agile, continuously integrated, etc... Tomorrow will offer other things. I don't want to wait for Maven to incorporate those concepts. I'd rather just take an ant script example and start from there. In fact Maven kind of feels like the whole heavy J2EE (EJB 1 & 2) where in trying to make something better (ant builds) they make it way too heavy and impose a way of doing things. Sounds familiar? It doesn't feel light and agile. I'm waiting for the backlash and going back to simple things like POA (Plain Old Ant).

Friday, December 22, 2006

Why I hate maven2

Recently at work I've been assigned to come in as firefighter to get a J2EE project back on track. Basically a ton of compile errors before delivery. I did the sensible thing like getting a cruise control server going and getting the developers to write meaningful unit tests. I also discovered they were using Maven2 as their build tool. I hadn't used it before so I was excited to finally have a real project to check it out on.

Well it's only been a week but I really just don't see the added value of Maven's dependency management. I've used a similar system Savant in another project and just junked for doing everything with ant and subversion. The thing that fundamentally bothers me is having two repositories. One is subversion for all the code, scripts, etc, and one is Maven for all your jars or binary dependencies. So you can no longer just checkout a project from svn and build it from scratch. You have to setup a local repository and maybe a remote repository, or connect to the internet. What happens when you want to build on production servers when there's no connection to the internet? The Spring guys have figured this out as well. So far for my projects it's just another layer on top of ant for not much gain. Just version your jars and check them in subversion!!! Also when I start seeing all the same ant tasks being replicated in maven you just have to wonder why???? I already get the creeps with ant when I feel like I'm coding Java in xml (for loops, if then, etc). So I'm definitely going to try to get my next project on something based on Ruby.

Or maybe I just need a little more time

Sunday, October 15, 2006

How to install Joomla 1.0.11 with Mysql 5

Started to get installation errors in step 2 inserting data in the db. Such as:

SQL=BLOB/TEXT column \'text\' can\'t have a default value SQL=# Table structure for table `jos_poll_data`\n\nCREATE TABLE `jos_poll_data` (\n `id` int(11) NOT NULL auto_increment,\n `pollid` int(4) NOT NULL default \'0\',\n `text` text NOT NULL default \'\',\n `hits` int(11) NOT NULL default \'0\',\n PRIMARY KEY (`id`),\n KEY `pollid` (`pollid`,`text`(1))\n) TYPE=MyISAM:- - - - - - - - - -# Table structure for table `#__poll_data`CREATE TABLE `#__poll_data` ( `id` int(11) NOT NULL auto_increment, `pollid` int(4) NOT NULL default '0', `text` text NOT NULL default '', `hits` int(11) NOT NULL default '0', PRIMARY KEY (`id`), KEY `pollid` (`pollid`,`text`(1))) TYPE=MyISAM= = = = = = = = = =


I tried fixing the joomla.sql file like some of the other posts such as http://forum.joomla.org/index.php/topic,103176.msg522184.html#msg522184 but kept getting more errors. So instead to solve the problem I just launched the Mysql instance config wizard and set the database to not be "strict". The installation worked fine after

Friday, September 08, 2006

Interpreted languages taking over

Sun is getting into interpreted languages and even they are jumping on the Ruby bandwagon. This just makes sense. And I believe the fundamental reason is that the act of compilation (on large scale projects especially) does not add enough value.

With agile requirements goes agile development and compilation doesn't add enough value (rigor, security, etc.) for the lost development gain. I see this every day on large projects where compile times are over ten minutes. The development cycle should be as fast as possible and then you compile only for a production environment.

The other main advantage of interpreted languages is no more xml configuration files. Bye bye Spring. Hallelujah!!!! No more java programming in psuedo languages/frameworks. Bye bye ant.
Back to learning one thing, Ruby, and learning it well.

Monday, August 28, 2006

switching from http to https to http with Apache 2.2

Here's how to do it with just using Apache configuration files. The application is J2EE struts running on JBoss 4.0.4GA.

in httpd.conf
make sure the mod_rewrite is activated like this

LoadModule rewrite_module modules/mod_rewrite.so

then add to the httpd.conf

RewriteEngine on
# checks if request is in HTTP and then only rewrites the login pages via a regex
RewriteCond %{HTTPS} =off
RewriteCond %{THE_REQUEST} login\.do.*action=init [OR]
RewriteCond %{THE_REQUEST} login\.do.*action=submit
RewriteRule .* https://%{SERVER_NAME}%{REQUEST_URI} [R,L]

# checks if request is in HTTPS and then rewrites all other pages to http via inverse regex.
# however do not rewrite static content such as images, css, javascripts or else returned page
# will not be 100% HTTPS. All static content under /staticcontent/
RewriteCond %{HTTPS} =on
RewriteCond %{THE_REQUEST} !login\.do.*action=init
RewriteCond %{THE_REQUEST} !login\.do.*action=submit
RewriteCond %{REQUEST_URI} !/staticcontent/
RewriteRule .* http://%{SERVER_NAME}%{REQUEST_URI} [R,L]

make sure that J2EE application is sending client-side rewrites and not just server-side forwards for the login pages or else this will not work because Apache will not get the chance to rewrite the URL's.

That's it!!

Saturday, April 15, 2006

Javascript Databases?

You might laugh at first, "like what...huh?? That's the stupidest thing I've ever heard!" Oracle types, DBA's, and other people generally lacking in imagination have this reaction.

But there is a value play. With the web2.0 there will be more and more need to cache things in the browser. So you think well ok there are cookies. But no, we're talking more than just storing your username and a couple of preferences. We're talking about caching data, like structured text and then being able to query it without having to go back to the server.

For just storage DOJO has a framework and there is AMASS based on Flash to get around the cookie size restriction. But if you want SQL check out TrimPath's TrimQuery. It's very cool and can do basic queries, even joins! But sadly "LIKE" hasn't been implemented yet. There is even a combo TrimQuery + AMASS.

At work we're going to use similar mechanisms but we're custom coding since we need "LIKE". But I'm wondering if there's a way to ditch Flash and do some sort of in-memory thing like a javascript Prevayler with ajax calls to do the updates?

Google Calendar,Virtual Companies, and Perverted Adsense

Calendar
Wow, it finally came out. People have been waiting for it after gmail. And by now we've all come to expect incredible DHTML things from google. It very slick.

At work I tried to have gmail as a frontend to our email backend but the company won't allow forwarding outside the company's domain. It's a shame because I wouldn't need Outlook or thunderbird anymore.

Now I'm thinking how a small (or even large) business could use gmail/calendar/groups/talk/writely/etc. to run their business virtually. If google would acquire or develop a file storage mechanism à la xdrive and incorporate it into google groups then it would basically all be there.

Perverted Adsense
Now I'm also thinking of a real perverted use of google adsense which a large organisation like my company www.atosorigin.com could use. Companies could and perhaps should advertise internally within their web office suite. Everyone is talking about knowlege management and our company has a system but who goes there? There is no real efficient way to get mindshare for new corporate programs, technologies, events, groups, etc. So why not internal advertising using the same auction system that every google ad has. Perhaps google already sells their adsense engine to corporations like their search engine? Or if they don't a startup should build one and sell it to corporations since google adsense works.

Monday, April 10, 2006

Windows Live Mail

Well Microsoft had to respond to Google's gmail. A lot of the people I know have already switched. So I tried out windows live mail from my hotmail account. It's a version of gmail except slower for now. But it almost is like Outlook. It finally has a search and you can select multiple mails with shift-click so deleting a lot of spam is easy!

But when I tried to open it with Firefox what did I get? The Classic version. And then this message:
• If you’re not using Internet Explorer 6.0: Using Internet Explorer versions 6.0 and higher will give you the best Windows Live Mail user experience with access to all functionality such as the reading pane and keyboard shortcuts. Internet Explorer 6.0 is available only for computers with certain system requirements.

I knew MS would do this. See my last post. But I think they're making a crucial mistake. They think that they're Windows Live will keep people on IE and not on Firefox or other future browsers. It's the same mistake that Apple made with their OS. In the end it's the apps that count and not the platform.

Saturday, April 01, 2006

The Web is at a new Inflexion Point

Wow the world is changing and fast. We're definately at an inflexion point. Here's what's going on. The web 2.0 is taking hold. The announcement of Google aquiring Writely just really confirms what is happening. And as Java was associated with the web 1.0, now Ruby and especially the phenominal momentum of Ruby on Rails is associated with the web 2.0. And it is growing exponentially. It seems clear to me now that RoR will eat up the J2EE and .Net market from the bottom up given the number of web hosters that offer rails hosting as well. Within a year rails will be a standard offering like php/mysql and have already made inroads into the j2ee/.net corporate world. The j2ee and .Net world will try to respond but the fundamental problem lies with the language. Java is not interpreted. See my other blog on this "How Rails saves time vs J2EE from an architect's POV"

Here is my view of the coming changes. We will go back to a semi-synchronous client / server architecture except this time with only a dhtml web browser and no more applets, activex, flash, etc. There will be a bunch of web2.0 applications built and then eventually a lot of commercial (Microsoft included) and free web 2.0 competing frameworks will eventually be winnowed down to one or two dominant opensource ones (like AWT and Swing in the Java world).

The big battle will be between Google and Microsoft. Google trying to replace all the MS apps via web2.0 apps (example: writely). MS is responing now but will as usual make their web2.0 apps only work with Internet Explorer. This could strategically be a crucial mistake. Will we then go back to a "service" business model as what was being hyped during the web1.0 dot com era? Something tells me not. I think we'll stay with a mix of paid software products and advertising based revenue streams.

One thing is clear is that all companies will have to upgrade their sites/apps to be web2.0 or they will loose traffic and customers. People are making fortunes now just redoing classic apps in web2.0 form. It truly is the web all over again but with less craziness, more experience, etc.

Saturday, March 25, 2006

How to install apache2 php5 mysql5

This weekend trying to get Joomla 1.0.8 ecommerce edition going.
Already had a mysql 5 installed so I installed php5 (with the automatic installer) and apache2.
All went ok but I got the: "MySQL support Unavailable" when trying to install Joomla.

After googling and then attempting a manual install of php5 which didn't work I went back to the php5 auto install and then simply did the final two steps:
1. in the c:\WINDOWS\php.ini uncomment the line:
;extension=php_mysql.dll
by removing the ";"

2. in the same file change the
extension_dir = "./"
to
extension_dir = "C:\programs\PHP\"

3.dowload the php5 manual installation unzip and copy the files
php-5.1.2\libmysql.dll
php-5.1.2\ext\php_mysql.dll
to
php\libmysql.dll
php\php_mysql.dll

Monday, February 27, 2006

How Rails saves time vs J2EE from an architect's POV

These are my impressions so far
J2EE so far means Struts + Spring + Hibernate

Structure:
In rails the application structure is given. The hierarchy is very clean and simple (controller, model, view, helper). In J2EE there is a WAR structure, a JAR structure, an EAR structure, SAR, etc. All of these different structures take time to setup when you start a project. Also if every you decide to change the structure the refactoring can be a nightmare. Classpath problems, classloading order problems, etc.

Interpreted language:
The fact that the development -> test cycle is so short (like PHP) you can get in so many more development revs. This is huge. Now that projects are test driven anyway I'm wondering what the added value of a compiler is? If the project doesn't compile your tests won't pass anyway. By eliminating the compiler then the whole concept of "continuous integration" is inherant in the language. Why?

1. Source and deployment are one (ooohhhhmmmm). If there's no compiler then your source tree is your deployment tree. No big ant scripts that clean build directories, make build directories, compile, copy all those wonderfully huge and error prone config files, and then make them into WARs, JARs, EARs deployment structures.

2. Codetime and development runtime are one (breathe and repeat ooohhhhmmmmm). If the language is interpreted then there's no deployment. Waiting for the container to start or for Spring to lazily inject all of those dependancies the first time you access a service can take a 10, 20,... 40 seconds? No big deal, but when you do this 200 times a day it just gets developers into the habit of working sloooowwwly. In fact there's no need for that wonderful J2EE ointment Spring. Yeah! no seperate environments: one for development and testing without the container and one for the "real production EJB container" integration environment.

Convention over Configuration:
This just seems like a good design pattern or common sense to me. Like ordering a "Caramel Macchiato". Specifying Espresso with vanilla and caramel syrup on the foamed milk in a grid pattern just takes too long. And you'll probably screw it up so the "Barrista" will then have to ask you if again and you then have to repeat your order again. Imagine if everyone in line did this? The orders would be exact but it would be very confusing, there would be many errors, and it would take a long time. There would probably even be "order consultants" to help you speed your way and books written about how to order. Sounds a lot like J2EE.

So Rails makes it easy for the majority of people to get what they want fast and then let the few demanding types order custom [insert favorite Starbuck's drink here]. We can do this in Java but we don't. Why? The ethos is more about being able to customize and control everything and all possible future extendable combinations first then using Java to build applications.

Thursday, September 15, 2005

Open Session In View Pattern

So far no success. No good examples on the web but the allure is great because it would eliminate a lot of work build hierarchies and the tearing them down going between the business and presentation layer. Same problems that others have encountered. Once I get the solution I'll try to publish a complete example.

Eliminate IE "You are about to be redirected to a connection that is not secure" message

Got this from here:
http://jehiah.com/archive/redirect-to-a-connection-that-is-not-secure

Instead of the 302 redirect, give a 400 responce, and a meta-refresh tag. meta equiv="refresh" content="0;url=http://jehiah.com/"

Wednesday, May 25, 2005

Buzzword compliance in my project

While reading "J2EE without EJB" I'm just wondering how long it will be before the book "J2EE without Spring" comes out. Just joking but not totally. Dealing with all the SpringBean dependancies is almost as much a "meta-data hell" as EJB deployment descriptors. The advantage of testing out of the container is good but otherwise I see the overall productivity problem as just being moved a little and renamed something else.

Otherwise here are the ways that the buzzwords are injected and weaved in our current application.
  • we're using the Spring WebApplicationContext with Struts to get access to stuff throughout the web app. We can say we are using a "lightweight container"
  • we're using Spring Beans to initalize a navigation tree via an XML file. We can say we're using "IoC Dependancy Injection"
  • we're using another Spring bean to have remote access to Session EJB's. For testing we replace them with the Bean classes directly so we don't have to use JBoss thus using a cross-cutting AOP.
  • ... I'm sure there's lots of others that I'm not aware of but I'll try to remember to say "IoC constructor injection" instead of "constructor" until these too are replaced with something else.

Friday, February 25, 2005

MDA is it worth it? And always write EXTERNAL requirements

In short I've found that any potential gains of MDA are done punctually and not globally. Trying to adopt a global MDA approach is too contraining for the architectural choices and will ultimately lead to miscommunication within the team and with the client.

Two of the major drawbacks of MDA are:
  1. Defining a model
  2. The problem of regeneration.
The project that I'm currently working on is large and complicated. Because of this the assumption was made and sold to the client to embrace a "Model Driven Architecture" approach. We were doing MDA not to have different technology choices but given the sheer volume of code needed to be written. By having a model we could then modify the model and the code would be generated. The technology was already chosen from the begining J2EE.

We started by modeling the domain objects and getting the client to approve them as requirements. The user interface and data model would then be extrapolated from the 'domain model". This was a huge mistake. This basically cost the project 15 analysts time for a year. Right now we're trying to implement the model and basically most of the time the model is either wrong, really inefficient, or relationships are not in the right direction.

So I'm now a firm believer in driving the domain model from the outside or the database and the user interface. This is called external requirements. I'm also a firm believer in only specifying and delivering to the client the user interface, data model, and business rules attached preferably to the user interface, datamodel, or messages, etc. Keep all domain object models, internal workings for yourself or else specifications and development will crawl to a halt, getting approval for each internal change. Some clients demand this transparancy but don't give approval, at least if you're on a fixed-bid contract. If you're on a time and materials then do whatever the client asks, the longer a project lasts the more money you make!!

So my best practice is to:
  1. model the database with a good tool like Power Designer and generate the database. Keep the physical model in synch with the actual sql.
  2. define really well the user interface (web, fat client, messages, etc) and all the business rules associated with the user interface events even though they might not be implemented in the presentation layer. Do a real mock-up of all or most of the screens or template screens.
Then think about generating certain things like:
  • once the database is created you can generate persistance objects and Hibernate mappings with Middlegen, or cocoabase.
  • If you have html mock-ups then you can generate jsps with xslt or presentation objects with xmlc
  • using xdoclet for struts is nice and keeps everything in the Action classes. Not the bullshit struts-config.xml
Getting back to the two major problems with MDA, the first being the problem of defining a model. The database model is well specified with entity relationship diagrams. These have been around for a while and most DBA's worth anything speak this language. Page mock-ups are WYSIWYG. No client surprises.

The other problem is regeneration. What happens if the model changes? What happens to your changes? are they lost? Most of the time the answer is yes, unless you adopt a full blown round trip engineering tool like Together or Rational XDE. Personally I favor Together but since they were acquired by Borland the quality has dropped off. I wouldn't recommend anything from Rational. Just way too complicated and very unstable. It will be a while before I'd bet my career on on of their products. So if you think that you're in for an iterative and shifty requirements based project (which most are) then forget about regeneration and make sure that it won't be a major slowdown in the development cycle to always modify the model, regenerate, then compile.

Wednesday, February 23, 2005

XMLHttp

Recently a colleague showed me Goggle's sugget. It's pretty cool and uses xmlHttp. An object that allows you to add to the DOM once in the browser.

In the past to do things like this I've used frames or iframes. The things I didn't like about frames are that you have to deal with frames, framesets, etc. If you've got a simple UI no problem but a lot of my projects have basically been clients that want a fat client in a browser with

Wednesday, January 26, 2005

To DTO or not to DTO ?

It seems like everytime on a project the question is asked again, why are we doing this? Why are we creating all these objects that just copy the attributes from Entity EJB's or Hibernate POJO's to a bean that is then sent to the presentation layer and visa versa. And then there are cries that DTO's are evil and I ask the question all over again. So does the team.

Conclusions:
A DTO provides a way of guaranteeing the scope of what you will send and what you will return between the presentation and business layers. For some domain models this is important for others not at all.

When you can use the business objects directly:
  • The business object in question is at the end of the line. In other words there are no many-to-one relationships or dependancies tied to it. I get the object and I don't have to wonder if I have to get the collections attached to them and the collections attached to them, etc.
  • The business object is just a bean. There are little or no process methods that you don't want to expose to other layers. For example what if there are business methods on the object like reset(), deleteAllStuff(), showBlingBling()
  • Other cases?
Otherwise it's DTO city. Why? Even with lazy loading you still might not want to expose all of a graph of objects to another layer. And then what happens when you want to save or update? What do you persist? The whole graph? only certain parts? How to do define a boundary of the transaction? Well, DTO's or hierarchies of DTO's are a way of limiting the scope of the transaction at hand.

I'm going to check into the "Open Session in View" pattern and playing with Spring's OpenSessionInViewFilter and Interceptor.