Monday, October 15, 2007

JavaRebel: Interesting but still iffy

I tried JavaRebel today and for the most part it does what it says. It was really cool to see a single class updated in Tomcat without Tomcat reloading the application. However, there were a couple of gotchas that I am not sure how to overcome if possible at all.

1. For some reason a fellow developer where I work needed to get the package name of a class at runtime. So we have getClass().getPackage().getName(); Once JavaRebel is in place getPackage() returns null. Remove JavaRebel and it works fine. I assume this has something to do with a class wrapper.

2. I primarily use Stripes and one of the things Stripes tries to do is cache configuration information at startup. For example, to inject a Spring Bean into a Stripes ActionBean I simply provide an @SpringBean for a bean setter. If I decide to inject a new/different Spring Bean into the ActionBean, even though it already exists in the spring context, the class reloads but Stripes doesn't know about it. Is this a JavaRebel flaw? No, not really. As I said, it works as stated. But this does limit the effectiveness for me.

I still think it is slick and I am anxious to see how java development improves for us web developers as JavaRebel improves.

Thursday, October 11, 2007

Stripes Presentation KC JUG Post Mortem

Last night's presentation on Stripes at the Kansas City Java Users Group went well. It was my first time doing that kind of a presentation. There was quite a bit of code to discuss and I wish I'd had more time. Overall I felt that I explained things well and I did get quite a bit of positive feedback from the attendees. I hope that I'll have the opportunity to do more of these types of presentations. I'm considering a JQuery presentation for early next year.

Monday, October 08, 2007

Halo 3 Looks Amazing

I played the original Halo on PC when it came out years ago. Never played Halo 2. Looking at Halo 3 it really looks amazing. Halo was a blast. So would I be nuts to want an XBox just so I can play Halo 3? I'm not a big gamer which is to say that when I do want to waste time I really have to like the game. So I doubt I'd buy a whole library of games if I did purchase an XBox.

Is it worth it?

Spring MVC Seems Overly Complicated

Chris Sawer wrote an article on Using Spring's MVC framework for web form validation. I haven't used Spring MVC a lot so I am not here to say he did it right or wrong. However, if he did it the right way I'm glad I am not using Spring MVC.

I thought it might be a good idea to show an alternative using the same example Chris used but I'll show mine in Stripes. I'm not going to repeat Chris' code here so you can follow along using another tab or open another browser window.

So the first thing Chris mentions beyond the web.xml file is the configuration for the controller bean in servlet configuration xml file. Stripes doesn't require controllers (Stripes calls them Action Beans) to be configured anywhere so we've already saved a bit of configuration.

Next Chris shows the SpringTestController.java and the SpringTestValidator; both of which are required to validate a form. Here is the Stripes version (Since I have no idea what properties a DataBean refers to I'll use my own object):

The code formatting didn't turn out exactly as I had planned so bare with me until I find a better solution. The gist of the post just be understandable, however.


import net.sourceforge.stripes.action.ActionBean;
import net.sourceforge.stripes.action.ActionBeanContext;
import net.sourceforge.stripes.action.RedirectResolution;
import net.sourceforge.stripes.action.Resolution;
import net.sourceforge.stripes.validation.Validate;
import net.sourceforge.stripes.validation.ValidateNestedProperties;
import org.apache.log4j.Logger;
import com.miadidas.model.User;

public class StripesTestActionBean implements ActionBean {

protected final Logger logger = Logger.getLogger(StripesTestActionBean.class);
private ActionBeanContext context;

@ValidateNestedProperties({
@Validate(field = "username", required = true),
@Validate(field = "password", required = true)
})
private User user;

public User getUser() {
return user;
}

public void setUser(User user) {
this.user = user;
}

public ActionBeanContext getContext() {
return this.context;
}

public void setContext(ActionBeanContext context) {
this.context = context;
}

public Resolution doSubmitAction() {
/* The givenData object now contains the successfully validated
* data from the form, so can be written to a database, or whatever.
*/
return new RedirectResolution("We would redirect to a new view at this point");
}
}


And now the JSP, however mine may be a bit different because of the DataBean I was unclear on:


<%@ taglib prefix="stripes" uri="http://stripes.sourceforge.net/stripes.tld"%>
<html>
<head>
    <title>Stripes Test</title>
</head>
<body>
<stripes:errors />
<stripes:form beanclass="com.test.web.action.StripesTestActionBean" method="post">
    <fieldset>
        <p>
            Username: <stripes:text name="username" />
        </p>
        <p>
            Password: <stripes:password name="password" />
        </p>
        <p>
            <stripes:submit name="doSubmitAction" value="Login" />
        </p>
    </fieldset>
</stripes:form>
</body>
</html>


And that's it. To me, its simpler. I'd like to hear what you think.