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 "mvc". 279 entries found.

You can also try this same search on Google.

[Hibernate] Open Session in View Pattern

I get this question a lot when folks check out my struts-resume application - so I figured I'd document it here - and then I can just send future developers a URL. The question is this:

Why do you tie your View to your Model Implementation by putting a Hibernate Session in your Service Interfaces?

I have a couple of reasons. The first reason is that I initially had ses.currentSession() and ses.closeSession() at the beginning and end of each DAO method. In fact, I found this old e-mail where you can see an example. This seemed to work for me and I was happy with it. However, I got an e-mail from Gavin (Hibernate's Lead Developer) that I was doing it all wrong. He said that I should use one session per request, rather than one on each method. Why? For performance reasons and to allow rolling back the entire session, rather than just a method. At least that's why I remember him saying.

So I refactored and implemented the Open Session in View pattern in conjunction with the Thread Local Session. You can checkout my ActionFilter and ServiceLocator for the View and ThreadLocal, respectively.

The problem now is that I pass my the Session object from my View -> Business Layer [example: UserManager] -> DAO Layer. So I'm tightly coupled with Hibernate, which I don't mind, because I really, really like Hibernate and have no plans to implement an alternate DAO (even though the architecture allows it). Even if I did choose to implement a new plain ol' JDBC DAO Layer, I can always get a java.sql.Connection from the Session using ses.connection(). Another option I've thought of is to just pass the ServiceLocator between the different layers, and call ses.currentSession() or ses.connection() when it's needed. But that seems to be the same thing I was doing before when I was opening/closing at the method level.

Comments and suggestions, as always, are welcomed and encouraged.

Posted in Java at Jun 11 2003, 02:12:31 PM MDT 8 Comments

Hotels.com powered by Struts!

This is kind of a cool announcement - giving more credibility to Struts. Personally, I think all the leading web application frameworks are great - and can probably be learned in a week or two (or a few days/hours!) - so it's not about which one you're using, it's about if you're using one or not. If you are - you're on the right path. If not, you're probably wasting a lot of time developing your own.

I am proud to announce the successful launch of a major vacation packaging site whose presentation tier has been built entirely with Struts:

http://packaging.hotels.com/packaging/index.do

We have made extensive use of the Struts MVC framework, custom tags, and I18N components, with some custom modifications. It has proven itself to be a stable and robust platform, able to amply handle the needs of both our users and management.

I would like to applaud everyone who has worked on the Struts project; it has been shown yet again to be an excellent framework for a commerical web application.

James Childers hotels.com Packaging Team

Posted in Java at May 30 2003, 10:59:40 AM MDT 1 Comment

Validation vs. Business Logic

In the manuscript I'm reading, I just ran into a diagram and overview of a layered architecture - and all of a sudden, it hit me. At work, most of our business rules are being implemented by Struts' Validator framework. In the case of indexed properties and more complicated rules, these reside in the validate() method of our action forms. So it's interesting to me that I'm using a business delegate to perform my business logic - when in actuality, all my delegates are doing is copying properties from a POJO to an ValidatorForm. So this begs the question - shouldn't validation (a.k.a business rules) be done wherever it is most convenient rather than only in the domain layer? Oh yeah, and most of this is just validation - our real business rules (comparing data for validation) takes place in Oracle stored procedures. And you know what - it works great!. So my opinion is - do whatever is easiest and makes the most sense.

Posted in Java at Apr 29 2003, 06:18:27 AM MDT 6 Comments

Struts Training: Week 5

I'm dialed in and listening to Don Brown presenting on Struts and XML/XSL. Don is a lucky guy - he's presenting from Hawaii this morning, where I'm assuming he lives. The bad part for him - it's 5:30 in the morning there. Don is one of the developers of Stxx and has also developed a Cocoon plugin for Struts. He works for DigitalNet and currently is working on a contract for the Navy. Hmmm, wonder if they're hiring - I'm willing to bet that Julie would consider moving to Hawaii! Enough dreaming - onto the presentation.

The following are types of XML/XSL Extensions for Struts:

  • XSL-based
      - stxx
      - StrutsCX
  • XML pipeline-based
      - Cocoon Plugin

stxx: features
  - replaces JSP with XSL
  - in action, create XML manually, or get it from another source
  - stylesheet selection based on criteria like browser type
  - automatic serialization of ActionErrors, resources, and request objects
  - extendable to support any object serialization or XML transformation technology
  - supports both Struts 1.0 and Struts 1.1

Pretty cool - for Struts 1.1, there's a Stxx plugin, and you use a .dox extension to indicate it needs transformations. In a stxx-transformations.xml, you define "transformations" that define XSL stylesheets, where to run at (client|server), and mimeTypes (html|xml|pdf). Sweet - maybe I can use this sucker for struts-resume! I wonder how Stxx compares with StrutsCX. Since Stxx can be plugged-in and can co-exist with JSPs, it might be the right path for me.

Advantages of Stxx: Simple, use of caching makes tranformations quick, can be used with Velocity or Cocoon, lighweight, very extendable.

Disadvantages: XML pipeline very limited, poor scaling of message resources (if ApplicationResources.properties in huge - i.e. > 1MB), requires all data to be gathered in Action (MVC-push).

Compared to StrutsCX - Don says that it's very similar, except that StrutsCX supports the Validator. As for the Cocoon Plugin, it supports all the features of Cocoon. Describing the features of this plugin seems pointless as I would just be describing features of Cocoon. For the Cocoon PlugIn, you define it the same as a regular plugin, and then change your path to point to an XHTML-compliant JSP. Apparently, Don has modified the struts-example app to use the Cocoon PlugIn, so hopefully I can provide a link to the download.

Here are some resource links from Don's presentation that might interested you:

As for my presentation on Remember Me and XDoclet, you can find those slides here. The slides (and lab) uses a simple JSTL-based app I whipped up last weekend. I'm planning on hooking it into a database eventually to allow online editing of a presentation, but I probably won't do that until I give another presentation.

Posted in Java at Apr 05 2003, 09:35:09 AM MST Add a Comment

Struts Training: Week 2

I'm planning on attending today's Struts training and will be reporting here again. I got up at 6, hoping to do the labs and discovered the first step was downloading the latest Basic Portal setup. Since it's 200 MB, I've been dicking around for the last hour and a half, waiting for it to download. Yikes - I thought struts-resume was bad at 10.5 MB! I guess the difference is that it includes JRockit, Mozilla, OpenOffice, Vim, Ant, Eclipse, JMeter, Jikes, PostgreSQL and Resin.

Today's session seems to be covering databases, SQL and database performance. Vic mentions that 90% of performance is in the data model design. If you can fit your database on a laptop, then performance will probably not be an issue. I agree with this. I did the first lab during the first half-hour of the preso. Pretty simple stuff: creating HTML files and accessing them through a browser. This is probably a good lab to get everyone going and stuff installed. Also proves that Resin is running. Of course, it took me two hours to complete this lab, including the download, so I guess it's not that short!

Commons SQL is a new version of Torque (a manual persistence layer). Vic uses RowSets a lot, has one site with 40,000 concurrent Struts users with sub-second response times. He attributes this to rowsets. He says, "To create high-scalable applications, you need to know SQL and use things like RowSet, Ibatis.com, Commons SQL and Scaffolding." I tend to disagree - I think that EJBs (and possibly Hibernate) are your best bet for highly scalable application (i.e. 10,000+ hits per second). If your EJBs are slow, it's probably your code or your appserver. Try EJBs on JBoss and I'm betting you will be pleased. Then again, I've never created a highly-scalable application, and Vic has, so I'm not much of an authority. He, he - he mentions that Castor has lost a lot of mindshare; "Great for development, but not very scalable in production." So true - or at least Roller seems to prove this. From the folks he's talked to, Vic says that TopLink has a horrible reputation.

Hmmmm, interesting. Vic puts all the database connections and CRUD in his ValidatorForms. This is not saying that his bean matches his database tables. I don't know that I'd recommend this, but it certainly might simplify things. However, personally, I'm more comfortable with keeping my POJOs and ActionForms pretty dumb (just getters and setters). He has a DAO that handles CRUD and population of the bean. I wonder where you'd put the business rules in this implementation? In the DAO? If it's in the DAO, what if you have to write a new DAO implementation. For instance, if we used this approach on Roller, we'd have to re-write our business rules for Hibernate and Castor. Ugh.

For testing, he puts a test() method on his beans and uses a Servlet or a plain class with a main() method. Personally, I'd recommend using JUnit and JUnitDoclet (and Ant) to generate and run your unit tests. It's much easier than writing a servlet to test - and can easily separate your tests from your real code. See struts-resume for examples. I'll be releasing AppFuse in the next couple of weeks. This (hopefully) will provide a nice starting point for creating web applications. In reality, if no one uses it, I'll probably be better off (less support). It's been working great for me on my current project and has easily saved us a month of startup time. Right now, appfuse == struts-resume.

Vic mentions using a BaseAction that dispatches to the appropriate method in your subclasses. He says that the only difference between this technique and DispatchAction (or LookupDispatchAction) is you can specify a default method. Here's a tip: use the unspecified method. Here's how to make your edit() method the default:

public ActionForward unspecified(ActionMapping mapping, ActionForm form,
                                 HttpServletRequest request,
                                 HttpServletResponse response)
throws Exception 
{
    return edit(mapping, form, request, response);
}

Vic hints that the next iteration of Basic Portal will be written to use the iBATIS Database Layer and MySQL. Interesting, I thought iBATIS was a company, but nope: it's from the author (Clinton Begin) of JPetstore. On most days, I'd recommend Hibernate here, but I've spent the last 3 days wrestling like mad with it, so I won't. Of course, after leaving work last night, I think I might've figured out the problem. My brain is likely to blame more so than Hibernate.

Ted Husted chimed in at the end and mentioned that he is going to touch on Hibernate next week. Cool!

Posted in Java at Mar 08 2003, 08:13:11 AM MST 4 Comments

The Debate is flawed: Struts vs. WebWork

Personally, I think the debate between Struts and WebWork is irrelevant. This is because I don't think that the Web Application frameworks are the problem. I spend most of my days getting persistence to work. Granted it's gotten a whole lot easier with Hibernate, but I've spent a lot of time tackling that learning curve in the last couple of months. Thanks to Dave Johnson and Gavin King for guiding me up the curve. I spend about 30 minutes each day writing Struts-related code, if that. More time is spent writing tests, CSS, JavaScript (the most time) and DAO's/Managers.

So the problem is my brain. If I could just get the damn thing to work right - it wouldn't matter which framework I chose, because I'd just know it. No learning curve == awesome productivity.

The WebWork guys claim to have this. Therefore, I'm interested. However, who's hiring WebWork gurus? Heh - I know - what I really need to do is learn WebWork and then I can offer an unbiased opinion. Right now, no one is offering an unbiased opinion. Patrick is heavily invested in Struts, as am I. Heck, I've written a chapter about it and I've used it on many project. Jason is invested in WebWork as he's a committer.

Baaah, I'm just gonna learn .NET - that's where the Florida Jobs are. Struts .NET and WebWork .NET - maybe I should work on getting those started. ;-) The post is meant to be read with a smile on your face - I don't want to start yet another flame war.

Posted in Java at Mar 03 2003, 04:13:58 PM MST 2 Comments

Struts Training: Week 1

I was invited to attend Basebean's Struts Training today. Vic Cekvenich was nice enough to give me a password to attend, and I agreed that I would blog about it. I also agreed to help out on the MVC Programmers mailing list. I don't know that I'll do the labs, but I am interested in doing them - especially since the examples run on Resin 3.0. So I'm sitting in right now and they're doing some introductions. More to come soon. It's about a 1 and 1/2 hour class this morning - should be fun.

The first 20 minutes have been mostly about open source and it's benefits. I'm thinking - most of the students already know this don't they? Maybe not. I guess my perspective is skewed since I've been involved in open source for so long. Before I started using it, I guess I kinda scoffed at it - so I suppose the intro is good.

The second 20 minutes has been about "why projects fail" and the importantance of requirements. I can definitely understand this - as I've been on a couple projects with a bad requirements-gathering process. So far, this class has been a little disappointing as I haven't learned anything yet. The students seem very interested in the first two topics though - so I guess it's satisfying them. I'm sure I'd be more satisfied if I'd already done the labs (the students have).

Now onto Project Management and CMM. Didja know you can get certified as a Project Manager from PMI.org. IMO, a Project Manager can single handedly make or break a project. I agree with Vic that "the best person to have certified on a project" is the PM. The PM on my current project rocks, and it's made the project soooo much easier. You can track your project's ROI at softwarereality.com.

Don't these student's have mute on their phones? I've heard kids crying and dogs barking so far ;-) No one's heard me sneeze yet - and I've done it 3 times!

Vic recommends the following:

  • When starting a project, create the entire application as an HTML mockup. I agree with this - it's awesome for getting requirements solidified.
  • Mockup the outputs - i.e. Reports in Excel. For reports, he recommends using iReport. After a quick review - it looks like a report designer that creates an XML file that can be fed to Jasper Reports.

NetLedger.com is a recommended UI for complicated forms. Rumored to have a free login.

Tip: When you have bad requirements, surf the web. Programming on your project will just frustrate you. My advice: contribute to an open source project - then you'll keep your skills up to par. Or, read blogs - you'll learn something there too.

Now we're learning how to setup an IDE (Eclipse) and deploy/test and example app. Looks like the sample app (webPIM) uses JSTL's Fmt tag. Cool, I've never used it, I should probably do the labs. Teaching students how to use an IDE for Struts Development is definitely the easiest way to go, but using Ant is the real-world way - right?

The next lab covers configuring Tiles and developing a sample layout. I noticed it was a big confusing for the students that the tiles definitions file is named layout.xml and the base Tiles template is named layout.jsp. I usually name my tiles definition file tiles-config.xml.

Posted in Java at Mar 01 2003, 09:49:51 AM MST Add a Comment

Struts Training (Darn Cheap too)

If you're looking to learn more about advanced features of Struts, you might want to checkout BaseBeans's upcoming training. I received the following e-mail in my Inbox this evening.

Announce: "*Best Practices in Struts -  Web Training*" by Cekvenich, 
Husted, and Turner and a presentation by Momjian on PostgreSQL. (each a 
published author)

Struts 1.1 might be released in March, so every Saturday at 10:30 AM 
Easter, watch and hear presentation via WebEx.com.

Meeting #	Date	 Title
616291003	1-Mar	 MVC Intermediate Setup
614301419	8-Mar	 MVC View for CMS/Contact
611367121	15-Mar 	 MVC – Ted Advanced + DAO Lab
611903740	22-Mar	 MVC – Bruce pgSQL + Multi Row Lab
611213868	29-Mar	 MVC - Turner + Options/Nested
(once you connect via PC, telecom phone is 1-408-964-1050)

This presentation is almost FREE (other than the cost of WebEx), the 
sooner you register, the cheaper it is.

A week of training by others could be $2400! Plus travel costs. Plus 
they did not get voted best, baseBeans.com did!

Register and pay at: http://www.basebeans.com/do/classReservation
Cost of all 5 sessions + labs (8 hours for each session) is .... $155 if 
you pre-register, or $275 if you late register and $475 if you register 
in March.

Labs (on your own time, hours each) include: Multi Row Updates, 
Validation, Tiles, Navigation, EL, Nested, Options, CRUD, etc. full 
agenda was published.

Each lab is at least 8 hours and required, if you do not do the labs, 
the next presentation will not make sense, no pretenders here. No money 
back for this, other baseBeans.com presentations are money back!

I'd sign up, but Saturdays are reserved for Julie and Abbie.

Posted in Java at Feb 16 2003, 07:34:22 PM MST Add a Comment

Denver JUG Meeting and Struts

The Struts Framework I managed to attend the DJUG meeting tonight (as I wrote this, time slid past midnight - oh well, it looks better on a new day). I arrived early for the Basic Concepts meeting and stayed for the Main Event. Both sessions were focused on Struts - the first being a very basic overview of MVC and Struts, and the second highlighted the newest features (i.e. Declarative Exception Handling, Validator, DynaActionForms). Like I said earlier, I wanted to meet Sue in person, so that's why I got there early. I introduced myself and she actually seemed to remember me (from the e-mails). I confirmed that she really did remember me (or she faked it quite well) at the end when she signed a copy of her book (that I won) - she asked me if I spelled my name with one "t" or two? Cool! BTW - do you know anybody named "Mat?"

When the DJUG Prez asked if anyone was looking for work, I raised my hand and said a few words about this site and Roller. I doubt anyone will find this site though; I didn't see anyone writing my domain name down, and how the heck do you spell "Raible?" So to offer a little Google love, here are a few different versions: Rabel, Riable, Raibel, Raybel, Rable, Raybell. If I was really bold, I guess I could send an e-mail to the DJUG Mailing List. I think I'll have to pass though, I'm just not that forward of a guy.

The meeting was packed, probably a 100 people showed up - most they've had in long time from the way they were talkin'. It was at DU, my Alma Mater, so it was fun to visit the ol' stompin' grounds. I had Mini-Me with me and found the DU Wireless network, but it required VPN software to get in (and my old id/pass didn't work to d/l the software).

Sue was a good speaker and did manage to impress me with her Struts knowledge. I didn't know that she is a contributing author of the JSP and Servlets column at O'Reilly's OnJava.com, nor that she's got a list of seemingly great publications. I tried to give her a tip about XDoclet, but she said she already knew about it and was planning on mentioning it in her preso. Doh! She really put me in my place. The best part of her presentation (for me) was the declarative exception handling, which I tried to implement on my current project, but it was too immature and buggy at the time. I think it's time to re-examine and refactor.

As a service to my readers, and possibly to readers from the meeting, here is a whole posse of good Struts links:

I'd love to see some weblogs published by Sue or Chuck (Cavaness) - it'd be great to see more Struts Evangelists in the blogging community. The next meeting should be good. Marc Fleury, founder of JBoss fame is going to be speaking.

Posted in Java at Nov 13 2002, 06:58:45 PM MST 3 Comments