Recreating RJS templates in Java: The beginning...

by Tim O'Brien

Port RJS to Java. Ugh. i dread this task. I really do. Recreating RJS templates in Java....Yuck. I dread this task because I made fun of the prospect of some Java programmer having to recreate RJS in Java a few weeks ago on this blog, but, I've created an application in Rails that must be ported to Java. Don't ask why, just know that it must be ported to Java. This isn't the first time, I've had to port something from Rails to Java.

So.....errr.....what does one do if your Rails "prototype" makes heavy use of some of the most advanced features of RJS templates and you have to migrate to Java? My first thought: ask the fine readership of this blog if they have found themselves in a similar situation, or, better yet, is anyone out there already doing this? C'mon, I can't be the only one in this wide world who has been using RJS and wondered, "Why can't I do this in my Java application?" ....The first step, Google "RJS in Java" - that search returned a few hits, but mostly links to Rails RJS pages and links to blogs bemoaning the fact that Java isn't there yet.

The real lesson here is "Never prototype with a technology more capable than the target platform." So, take this as a lesson, if you are using Rails as a prototyping language, don't use RJS, you'll end up wishing that your prototyping technology was your production technology. As I've said before, J2EE is a trusted, capable platform, and in some ways it is lightyears ahead of Ruby, but, as far as web applications go Rails does laps around Java. So, maybe porting RJS to Java might help level the playing field? Maybe? Who knows, all I know is that I'm not the only only who thinks that Java is not Web 2.0.

Read on for the options...

16 Comments

roberthahn
2006-08-06 16:39:01
So, assuming that you're doing this either for a client or your employer, is recreating RJS in Java more cost effective than simply using Rails? Have you been able to demonstrate, on a cost basis(either hourly or a dollar cost), how much they'll be in for on either alternative?


I'm not asking this from the standpoint of a Rails fanboy - if Java's the best platform for building the solution, then who is this random poster to say different? On the other hand, if they don't know that they're asking for a high-risk, high cost port of a proven solution, then they really ought to know that, because you'll otherwise put the project in jeopardy.


And if it isn't high risk or high cost, why are you writing this again? :)

Tim O'Brien
2006-08-06 17:30:52
Robert, good question. The motivation in this instance is an organization's goal to standardize on a single production platform. And, from this perspective it does make some sense, organizations plan for a specific production platform, they hire developers for this platform, the operations team has experience deploying to this platform. But, you are certainly right, the risks and costs need to be calculated and communicated.


Personally, I'd really like to have RJS-like features available to me in a Java application using a similar approach. It is a gap that needs to be filled; hopefully, I can interest others in the effort.

jherber
2006-08-06 19:55:29
Might be faster to port their other Java web applications to Rails ;)


http://article.gmane.org/gmane.comp.lang.ruby.rails/24863

Ulrich Weber
2006-08-06 23:52:35
@jherber
http://article.gmane.org/gmane.comp.lang.ruby.rails/24863


>>>
Here are some figures from today's most recent SVN pulls:


Java version:


10361 lines of Java code
1143 lines of JSP
8082 lines of XML
1267 lines of build configuration
-----------------------------------------------------------
20853 TOTAL lines of stuff


Rails version:


494 lines of code (386 "LOC" per rake stats)
254 lines of RHTML
75 lines of configuration (includes comments in routes.rb)
0 lines of build configuration
>>>


Comparisons like that are bollocks if you count the getters, setters and instance variables for the persistent Java-classes. Those getters, setters and instance variables are automatically created by J2EE-Tools available in Eclipse, Netbeans and IDEA.


And by the way: DRY is Bullshit!
I want to see the fields of my persistent classes including the Javadoc in my sourcecode. Why should I consult the SQL-script for that? I really like to know how RoR-developers are documenting their programs if no information about the structure of the persistenct class (ActiveRecord) is available.


@Timothy


> From what I can see GWT isn't something that augments an existing web application, it takes it over.


Just the opposite is true.
You can write the server-part in PHP, Perl, C++, Asp.Net, Ruby, Python, Java or whatever. All you need is a RCP- or JSON-connection to the client. I wouldn't call that a "taking-over". GWT gives you an incredible flexibility. You can even combine an existing web-application say the HTML-part with GWT. You can "ajaxify" any existing static or dynamic page with GWT.


What's about connecting phpBB or MediWiki with a GWT-frontend and reusing the existing PHP-infrasture say the tables, images, skins?

Ulrich Weber
2006-08-07 00:12:45
Just an addition:
phpBB has 60 tables. The 2 biggest tables have around 60 fields. Now have fun with Ruby on Rails. RoR is like going back to the eighties. Some years ago I wrote my programs with MS Access openened because I had to copy and paste the names of the table-columns in my programs. You have to do the same with RoR!


Additionally I had to deal with much bigger projects i.e. tables having up to 250 columns (!!) I guess RoR-fanboys are never writing bigger projects. How will you deal with such schemes?


Welcome back to stoneage with Ruby on Rails! There is no excuse and no justification for DRY. Maybe it is good enough for writing some Mickey-Mouse-applications.

Tim O'Brien
2006-08-07 05:01:12
@UlrichW, you are right, Rails can't handle applications with more than 2 tables. And, last time I checked every *great* application had at least one table with more than 60 columns. And, even better, *bigger* projects have tables with up to 250 columns. (Huh?) And, DRY, I mean, what's up with that, I like repeating myself as much as possible, I like repeating myself as much as possible. If I were you I'd stick with PHP, PHP is really the ultimate web application platform, by far.

2006-08-07 13:46:57
Ulrich... first off if you want to know the fields available to you in an ActiveRecord class look at the db/schema.rb file that is autogenerated for you when you use migrations. Or you can look at Dave Thomas's Annotate Model's plugin.


Also I would suggest you learn about a concept called "normalization"

Ulrich Weber
2006-08-07 22:13:08
> Also I would suggest you learn about a concept called "normalization"


I have no control over the table-scheme. It is an existing table-scheme used by a standard-application for transport/logistics.

sroach
2006-08-08 05:39:54
Take a look at taconite framework. It gives you the abstraction and it's not framework dependent. http://taconite.sourceforge.net/ Take a look at the examples and you'll see how easy it is to use
Tim O'Brien
2006-08-08 06:23:53
@sroach, definitely a step in the right direction, but not close enough to what I'm looking for. If insertion, deletion, and replacing was all I was looking for than this would be a good option, but, unfortunately, I'm looking for much more than the operations that framework exposes. Also, I'm looking for something that is going to work with Prototype transparently - from the examples, Taconite requires some JS setup. Also, I need to ability to push down arbitrary JS if needed. Taconite is a good start, but compared to RJS it's not there yet. But thanks. Don't get me wrong, it's an interesting idea - and Taconite could be cannabalized to creating something more capable.
sroach
2006-08-09 06:26:42
The spring modules team have done some of the things you are talking about with taconite. Personally I don't feel that Javascript needs to be on the server side. https://springmodules.dev.java.net/docs/reference/0.5/html/xt.html#ajax
Also, I'm not too familiar with RJS, can you tell me what RJS has, I might have some other ideas.

2006-08-14 05:11:11
2. Recreate RJS in Java. [...] I'm also resigned to the fact that this approach is: A. Very derivative of rails [...]


What's wrong with being derivative of Rails? If it's a valid and effective solution, I don't care where it comes from: what's right is right.


Dave

Tom Jordan
2006-08-18 13:48:12
Why don't you try running your rails app under JRuby?
Dave
2006-10-03 21:00:52
I'm curious. In what ways is Java lightyears ahead of Ruby?
@Dave
2006-10-04 04:20:27
> In what ways is Java lightyears ahead of Ruby


Oh, man, I'm just curious, how long have you been developing, let's start from the top. First, performance, read the latest interview with Nutter-Bini-Enebo, read various threads in the Ruby community, performance is an afterthought in Rubyland. While Java's VM might not be the fanciest of poodles it has been around for a decade and runs solidly for large institutions in a massively clustered environments. (I'll take clustered JBoss on a 32-way machine over running a bunch of mongrel clusters any day, anyone telling you otherwise is trying to sell you conference seats)


Then there is the level of support and the number of choices in the Java community. I just had to reevaluate web frameworks this weeks, and, in Java, I had at least ten major players to choose from. Each of those with a range of 2-6 years of code time behind them. Then there is the idea that if I need to do something like transform objects to XML - there are about 10 different approaches, all of which have advantages and disadvantages from a performance perspective.


Then there is real world installation, configuration, optimization experience. From monitoring to clustering, Java is lightyears ahead of Ruby in this space.


Ruby's just begun, it's a bright kid, I use it all the time, I try to seel it to people whenever I can. But contrary to the bevy of speaking consultants who roam the country, I'm going to tell you that DHH is wrong when it comes to counting Java out as a dead end.

JohnD
2006-12-10 07:56:55
If Rails is not ready for high-volume apps, is there some combination of Rails and Java that would make sense? Like what about using Java to create Web services that broker the database(s) on the back end, then having Rails models that abstract those services? Maybe ActiveRDF is doing something analogous to part of that. Or does that not deal with the part of Rails that isnt scaling?