Matt RaibleMatt Raible is a Web Developer and Java Champion. Connect with him on LinkedIn.

The Angular Mini-Book The Angular Mini-Book is a guide to getting started with Angular. You'll learn how to develop a bare-bones application, test it, and deploy it. Then you'll move on to adding Bootstrap, Angular Material, continuous integration, and authentication.

Spring Boot is a popular framework for building REST APIs. You'll learn how to integrate Angular with Spring Boot and use security best practices like HTTPS and a content security policy.

For book updates, follow @angular_book on Twitter.

The JHipster Mini-Book The JHipster Mini-Book is a guide to getting started with hip technologies today: Angular, Bootstrap, and Spring Boot. All of these frameworks are wrapped up in an easy-to-use project called JHipster.

This book shows you how to build an app with JHipster, and guides you through the plethora of tools, techniques and options you can use. Furthermore, it explains the UI and API building blocks so you understand the underpinnings of your great application.

For book updates, follow @jhipster-book on Twitter.

10+ YEARS


Over 10 years ago, I wrote my first blog post. Since then, I've authored books, had kids, traveled the world, found Trish and blogged about it all.

Ajax webapps are cool, but non-javascript versions still needed

I think we can all probably learn a lesson from Google. I've heard that GMail is the "gold standard" for Ajax applications. If that's the case, then you should note that they've recently added a "basic HTML" link to the bottom of their pages. With this link, you can view your e-mail using the old way: Yahoo-style, no-JavaScript-needed. My guess is they added it because of demand, or simply to compete with other providers who have this feature. I think it's a good lesson though: use Ajax features in webapps where appropriate, but don't make JavaScript necessary to use your app.

A couple of Ajax features I've been thinking of developing:

  • Saving forms with XMLHttpRequest: just display a success message at the top, and switch the "Cancel" button to "Done". Since the form's content doesn't change, this seems like a reasonable use of the technology.
  • Switching out entire "content" <div> elements. Most of my apps have a <div id="content">, so it'd probably pretty easy to just replace that in response to button and link clicks. Of course, the hard part is having the requested server-side object load the view template, process it, and send back the content. This is probably more trouble than it's worth.

Posted in Java at Mar 07 2005, 07:42:18 AM MST 13 Comments

[TSSS] BOFs, Booze and Benitar

On Friday night, I attended all three of the 7:30 Birds of a Feather sessions. The first one I went to was Spring, where Rod talked about what's coming in Spring 1.3. Rod did a 25 minute presentation on the new stuff and then opened the floor up to Q and A. The session was well attended and I skipped over to the Tapestry/Trails BOF when the Q and A started.

I was surprised to find that very few folks where at the other BOFs. While the Spring BOF had 50+ attendees, the Tapestry one only had around 15-20 and JSF had around 8. I quickly left the Tapestry/Trails BOF when Chris started walking through his Trails Video. He was doing a live version of it, and since I'd already seen it, I figured I wasn't going to learn anything new. I've also been following Trails since it first started, and was more interested in talking about Tapestry.

I walked into the JSF BOF as Ed was talking about JSF 1.2 and what's next for JSF 2.0. This was good timing as I had a few suggestions for 2.0: HTML Templates like Tapestry, bookmarkability (don't make everything a post) and thinking about tools like Tiles and SiteMesh. While neither tools is part of the spec, I think they should be remembered in case there's an opportunity to make integrating with them easier. Ed did mention that JSF 1.2 has pretty much solved the content-interweaving problem, so putting HTML in your JSF JSPs should be better supported.

The very interesting part of this BOF is that Ajax capabilities are very much on the radar for JSF 2.0. They plan on providing native XMLHttpRequest capabilities. My suggestion for this was to provide the setup and registration of requestable class methods as part of the framework, and leave writing the JavaScript to the developer. This was a good BOF and I'm pumped to see that JSF is embracing the next-gen way of developing webapps. Let's just hope JSF 2.0 is released this year and not 2 years from now.

After the BOFs, I joined Matt and Jim to wait for one of Matt's buddies (Scott) to come into town. After he arrived, we headed over to the OpenSymphony open bar at the Bellagio. There, I got to meet Patrick Lightbody and enjoyed several beers and good conversation with the likes of Seth Ladd, Thomas Risberg, Mike, Dion and Christian.

After the open bar closed, Jim, Matt, Scott and I headed just off the strip to the Gold Coast Casino. Matt and Scott wanted to find some poker (tables had a 2-hour wait on the strip) and Jim and I wanted cheap Blackjack. We were pleased to find $5 tables and stayed there for several hours. I don't know what time we headed back to our hotel, but I'm guessing 1 or 2. The rest of the night was pretty funny. Jim and I gambled until 7 in the morning at several blackjack tables. Our hotel had this "celebrity theme", so we had dealers like Pat Benitar and Stevie Wonder throughout the morning. Both of these dealers were great and I got "hooked up" on several occasions. There were at least 10 times where I asked for a card and they didn't give it to me (after which I won b/c they busted). We ended the night at 7:00-7:30 with 5 crisp $100 bills in my pocket. Total cost of the whole trip: $100. Not bad eh?

Getting home yesterday was quite an adventure. After going to bed at 7:30, I woke up by some miracle at 11:00. I don't know if I had a wake up call or what, but my buzz was still in full swing. I caught a cab and headed to the airport. I paid the cabbie with a $25 chip, which he didn't like, but after I told him to keep the change (it was a $6 cab ride) - he happily obliged. At the airport, I took a nap while waiting for my flight to board and almost missed it. They called my name over the intercom b/c I was the only passenger left to board. Luckily, I was awake and made the flight. Upon arriving in Denver, I walked to my car and promptly locked my keys in the trunk. The airport officials got them out for free and I made it home to a very happy family around 6:00 p.m. It's good to be home.

Posted in Java at Mar 05 2005, 06:09:32 PM MST 3 Comments

[TSSS] Days 1 and 2

I'm sitting in the EJB3 BOF right now. The room is packed, but it seems most folks are uninterested and the moderators are just talking amongst themselves. Seems like a good time to blog since this BOF doesn't interest me whatsoever. Yesterday, I arrived at 8:00, took a cab to the Imperial Palace (where we're staying) and then headed over to Caesar's for the conference. I registered, assured we could drink beer during the sessions, and attended the (rather dry) keynote. Hani has a good synopsis of this talk.

After the keynote, I went to Patrick and Jason's WebWork talk for about 10 minutes. I soon realized it was an intro to WebWork and left to try and learn something. I went to Craig McClanahan's talk on "The Development of Web Application APIs and Standards for Java." His talk was pretty good, and covered "de facto" versus "de jure" standards. De facto standards are ones that evolve from the community through widespread usage, whereas de jure standards are imposed on the community (like JSF). Again, Hani has the full scoop on this talk.

Next, I went to Dion and Ben's talk on Ajax applications. They talked about XHTML/CSS and how XMLHttpRequest makes rich client-side applications possible. I think the whole Ajax thing is pretty funny. It's something that's been available for several years and my guess is most folks just didn't know about it. I've been using XMLHttpRequest for a couple of years now, and it's interesting to see it become popular all of a sudden. It's quite nice actually. I've been writing HTML/JavaScript for over 10 years, so I find Ajax development pretty easy. I hope to add support for Ajax-type features in AppFuse before this summer.

I wonder when/if the community will realize the power XSL processing in the browser? Since we're all developing XHTML applications now, our pages are XML and we could easily start leveraging client-side XSLT to do some pretty cool stuff. With a client-side XSL sheet, you could do page decoration (like SiteMesh) just by adding one line to your pages. For example:

<?xml-stylesheet type="text/xsl" href="styles/global.xsl"?>

The only problem with client-side XSLT is your pages have to be well-formed XML or everything bombs. With HTML, if you screw something up, chances are the browser will still render it correctly.

After the Ajax review, I had lunch and headed down to the Casino for some beers and gambling. I came back in time for Rod's "Why J2EE Projects Fail." It was a good talk, but there wasn't any revolutionary or new information provided. After his talk, I was motivated to learn more about Web Services Security, but instead opted for beers with Crazy Bob, JIRA Mike and Neon Dion. A couple of beers turned into several, and I found myself having dinner with the SourceBeat guys (Bill, Matt and Jim) a couple hours later. Steak and Lobster was my plate of choice and it tasted quite good. The rest of the night was spent gambling, drinking and harassing Pai Gow Poker dealers. We had breakfast around 2 and made it to bed by 3. Total cost of the trip so far: $300.

I slept in until noon today, after which Jim and I headed back to the conference for some lunch and afternoon sessions. Lunch was good and followed by Oracle demoing JDeveloper and coding EJB3 and JSF with it. I've often wondered about the cost of Oracle's ADF JSF implementation and actually got an answer from one of the attendees. I think he was an Oracle employee but he basically said you have to buy at least 1 copy of JDeveloper ($999) and you get a runtime license for ADF Faces as part of that. That sucks because Oracle's implementation looks like one of the most full-featured ones available. Why should I have to buy a tool I'll never use just to use ADF Faces?

After lunch, we attended Rod's "Advanced Spring Framework" and Craig's "JSF: Dead on Arrival or Raging Success". Rod's Spring presentation covered some advanced Spring features: autowiring, inner-beans, lists, instantiation choices, factory beans and template bean definitions. The presentation was good, and I was pleasantly surprised to find I knew most of the things he covered. Colin spoke about using JDK 5 annotations for transaction demarcation and Keith talked about Spring Web Flow. The Spring Web Flow stuff looks cool, especially since the other framework developers are listening and liking what they see. Craig even mentioned that he'll probably ditch what he's put together in Shale and use Spring Web Flow instead.

Craig's talk about JSF was rather boring, but most of these sessions are (mainly because there isn't a whole lot of new information). Craig did manage to pimp Java Studio Creator a bit. I find JSC demos to be quite funny since it hides so much code with code-folding. In the demo, Craig showed us a 10-line Java class that made JSF (and JSC) look like good stuff. Jim and I noticed code-folding was turned on and the class was actually 120 lines long! This is more of a problem with JSC then JSF IMO. The one nice thing about this talk was learning that a JSF 2.0 BOF is tonight. The main goal of the BOF is to see what the community wants in 2.0. I hope to attend and express a desire for HTML templates like Tapestry has.

Tonight kinda sucks because all the good BOFs (Spring, Tapestry and JSF 2.0) are at the same time (7:30). I'm hoping to hop around between them and get some good networking in. After the BOFs, OpenSymphony is hosting an open bar - so that should be a good time. Hopefully we can scare up a few free carbombs. For more blogs and coverage of the conference, see the TSSS 2005 blogger list.

Posted in Java at Mar 04 2005, 05:33:59 PM MST Add a Comment

Simplifying XmlHttpRequest with JSON-RPC

In my day job, we decided to use a little XMLHttpRequest lovin' to populate one drop-down from another. This is my review of JSON-RPC, an open source JavaScript library and servlet for simplifying XMLHttpRequest. I considered integrate Direct Web Remoting (DWR) as well, but its java.net site was down the day I needed it. I started out with JSON-RPC 0.7, which caused some conflicts with Commons Validator client-side validation. This was fixed in the 0.8 release. JSON-RPC takes a little more setup than I care for, but it's pretty easy nonetheless:

  1. Download the 0.8 release from http://oss.metaparadigm.com/jsonrpc-dist/json-rpc-java-0.8.tar.gz.
  2. Add the JAR to your project and the webapps/jsonrpc/jsonrpc.js to your projects' "scripts" folder. Include this file in your SiteMesh decorator or Tiles layout. If you're not using SiteMesh or Tiles, it's high time you started.
  3. JSON-RPC currently requires that you register each class you want call methods on. In our project, I registered a Spring bean (LookupHelper) that's a singleton with references to Maps in the ServletContext. Then we used JavaScript functions to call JSON-PRC and look up units for a plant, and vice versa. I'm not going to put the LookupHelper class here - you'll have to trust its methods return a single String or a comma-separated list of Strings. To register this bean with JSON-RPC, I created an HttpSessionListener and configured it in web.xml.

    /**
     * UserListener class used to add/remove session attributes when
     * a user first logs in.  Mainly for JavaScript Remote Scripting stuff.
     *
     @author Matt Raible
     */
    public class UserListener implements HttpSessionListener, HttpSessionAttributeListener 
        private final Log log = LogFactory.getLog(UserListener.class);
        public final static String BRIDGE_KEY = "JSONRPCBridge";

        /**
         * Initializes LookupHelper singleton with values needed for lookup
         *
         @param event the HttpSessionEvent to grab session information from
         */
        public void sessionCreated(HttpSessionEvent event) {
            // Find the JSONRPCBridge for this session or create one
            // if it doesn't exist. Note the bridge must be named BRIDGE_KEY
            // in the HttpSession for the JSONRPCServlet to find it.
            HttpSession session = event.getSession();
            JSONRPCBridge jsonBridge = new JSONRPCBridge();
            jsonBridge.setDebug(true);
            session.setAttribute(BRIDGE_KEY, jsonBridge);
        }

        /**
         * Destroys LookupHelper
         *
         @param event the HttpSessionEvent to grab session information from
         */
        public void sessionDestroyed(HttpSessionEvent event) {
            if (event.getSession() != null) {
                event.getSession().removeAttribute(BRIDGE_KEY);
            }
        }

        public void attributeAdded(HttpSessionBindingEvent event) {
            if (event.getName().equals(BRIDGE_KEY)) {
                HttpSession session = event.getSession();
                // register LookupHelper so we can call methods on it
                ApplicationContext ctx =
                        WebApplicationContextUtils
                        .getWebApplicationContext(session.getServletContext());

                // check for null so we don't have to initialize Spring in tests
                if (ctx != null) {
                    log.debug("Registering lookupHelper for XmlHttpRequest...");
                    JSONRPCBridge jsonBridge =
                        (JSONRPCBridgesession.getAttribute(BRIDGE_KEY);
                    jsonBridge.registerObject("lookupHelper",
                                              ctx.getBean("lookupHelper"));
                }
            }
        }

        public void attributeRemoved(HttpSessionBindingEvent event) {
            // don't care
        }

        public void attributeReplaced(HttpSessionBindingEvent event) {
            // same as attribute added
            attributeAdded(event);
        }
    }

  4. After this setup was complete, I was able to add the following JavaScript to the bottom of my JSP. These are functions that our drop-downs call to populate each other, and keep their options in synch.

    <script type="text/javascript">
    var jsonurl = "${ctx}/jsonrpc";
    var jsonrpc = null;
    var unitDropDown = document.getElementById("equipmentName");

    function filterUnits(plantDropDown) {
        var plantName = plantDropDown.options[plantDropDown.selectedIndex].value;

        if (plantName == "") {
            reloadUnits("");
            return;
        }

        try {
            jsonrpc = new JSONRpcClient(jsonurl);
        catch(e) {
            alert(e);
        }

        // Call a Java method on the server
        var units = jsonrpc.lookupHelper.getUnitsForPlant(plantName);
        setUnits(units);
    }

    function reloadUnits(value) {
        if (value == "") {
            try {
                jsonrpc = new JSONRpcClient(jsonurl);
            catch(e) {
                alert(e);
            }

            // Call a Java method on the server
            var units = jsonrpc.lookupHelper.getAllUnits();
            setUnits(units);
        }
    }

    function setUnits(units) {
        var unitArray = units.split(",");

        unitDropDown.options.length = 1;  // keep "All" option
        for (i=0; i < unitArray.length; i++) {
            unitDropDown.options[unitDropDown.options.length=
                new Option(unitArray[i], unitArray[i]);
        }
    }
    </script>

The hardest part of using JSON-RPC is setting it up. We only experienced minor issues with Commons Validator, but since the JSON-RPC 0.8 release - everything has worked great, on all browsers we need to support. The only thing I don't like about this library is that you have to register objects for each user's session. I briefly looked at DWR and it looks a little cleaner - especially b/c of its Spring integration. The next time we need XMLHttpRequest, we'll probably use DWR just to compare the two.

Posted in Java at Mar 03 2005, 08:44:40 AM MST 8 Comments

Off to Vegas

I'm leaving for Vegas in a couple hours to attend TheServerSide Symposium. It should be a good time, mostly because it's in Vegas - but also because there's going to be a lot of folks to network with and some good sessions to attend. My only goal for this whole 3-day vacation is to attend 5 sessions. I should be able to get most of those in today, so I can sleep in and goof off tomorrow. Of course, since it's Vegas, I might still be up tomorrow when the sessions start. ;-)

Thanks to SourceBeat for the free trip to Vegas!

Posted in Java at Mar 03 2005, 03:47:59 AM MST 3 Comments

Fun with jWebUnit and Canoo WebTest

For the past few days, I've been messing around with jWebUnit and Canoo WebTest at my "day job". I say messing around because I've mainly been trying to overcome perceived bugs with both projects. I'm used to using Ant and both of these libraries "just work".

The problem I had with jWebUnit is that the setOption(selectName, optionLabel) didn't work for me. This turned out to be some sort of conflict with SiteMesh, and when I commented out the SiteMesh <filter-mapping>, everything worked as expected. This is quite strange since I use SiteMesh+jWebUnit with Equinox. I tried to reproduce the problem with Equinox by adding a <select> with <option> elements, but it all worked fine there. I'd blame it on Maven, but I was running my tests from IDEA. As a workaround, I subclassed SiteMesh's PageFilter and stopped processing when the user-agent.startsWith("httpunit"). This is very similar to the JCIFS and jWebUnit workaround we're using.

Before I figured out the jWebUnit/SiteMesh issue, I decided to try my favorite UI testing tool: WebTest. Since we're using Maven, I figured the Maven Canoo Webtest Plugin would be the way to go. This took me about a day to get working (so much for the ol' 10 minute test). Most of the problems where related to the fact that setting the properties didn't seem to have any effect. I ended up writing my web-tests.xml much like I would with Ant - with taskdefs and importing project.properties for the properties to take effect. Last night, after I couldn't get webtest to click a button, I decided to try the same XML file with Ant. I dropped it into AppFuse, changed a few settings and voila! - it all worked! "WTF?" I thought to myself. Turns out the Maven Plugin is from October 2004 and is based on build 543. I ended up rebuilding the plugin to build 733 and then everything worked fine. Here's the patch.

Now that I got them both working, I'm leaning towards using jWebUnit because I can use Java to get the last inserted id (for fullying CRUDing an object). With Canoo, I'd have to use our query interface, add a feature to sort by id (or somehow get the last record added), then click on it to edit the new record. To make matters worse, the API we're talking to right now let's us add records, but we can't fetch them back - no matter what we query by. We've tried both the web services interface and the EJB one with the same results.

Ahhh, the life of an enterprise developer - trying to make 3 systems talk to each other and all of them have broken (or non-existent APIs). For one system, we're actually going through their web interface with httpclient to do CRUD on records!

Posted in Java at Mar 01 2005, 05:09:59 PM MST 5 Comments