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.
You searched this site for "java". 1,588 entries found.

You can also try this same search on Google.

Denver JUG and Rock Bottom Brewery

Last night was a fun night. First of all, Mike Clark spoke about TDD development at the DJUG and he wowed me with his presentation abilities. I think he could have presented on just about anything and it would've been entertaining. He had a fair amount of humor in his presentation and came off as a true Montanan (a.k.a. very cool guy). I talked with him after the meeting as a whole bunch of us were entering Rock Bottom Brewery and my suspicions where confirmed. I look forward to the next time I hang out with Mike.

At Rock Bottom, it was all about drinking beer and bullshitting about Java. I sat across from Rod Cope (Out of the Box) and next to Bruce Snyder (Geronimo/Castor). The topics ranged from Groovy (Rod is speaking about Groovy at the Denver NFJS) to Spring to Castor and Kids (Bruce has a little one that's a week and a half younger than Abbie). I had a great time talking to these guys and look forward to our next meeting. It won't be long until I see Bruce again - he's attending SD West next week. He reminded me that next Wednesday is St. Patty's day, so since I'm part Irish - it should be a fun night. St. Patty's day is also both my sister and Julie's sister's birthday - neat eh?

I didn't leave downtown until 1:00 a.m. - a great Java-infested night it was. Thanks for the conversations and the booze folks - I had a great time.

Posted in Java at Mar 11 2004, 05:56:16 AM MST Add a Comment

Replacing line breaks with HTML breaks in Velocity

Roller currently has an issue where line breaks in comments are not auto-converted to <br>'s. This problem only exists in the in-page comments and the twisty comments you see on this site. Today, I might've figured out the solution. It turns out that using Jakarta Common's StrutsUtils to replace new lines with <br>'s doesn't work:

#set($comments = $stringUtils.replace($comments, "\n", "<br />"))

However, using the String.replaceAll(new, old) in JDK 1.4 does work:

#set($comments = $comments.replaceAll("\n", "<br />"))

I figured this out on my current project and haven't tested it on Roller. Since I didn't find anything on this via Google - I though y'all might be interested.

Posted in Java at Mar 10 2004, 03:58:26 PM MST 6 Comments

Groove Systems: Cheap Java Hosting Provider

Spotted on the WebWork Mailing List today. Groove Systems (Rick Salsa's employer) has some nice hosting solutions. I currently pay $30 (Canadian) for 200 MB, 5 GB Transfer and my own JVM at KGBInternet.com. Keith (at KGB) rocks because he is always quick to respond to any of my issues and always tries to help me out. However, I have to admit, Groove's Grooviest package looks pretty nice. For the same price ($30 Canadian), you get 1 GB space, 15 GB Transfer and your own JVM.

The only question I have is how much memory do you get? Keith does nothing to limit memory usage, so I'm currently set at a 512 MB max heap size. Who knows if I'm using it all, that's just what I'm set at. Oh and one other thing you might like to know:

... right now you can get a 32meg private jvm for free.

Read the read e-mail from Rick for more info.

Posted in Java at Mar 10 2004, 12:54:11 PM MST 3 Comments

[DisplayTag] Changing a row's CSS class based on values in the row.

One request I've seen on the displaytag-user list a few times is the ability to change a <tr>'s CSS class based on a certain value. While the displaytag doesn't have this feature out-of-the-box, it is possible (and fairly easy) to do. All you need to do is sprinkle a little JavaScript into the mix. Basically, the displaytag will render a well-formed HTML table - like the following:

Username First Name Last Name
mraible Matt Raible
tomcat Tomcat User

By adding an "id" attribute to your table (i.e. id="user"), your table will get an "id" attribute and now you can easily access it via the DOM. The following JavaScript will grab the table and search the first column for a value of 'mraible' - and if found, it will change the row's background color to red.

<script type="text/javascript">
<!--
    var table = document.getElementById("user");    
    var tbody = table.getElementsByTagName("tbody")[0];
    var rows = tbody.getElementsByTagName("tr");
    // add event handlers so rows light up and are clickable
    for (i=0; i < rows.length; i++) {
        var value = rows[i].getElementsByTagName("td")[0].firstChild.nodeValue;
        if (value == 'mraible') {
            rows[i].style.backgroundColor = "red";
        }
    }
//-->
</script>

You could easily change rows[i].style... to rows[i].className = if you want to assign a new CSS class. Now let's see it in action (and see if your browser supports it). This has only been tested in Safari and Mozilla on OS X.

Username First Name Last Name
mraible Matt Raible
tomcat Tomcat User

Other displaytag tips: Static Headers HowTo and Highlight and allow clicking of rows. The 2nd tip (highlighting) is available in AppFuse, in the userList.jsp page.

BTW, I also added support for the DisplayTag to render the results from JSTL's SQL Tag. I haven't committed it yet - I'm still waiting for more feedback.

Posted in Java at Mar 08 2004, 01:22:34 PM MST 10 Comments

BeanUtils.copyProperties() with Dollar amounts and Dates

A frequent issue that crops up when using Struts is how to transfer data from ActionForms to DTOs or POJOs and vise-versa. In other words, how do you get the data from your true model into Struts' Model? There are a few solutions out there, including the ActionForm-Value Object Mapper and BeanUtils.copyProperties. I've used both and (IMO) the only advantage of using BeanUtils is that Struts uses it internally and it's a bit easier to work with.

The reason I'm writing this post is to show you how to handle Dates and Doubles in your POJOs. The first step is easy - you simply need to register converters for Date and Doubles. The easiest way to do this (that I know of) is to add a static block to one of your classes. I do this in BaseManager, but it could be easily done in a BaseForm class.

    static {
        ConvertUtils.register(new CurrencyConverter(), Double.class);
        ConvertUtils.register(new DateConverter(), Date.class);

        if (log.isDebugEnabled()) {
            log.debug("Converters registered...");
        }
    }

When I use Doubles, it tends to be for dollar amounts displayed in a JSP page. Therefore, I call it a CurrencyConverter (source), and I use a DateConverter (source) for dates.

After registering these converters, the next step is to throw a little validation into the mix so that the String values (from the Form) are in an expected format. Since I'm using XDoclet to generate my Forms, it's as easy as adding a couple of tags to my POJO. Here is an example for validation Dates:

    /**
     @return Returns the startDate.
     * @struts.validator type="required"
     * @struts.validator type="date"
     * @struts.validator-var name="datePatternStrict" value="MM/dd/yyyy"
     * @hibernate.property column="start_date" not-null="true"
     */
    public Date getStartDate() {
        return startDate;
    }

And one for validating dollar amounts:

    /**
     @return Returns the startingSalary.
     * @struts.validator type="required"
     * @struts.validator type="mask" msgkey="errors.currency"
     * @struts.validator-var name="mask" value="${currency}"
     * @hibernate.property column="salary_start" not-null="true"
     */
    public Double getStartingSalary() {
        return startingSalary;
    }

For the currency validation to work, you have to add a few things to your Struts project. The first is the errors.currency to your ApplicationResources.properties file:

errors.currency=The '{0}' field should be a dollar amount.

The 2nd piece you'll need to add is the currency mask as a constant in your validation.xml file (or metadata/web/validation-global.xml if you're using XDoclet/AppFuse):

<constant>
    <constant-name>currency</constant-name>
    <constant-value>^\d{1,3}(,?\d{1,3})*\.?(\d{1,2})?$</constant-value>
</constant>

I'm not much of a regular expression expert, but I think this mask is specific to US Dollar amounts. I'd love to see a i18n version, but I haven't had a need for one (yet) - so it's not a big deal for me. The last thing you'll need to do is add a little JSTL lovin' to render your dollar amounts with the proper number of decimal places:

<fmt:formatNumber type="number" minFractionDigits="0"
    maxFractionDigits="2" value="${myForm.startingSalary}"/>

It seems that most web frameworks are getting away from a separate web model (ActionForms) and allowing you to use your POJOs in your view. This is likely to be a bit cleaner, but I'm sure they still have to use some sort of converter to get Dates/Doubles from your UI into your POJOs. The nice thing I've seen in other frameworks is that they have Date Converters built in. Why doesn't Struts? Who knows, but IMO it should be a built-in component.

Both of the Converters described in this article can be found in AppFuse.

Posted in Java at Mar 08 2004, 07:00:08 AM MST 1 Comment

Outline for talk on Display Tag, Struts Menu and AppFuse in NYC

This weekend I'm preparing slides for my talk in NYC on the Display Tag and Struts Menu. I'm also going to do a bit about AppFuse since it includes and uses both libraries. I have an hour to talk, so I think I'll try to present for 50 minutes and leave the last 10 minutes for questions or simply quitting early. That means, realistically, I only have 15-20 minutes for each project. That sure seems like a lot now, but I'm sure it'll fly once I'm up there in front of everyone. I'm definitely nervous about this event - I've only ever done technical talks to team members, never to a large audience. I've done large audience (20-50 attendees) talks, but those where in college and covered growing up in Montana and business plan-type presentations. Oh well, I'm sure I'll get over my anxiety about 10 minutes into it.

The purpose of this post is to write down the topics I plan to cover and hopefully get some feedback from the more experienced presenters out there. I'd also like to get feedback from developers - as in what you'd like to see covered if you were attending.

  • Introduction. Who am I, etc. (2 minutes)
  • Struts Menu. What is it - it's history, etc. (3 minutes)
       - Features and Demo of sample app. Questions. (5 minutes)
       - Expression Language support and building menus from a database (including code). (10 minutes)
  • The Display Tag. What is it - it's history, etc. (3 minutes)
       - Features and Demo of sample app. Questions (7 minutes)
       - Expression Language support and using to create an editable table (including code). (10 minutes)
  • AppFuse. What is it - it's history, etc. (3-5 minutes)
       - Features, Libraries included, etc. Questions (5 minutes)

Posted in Java at Mar 06 2004, 09:47:32 AM MST 8 Comments

JAG - similar to AppFuse, but offers more choices

This afternoon, I stumbled upon the open source Java Application Generator on SourceForge:

JAG is an application that creates complete, working J2EE applications. It is intended to alleviate much of the repetitive work involved in creating such applications, while providing a means of quality assurance that the applications created will be of consistent quality.

Major differences include: JAG has a Swing GUI to create your app and it uses EJB 2.0 for its persistence layer. AppFuse has an Ant task (ant new) and uses Hibernate (or iBATIS) for the persistence layer. Both use Struts 1.1 with Tiles and Validator support. The question is - will they eventually offer Spring, WebWork and Tapestry options for the MVC layer? I doubt it...

BTW, my experience with java.net has been quite nice so far. I like the fact that I can use a pserver for developer CVS access (vs. SSH only at SF). I also like that I can approve e-mails just by replying to an e-mail (vs. using a web interface on SF). The best part, however, has to be that CVS commits and e-mail messages are immediately browse-able in the archives. This is rather convenient when you're a blogger that likes to link to source code and messages in (sudo) real-time.

Posted in Java at Mar 04 2004, 01:05:51 PM MST 1 Comment

[ANN] Anthill 1.7.0 Released!

I've been using Anthill for about a year now, and I think it's a kick-ass product. I don't really have any issues with the current version, but it's nice that there's a new release. If you're interested, you can view the release notes.

Posted in Java at Mar 02 2004, 09:52:51 AM MST 2 Comments

AppFuse 1.4 Released!

This release involves many changes: re-arranging packages/directories, Spring integration, Remember Me refactorings and I also added iBATIS as a persistence option. I also spent a lot of time going through the tutorials to make sure they are up to date. I've been using AppFuse 1.4 for a few weeks on my current project, and I really do like the way Spring makes it easy to configure Hibernate, Transactions and Interface->Implementation relationships. If you're interested in upgrading your AppFuse 1.x app to use Spring, you can checkout this howto.

I also made the leap and moved the AppFuse project from SourceForge to java.net. This is mainly so I have more control over mailing lists and adding other developers. As of today, CVS files in SourceForge and Java.net are the same - but I'll only be updating Java.net from here on out. I also have released files in both projects, but will only use java.net in the future.

I spent all weekend updating the tutorials and fixing release-related issues. Phew - I'm glad that's over. "So," you ask, "what's next?"

A week of vacation (my sister flies in tomorrow), followed by starting to write Spring Live and creating a Spring MVC option for AppFuse. Oh yeah, I'll also be at SD West in Santa Clara, CA - let me know if you plan on attending.

Posted in Java at Mar 01 2004, 12:35:54 AM MST 11 Comments

Generating indexed-property ready ActionForms with XDoclet

One of the issues with using XDoclet to generate your Struts ActionForms (from POJOs) is that out-of-the-box, your Forms will not support indexed properties. This means that if you have a List on an object (this list will likely contain other objects/forms), you have to extend the generated form to add the necessary setters for indexed properties. For example, if you have an addresses List on a PersonForm, you would need the following in order to edit those addresses in Struts.

    setAddresses(int index, Object address) {
        this.addresses.set(index, address);
    }

The worst part is that you need to populate the addresses list with a bunch of empty AddressForm objects before Struts' auto-population will succeed. If you were coding the PersonForm by hand, you could code a reset() method such as the following:

    public void reset(ActionMapping mapping, HttpServletRequest request) {
        this.addresses = ListUtils.lazyList(new ArrayList()new ObjectFactory());
    }

    /**
     <code>StringFactory</code>
     *
     @see org.apache.commons.ListUtils
     */
    class ObjectFactory implements Factory {

        /**
         * Create a new instance of the specified object
         */
        public Object create() {
            return new AddressForm();
        }
    }

Now for the best part - I figured out how to generate this code with XDoclet, so any lists on your Forms will be indexed-property ready. By using <nested:iterate> in your JSP, you can easily CRUD you indexed properties. Pretty slick IMHO. The template is a bit much to put on this site, and it's long lines won't fit in a <pre> - so you can temporarily view the template here. I'll add a link to it in AppFuse's CVS once it shows up there. One thing you'll notice in this template is a little Velocity-lovin':

<XDtVelocity:generator>
  #set( $method = $currentMethod.name)
  ## trim off the 'get'
  #set( $objectName = $method.substring(3, $method.lastIndexOf('s')))
</XDtVelocity:generator>

Thanks to Erik on Merrick's blog for the quick Velocity/XDoclet howto. It was especially helpful since the XDoclet site has no documentation on this feature.

For all you my framework is better junkies - a clear explanation of how your framework handles indexed properties would be appreciated.

Posted in Java at Feb 27 2004, 05:18:10 PM MST 2 Comments