Matt RaibleMatt Raible is a writer with a passion for software. 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 "struts". 749 entries found.

You can also try this same search on Google.

Copying Properties: The Good, the Bad and the Ugly

I realize that having an ActionForm and a POJO with the same getters/setters is ridiculous, but please bear with me for this example. I have a Form and a POJO with Strings, Longs and Dates. The Longs and the Dates get converted into Strings when I get the data from the database using BeanUtils.copyProperties. This works great.

BeanUtils.copyProperties(userForm, user);

However, when going back, it's a different story - here's the ugly way:

SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");

Date dateChanged = format.parse(userForm.getDateChanged());
Date dateCreated = format.parse(userForm.getDateCreated());

user = new User(userForm.getUserId(), userForm.getPassword(), 
                Long.valueOf(userForm.getDesktopId()),
                Long.valueOf(userForm.getCubeId()), 
                userForm.getCreatedBy(), dateCreated,
		userForm.getChangedBy(), dateChanged);

While this works, it's ugly and a pain. I want something like the ActionForm-Value Object mapper. This mapper allows you to easily copy properties between VOs (or Hibernate Objects) and Forms, and vise-versa.

vo = FormToVOMapper.map(form, new ExampleVO());

So I could do something as simple as user = FormToVOMapper.map(userForm, new User()); I like this mapper and I used it on my last project, where it works great. However, I get the feeling that developers in the Struts Community are using something better - and I want to use it. So please, tell me what it is and lets figure out the best way to do this. Another method I've used in the past is to set the VO (or object) on the form itself, allowing for setting of Strings without copying - and setting dates on the form, to be manipulated by the setter. This framework worked great, and I was actually the happiest with it out of any of the above. Chime in and give me your opinions!

Posted in Java at Dec 27 2002, 03:14:29 PM MST 6 Comments

ChainedExceptions and BeanUtils.copyProperties

I am wondering about a few things, so thought I'd try and get some help from the best source I know - the java.blogs community. First, an update on last night. I experienced some difficulty with Hibernate (persisting child objects) and Struts (nightly build doesn't quite work right with Tiles and Modules) and gave up at 2:00 a.m. Luckily, my head cleared up this morning after a deep 4 hours of sleep and I figured out Hibernate and it appears that a fix for the Tiles/Modules problem was checked into CVS by Cedric.

Now I'm wondering if it's possible to use declared exceptions in Struts to grab all your Exceptions from the bottom up. I can do this in an Action (or even a filter) using the following:

// caught exception e
ActionErrors errors = new ActionErrors();
errors.add(ActionErrors.GLOBAL_ERROR,
           new ActionError("errors.general"));

while (e != null) {
    errors.add(ActionErrors.GLOBAL_ERROR,
               new ActionError("errors.detail", e.getMessage()));
    e = (Exception) e.getCause();
}

request.setAttribute(Globals.ERROR_KEY, errors);

Can I do this with declared exceptions? Man that would be sweet if I could - I wouldn't have to have any exception handling in my Actions. Maybe that's the easy way out, but it also makes for rapid development - and you can always add them in when you really want them. Two other things I need to do.

  • I have a java.util.Set on my User (Hibernate) object. This refers to a collection of Resume objects. When I generate my StrutsForms, I need to do something in my XDoclet template to turn a java.util.Set into a java.util.ArrayList. I don't know that I have to do this, but I've always used ArrayLists or Vectors on ActionForms for child objects.
  • I am using BeanUtils.copyProperties in a Business Delegate to transfer properties from my User object to a UserForm object. When I do this, the child objects come through as Resume objects - where I really want them to come through as ResumeForms. Is this possible using BeanUtils, or do I have to do this manually?

I should probably do some research now to try and figure this stuff out on my own - but hopefully an answer will come through while I'm doing that ;-). I'll post to the proper mailing lists if I can't figure it out by COB. BTW, if you're using Hibernate, the FAQ is awesome. I wish more OSS (or closed-source software) had documentation this good.

Posted in Java at Dec 27 2002, 11:40:40 AM MST 9 Comments

Will this be an all-nighter?

I'm making a big push to finish the Struts Chapter tonight. Moreover - to finish the sample application. Things are going well so far. I hope it's not an all nighter, but as soon as I'm satisfied with the application, I'll have to deal with proof-reading the chapter, which could be a real headache. On the last chapter, the proof-reading took me an entire day. Ugh.

I just wanna get this darn thing done so I can spend some time with my family again, so I don't have to work weekends, and I can quit (pretty much) working for free. I think the time spent on the sample app will pay off in the long run, as it's already making it easier to develop the application at my new job. I was able to install, compile, deploy and start authenticating/pulling information from Oracle in a matter of hours. That's taken weeks in previous gigs. Of course, if you count the slow machine I had, the meetings and the installation of new software (trying to get the machine setup), then it probably took a week.

I took my home-built machine into work this morning - and all was peachy until I asked the help desk to add my computer to the domain. Politics came into play and I was told that the technicians have to build the machines, not some dev-head. No biggie, just get me a faster machine I said. I argued with the guy for a bit as I tried to explain that a 700 Mhz, 128 MB RAM machine was too slow for Java Development. When he said that was one of the fastest machines they had, I almost choked. Luckily, they found a 2 Ghz machine that I get to start using tomorrow - this'll be the 3rd machine I've built since I started last week. Damn. Sure is nice working from home when you have everything setup already. Do you think that tele-commuting will be the wave of the future? The clients that've paid me to work from home are getting a heckuva better deal than the ones that require an on-site consultant.

Posted in Java at Dec 26 2002, 05:01:44 PM MST Add a Comment

iTerm, StrutsForm Generation and the Work Life

I found iTerm via a quick scan of posts on java.blogs. Very cool - I'll have to download it tonight.

I'm still working like a banshee as you might be able to tell from my lack of posting. I was up until 4 in the morning on Sunday trying to complete my struts-resume app for my Wrox Chapter (still not done). I've backed off from my attempts at generating Struts Forms and Hibernate classes from the same POJO. It just doesn't seem likes it's worth the effort. I'd still like to generate the initial stubs for these classes form a database, but I've come to realize that it's not practical to have these classes generated each time. It's just too much of a nightmare to mix and match what goes to Struts and what goes to a Hibernate class. I am going to give it one last college try though. I hope to use a POJO with XDoclet tags, and then modify the XDoclet code for StrutsForms so they can be produced from a POJO. Of course, if I were smart, I'd just finish the damn application the hard way and be done by tonight. Wrox would be much happier I'm sure. I'll try for 2 hours and if I can't get it, I'm done. I think that I'll end up generating the initial struts form and then stuffing it into the source tree for later manipulation. I've found that it's nice to add getter/setters to the form (that never make it to the backend), so this is probably the best way.

Things at the office are going well. I spent most of the day installing Tomcat, MySQL, VeryQuickWiki and Scarab on a Sun box. It was fun doing the ol' command line thing all day and OS X makes it a real pleasure to interact with Unix systems. Transmit2 makes it super easy to transfer files and even allows you to edit with BBEdit. It's worth the purchase for sure at $25.

I've decided (once again) that OS X is not the development environment for me. Eclipse is too flaky (I'm running 2.1 M4) and takes forever to do anything. Ant runs slow as hell, and Tomcat does too. I'm also addicted to Windows Exploder and OS X's Finder does nothing for me. So I told my boss that they were losing money if I didn't get a faster box, and Windows would probably be best. They said it didn't look good, so I volunteered to bring in my own machine (Dell 8100 P1.5, 768 MB RAM) if they could get me a new hard drive. By getting a hard drive, I don't have to blow out my Red Hat 8.0 installation and I can transfer the hard drive to the new machine when they finally get me one. So they found a 20 Gig hard drive and I'm building the machine as I hammer out struts-resume.

Posted in General at Dec 23 2002, 03:12:13 PM MST 1 Comment

Hibernate Reverse Engineering Tool

Thanks for all the tips for setting my proxy/port for Java apps. Now I just have to try to figure out what the proxy server/port is. I tried to get it yesterday, but everyone only seemed to know the automatic configuration URL. I'm hoping that's a text file with some information in it that I can use.

Jon Lipsky also hooked me up (via e-mail) with the Reverse Engineering Tool for Hibernate. If I get a chance to use it today - I'll report on it's ease of use, etc. I wonder if I can generate my classes, mark them up with XDoclet and then produce my Struts ActionForms. Or possibly, I can generate the classes with Hibernate and create my ValidatorForms by hand. It'd be cool if the Reverse Engineering Tool supported generating an XDoclet-ready class, and also allowed for regeneration. I probably shouldn't be hoping for too much - it might just work as is.

Posted in Java at Dec 20 2002, 12:23:52 AM MST 3 Comments

Bailey's at 9:00 a.m.

I was up until 3:00 a.m. last night as a friend was passing through town and stopped by to say hi. He (and his dad) didn't get to our place until 12:30, so I didn't get to visit long, but it was worth the lack of sleep. I got up at 7:00 and went to work feeling like a zombie - only to find out that there was a Bailey's party at 9:00! That's right - one of the ladies made some home-made Baileys and brought it in for everyone to enjoy. I have to say, it's the first time I've had spiked coffee at work!

We just got home from dinner at a friend's house and I am beat. I do have a couple questions and news items though.

  • Is it possible to configure Java to use a proxy server to connect to the Internet. The only way to connect to the Internet at work is to setup your browser to use an Automatic Configuration URL. This means that Struts can't validate to it's DTDs (unless I change to use a System DTD) and I can't use Maven to download jars.
  • Can Hibernate generate classes and it's mapping files from an existing database?
  • Konstantin Priblouda has published a demo of using Hibernate, XDoclet and JBoss. You will need a current version of XDoclet from CVS to run it.

Posted in General at Dec 19 2002, 05:07:51 PM MST 2 Comments

The First Day

The first day at the new job was good. The three developers on the team (myself included) had a 3 hour meeting getting our arms around the project and figuring out how to do everything. It's an interesting approach we're using - where an Excel speadsheet is e-mailed to a mailbox. It's then picked up, processed, and if it meets certain criteria, it's entered into an Oracle database. Then we're going to use a web front-end and Struts to grab the data and render it to the user so they can correct it. I wonder if I can use the Struts Validator on the way out? It'll be interesting to find out.

The only unfortunate part of the day was the machine I found myself in front of. It's a Dell GX110, and has 128MB RAM and a 733MHz processor. Ughhh, try running Ant, Eclipse and Tomcat at the same time on that sucker! I faired better than the other developer though - he got an NT 4 box - at least mine's 2000! They said they'd try to get us better machines, but I hope to just use the ol' Powerbook. The dual 21" monitors is helping to reduce the pain.

Posted in General at Dec 18 2002, 02:59:57 PM MST Add a Comment

Erik Hatcher's Blog

I saw it a couple weeks ago, but now Erik appears to be updating it regularly. Just in case you didn't know - you can find it here. Erik is an Ant Guru and has written many cool Struts extensions (i.e. LookupDispatchAction, XDoclet integration). He's made my life a lot easier with his Ant wisdom and Struts goodies - thanks Erik.

Posted in Java at Dec 18 2002, 01:17:30 AM MST 1 Comment

Eclipse Plug-ins for Struts and DAO Generation

I ran across STRECL.COM today via the struts-user mailing list.

TRECL is a set of plugins for the Eclipse IDE. Using STRECL you will get a powerful tool for Java server-side applications development. STRECL plugins offer easier utilization of the Struts framework in Eclipse IDE by visualization of editing, facilitating navigation, wizards etc.

STRECL currently offers the following plugins:
  • struts-config.xml editor
  • JSP editor
  • DAO generator
  • validation.xml editor
  • Struts navigator view

Just in time to get some coverage in my Struts chapter - that is, if it's any good ;-)

Posted in Java at Dec 17 2002, 05:52:00 AM MST 3 Comments

Bloody Noses and Struts Chapter Progress

I've gotten three bloody noses in the last 36 hours - and I don't seem to recall ever having them before in my life! Yikes - is the stress getting to me?! Oh well, I'm sure I'll be fine. I read on a website today that bloody noses are way over-emphasized and they aren't a big deal at all.

I'm at 22 pages on the Struts chapter now, doing Exceptions and how Struts lets you declare exceptions in your struts-config.xml -- pretty cool stuff. The bad part is that I've never used them before, so it's kinda tough to write about them - at least in the context of Struts. I tried to use Strut's ApplicationException (now renamed ModuleException) last summer on a client's project - and it was too buggy to use. Now it seems to to work as I originally expected it to, and it's pretty sweet. I do feel like I'm building an application to show functionality though, rather than developing an application to fulfill some requirements, which is unfortunate. I'd rather build an application that employs KISS, and shows the easy way to do things. It's like using design patterns because your manager thinks they're a good idea, but you could get the project done in half the time without them. Sure, your app might not be extendable in the future, but if it doesn't live past 3 months, what's the point?! Of course, I think using the Validator and Tiles is easy, and many developers think that's the complicated part. If my learning curve was up to snuff, Exception and Modules (a.k.a sub-applications) would be easy. Soon they will be, though I still may never use them.

Tomorrow is my last day (for a while) as a full-time employee of Raible Designs. I've certainly enjoyed the last year, but I've missed the office comradery and face-to-face interaction. It'll be good to get back into an office, but I'm sure I'll miss coding in my living room within a week, and wish I was back here.

I'm going to get my mugshot tomorrow for the Wrox book - I've convinced Abbie and Julie to go with me so we can get some good family photos - should be fun. After that, I'm going to fill out the paperwork - W2's - for the new gig, and then off to a project kick-off party! Sounds like my kind of project already!! It's got a good name too - Project Fiji. One of the things I'm looking forward to is implementing Struts and Hibernate (if they'll let me) using XDoclet. I've done it in my sample project and AppFuse (expect a new release in a week), but it'll be awesome to cut our development time in half right away! Especially when the first deliverable is due January 15th!

If I'm good (and I can figure it out), I hope to use Maven on the project as well. It should be interesting to be the primary Java Developer on the project, along with a Web Developer and Oracle DBA. I've always been the web developer - but I've learned so much in the past year and a half (since I met Struts), that I feel more than comfortable being the Java guy. You know what the best part is - I feel like I've learned more from the java.blogs community than I have from studying for certifications, or from any conferences I've been to. Keep it up - learning is awesome!

You know what the better part is? Julie just said to me - "thanks for making all my dreams come true." Enough said, life is awesome - even with toilet paper stuffed up my nose and a chapter that seems like it'll never get done.

Posted in Java at Dec 16 2002, 03:56:38 PM MST 1 Comment