Seam, a second look at JSF
10 Jul 2008 22:04 - (0) comments
I decided to have another look at JSF by reading the Tutorial. The last time I used JSF was 2 years ago (I thought it sucked then). Maybe it has improved with Seam.
Besides almost falling asleep from all the xml I did notice Seam supports Ruby style templating Strings(example 1.2), which is sort of nice.
I'm not sure if you can use simple java oneliners though.
A couple of things that suck:
- Validation of required fields in views (Example 1.7)
Username: <h:inputText value="#{user.username}" required="true"/>
- Session beans require an interface. Let's define everything twice!
- Displaying a simple date requires 120 chars (Example 1.12)
<h:outputText value="#{msg.datetime}"><f:convertDateTime type="both" dateStyle="medium" timeStyle="short"/></h:outputText>
- Configuration in the views and confusing prefixes.
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
- Removing duplication from views sucks because you can't extract methods.
I actually forgot how much JSF sucked (I remember it was hard to test).
The biggest problem is that it's been developed by someone who doesn't use it to write real applications.
It's full of crappy implementations of concepts that seem like a good idea from an ivory tower.
Here is a script that generates the same application in Rails(2.1), it's just a bit longer than just the web.xml from the seam example:
puts `rails seam`
Dir.chdir "seam"
open('config/database.yml', 'w') do |f|
f << %{development:
adapter: mysql
socket: /opt/local/var/run/mysql5/mysqld.sock
database: seam
username: dev
password: dev}
end
puts `rake db:create`puts `script/generate model user username:string password:string name:string`
open('app/models/user.rb', 'w') do |f|
f << %{class User < ActiveRecord::Base
validates_length_of :password, :in => 5..15
validates_presence_of :name
validates_length_of :username, :in => 5..15
validates_uniqueness_of :username
end}
endputs `script/generate controller Register`
open('app/controllers/register_controller.rb', 'w') do |f|
f << %{class RegisterController < ApplicationController
def index
@user = User.new(params[:user])
render :action => :registered if params[:user] && @user.save
end
end}
endopen('app/views/register/index.html.erb', 'w') do |f|
f << %{<html>
<head><title>Register New User</title></head>
<body>
<%= error_messages_for 'user' %>
<% form_for @user, :url => {:action => :index} do |f| %>
Username: <%= f.text_field :username %><br />
Real Name: <%= f.text_field :name %><br />
Password: <%= f.text_field :password %><br />
<%= submit_tag "Register" %>
<% end %>
</body></html>}
endopen('app/views/register/registered.html.erb', 'w') do |f|
f << %{<html>
<head><title>Successfully Registered New User</title></head>
<body>Welcome, <%= @user.name %>, you are successfully registered as <%= @user.username %>.</body>
</html>}
endputs `rake db:migrate`
Comments
No comments allowed.