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 "framework". 558 entries found.

You can also try this same search on Google.

Creating column indexes with Hibernate

One of the best ways to speed up your application's performance is to create or optimize indexes in your database. On my current project, when we created our database on the AS/400 last week, the DBA noticed that there weren't any indexed created. I expected this and said I'd do some research on creating indexes with Hibernate. Thanks to Gavin, it turns out to be quite simple. Let's say you have an XDoclet tag on a column you want to index. Currently it is:

@hibernate.property column="username" not-null="true"

If you're using Hibernate's <schemaexport> task, you can add an index on this column to your mapping file and it'll create the index when creating the database. To add an index, it's as simple as changing the above XDoclet tag to:

@hibernate.property
@hibernate.column name="username" not-null="true" index="index_name"

Now the hard part comes. Which columns should you put indexes on? From what I've heard, it's the ones that you use in where clauses of your queries. I expect one or two per table is sufficient (??). One thing I'm not sure of is: should id columns contain an index?

Posted in Java at May 03 2004, 12:06:44 PM MDT 11 Comments

Populate your drop-downs with listeners and allow for refreshing

Most webapps have drop-downs (a.k.a. pick lists) that users select from when filling in forms. Spring has a nice referenceData method on its Controllers that you can use to populate these, but I prefer a different way. In AppFuse, I populate these using a ServletContextListener. However, one of the problems with using this is that your drop-downs won't get refreshed unless you have admins screens or a way to reload the attributes set in the listener.

In short, I think it's a good idea to load drop-down options in a listener and also have an action or servlet to refresh these options. For examples, see StartupListener.java and ReloadAction.java. Got a better way? I'm interested...

Posted in Java at Apr 29 2004, 04:50:55 PM MDT 4 Comments

What should we do with Tiles?

There's some discussions taking place on the Struts Developer Mailing List about what to do with Tiles. Tiles is gaining popularity in frameworks other than Struts - i.e. Spring and JSF. Personally, I don't mind that Tiles is buried deep inside struts.jar b/c it's basically the difference between a 500 KB JAR and a 100 KB JAR - and disc space is cheap! However, an advantage of extracting Tiles from Struts is that it then has the opportunity to become friendlier to other web frameworks. I'd even like to see a Sitemesh-like Filter so you could do Sitemesh stuff with Tiles. Or maybe just bundle Sitemesh with Tiles as a kick-ass templating engine.

So the question is: What should we do with it? Should it become a Jakarta Commons project or a Jakarta Project? Or even a java.net project? Tiles Users - we need your feedback!

Posted in Java at Apr 28 2004, 11:35:00 AM MDT 16 Comments

Logout your users automatically after their session times out

One of the common issues I see in webapps is a user leaves their computer, their session times out, and when they come back to do something - the app throws errors b/c their session is null. There are several easy ways to fix this. If you use Container Managed Authentication, the user will likely be prompted to do login and can continue as before. If you're using a slick Remember Me feature (like AppFuse has), the user won't even notice. However, you might not have these options available to you. For those circumstances, I recommend you put a meta-refresh in your app to automatically show the uses a timeout message when their session expires. It's as simple as the following:

<meta http-equiv="Refresh" 
  content="${pageContext.session.maxInactiveInterval}; url=timeout.jsp"/>

I used JSP 2.0's EL in this example for simplification. If you're using a JSP 1.2 container - you'll have to wrap that expression with a <c:out> tag.

Posted in Java at Apr 24 2004, 07:33:10 AM MDT 8 Comments

How does your MVC framework handle duplicate posts?

One of the problems that you'll often see in webapps is that when a record is added - hitting refresh on the browser will cause a 2nd record to be added. This is because the "Save" action usually does a forward, rather than a redirect, and the full post is re-created. I'm curious to know how other MVC Frameworks handle this issue, particularly Spring, WebWork, Tapestry and JSF. In Struts, it's pretty simple to solve. When the form is first displayed, you'll likely go through an Action. In AppFuse, this would be something like UserAction.edit(). In the edit method, you add a saveToken() call to put a token into the session:

// edit method - mark start of operation
saveToken(request);

Then in the save() method, you can check for a duplicate post using the isTokenValid() method:

// save method - check for valid token
if (!isTokenValid(request)) {
    // duplicate submit, continue to success mapping
    return mapping.findForward("success");
else {
    resetToken(request);
}

How does your Java MVC framework handle this? Do you have to programmatically handle it like Struts - or is it built-in to the framework to handle it auto-magically?

Posted in Java at Apr 20 2004, 11:36:29 PM MDT 22 Comments

Make your JUnit Tests run faster when using Spring

JRoller is down, and has been down for an hour or so - so I've decided to post this Spring Live entry here.

I discovered an interesting thing today about Spring and my JUnit tests. I noticed that the VelocityEngine I was setting on my PositionManager was getting initialized once for each test* method in my Test. This means that since my PositionManagerTest has 10 test methods - it would load the context 10 times.

Loading the context so many times was because the following code was in my Test's parent's constructor:

    ctx = new ClassPathXmlApplicationContext("/applicationContext.xml");

I suppose I expected any constructor-iniatialized variables to be initialized once and only once. So I figured out a solution to make my JUnit tests run faster. By making the ctx variable static, and loading the file in the member variables definition, I greatly reduced the amount of time needed to run tests. Below is the new code I'm using:

    protected static ApplicationContext ctx = 
    	new ClassPathXmlApplicationContext("/applicationContext.xml");

By doing this, the ApplicationContext is only set once, and my tests run much faster. Here's some performance comparisons from Struts Resume:

Average time to run "ant test-dao": 36 seconds
Average time to run "ant test-dao" after this change: 26 seconds

A 10 second improvement - that's crazy talk dontcha think?! I've tried it on single tests, as well as suites - and it seems to improve performance by approximately 30% across the board.

Because of this experience, I have to recommend that when you write JUnit tests that use Spring - you should initialize your ApplicationContext in a static member variable. It seems to be the best performing and logical choice. Of course, if I'm off my rocker - please let me know.

On a sidenote, it would be cool if Roller allowed me to turn off comments for a single post. I like how Simon posts stuff on java.net and then aggregates it to his personal weblog.

Posted in Java at Apr 08 2004, 01:22:14 AM MDT 21 Comments

WebLogic Workshop's NetUI and Page Flow

FYI...

April Denver BEA User's Group Meeting

Tuesday April 6th 6:00pm
Tattered Cover Down Town
1628 16th Street
Denver, CO, 80202

This months meeting will focus on WebLogic Workshop's NetUI and Page Flow technology that is built on top of Struts. We have a special treat in that Eddie O'Neal who is the BEA Engineering technical lead on NetUI and Page Flow is comming to talk with us. The primary discussion will focus on Weblogic Workshop and NetUI technology which is built on top of Struts 1.1. We will look a how these two relate and talk about the additional features NetUI provides on top of Struts like the additions to the programming model and the richer data binding. We will also look at a Struts variation of the petstore application that was migrated to a Page Flow.

AGENDA

5:30 - 6:00 Registration, Networking, Refreshments
6:00 - 7:00 WebLogic Workshop NetUI and Page Flow - Edie O'Neal
7:00 - 8:00 Field Secrets the next installation - John Funk
8:00 - 9:00 Further discussion at the Wynkoop Brewery and Raffles

Technology followed by beer is always a good thing!

Posted in Java at Apr 04 2004, 11:39:02 AM MDT 8 Comments

NYC Seminar: Flex and WebWork

Christophe talked about Flex, it's architecture and built the data grid for the Flex pet store in a matter of minutes. After seeing this presentation, I definitely think Flex is wicked cool. It's too bad that it's price tag is $6K/CPU. However, Vic is probably right - this stuff should be the next generation of webapps. I'd order the developer CD but it sounds like something I'd play around with and never use. It looks so easy to use that I'm willing to bet I can wait until a client demands it - then learn it in a matter of days - or even hours. I did end up asking Christophe about unit testing these Flash UIs. They're working on it, but nothing exists yet.

Now Jason is up - the last session of the day.

What is WebWork 2.0?

  • The 2nd generation of WebWork
  • A web MVC Framework
  • a wrapper on top of a generic Command Pattern implementation (XWork)
  • A small but powerful tag library

XWork is where Jason spends most of his time. XWork is a generic command pattern implementation. Actions are command objects in XWork. XWork adds advanced features.

  • Interceptors: setting parameters, workflow, etc.
  • Results: includes one for chaing to another Action
  • Simple IoC container
  • Powerful expressional language (OGNL)
  • Flexible type conversion
  • Metadata driven validation framework

What does WebWork add?

  • Adapter for Http request/response
  • Integration of Session / Application Scopes
  • ServletDispatcher translates HTTP Requests into Action execution
  • Request parameters passed to Action Results
  • Supported view technologies: Velocity, Freemarker, XSLT Jasper Reports, JSP

Action is a simple interface with an execute method. ActionSupport is a useful base class.

I gotta say - one of my favorite things about WebWork is the fact that all its UI tags are built using Velocity. This means that you (the developer) have full control over what HTML is generated from the JSP tags.

Interceptors have been nicknamed "Domain AOP." Interceptors allow custom code into the call stack and much of the WebWork "magic" happens with Interceptors. WebWork has a number of built-in interceptors:

Setting Parameters

  • ParameterInterceptor
  • StaticParameterInterceptor
  • ChainingInterceptor
  • ConversionErrorInterceptor

Defining Workflow

  • DefaultWorkflowInterceptor
  • PrepareInterceptor
  • ServletConfigInterceptor

Preventing duplicate posts

  • 2 types of token interceptors

Interceptors can be grouped into named Interceptor Stacks (i.e. defaultStack, validationWorkflowStack).

2 types of actions possible: Model-Driven vs. Field Driven (merging of Action and ActionForm). ModelDriven Interface - public Object getModel(). Porperties of the model will be available as simple properties - "user.name" becomes "name". To use, you have to add ModelInterceptor to your WW config file.

OGNL (Object Graph Navigation Language). An expression and binding language for getting and setting properties of Java objects. Normally the same expression is used for getters and setters.

XWork Validation Framework

  • XML based. Validation file in the same package as the class. Defines one field validator and the error messages to add if it fails.
  • Bundled validators - supports required, range, email, url and OGNL Expressions (very powerful).
  • JavaScript support recently added for simple validators - nothing for expressions though (tough to do).

Doh! Jason's demo didn't work. I did a lot of demos in my preso so I couldn't help but say "shoulda used a Mac!" These PowerBooks might be a bit slow for development, but they're definitely nice for this traveling salesman thing.

This is where you get your money's worth: All the speakers and attendees comparing frameworks, talking about their problems and trying to figure out a better way.

Posted in Java at Apr 03 2004, 04:13:54 PM MST 8 Comments

Macromedia Flex 1.0 Released

Macromedia has released Flex 1.0. Flex is basically a server plugin that allows you to write XML to render flash. Here's the marketing lingo from their product page:

Flex is a presentation server installed on top of a J2EE application server or servlet container, a rich library of user interface components, an XML-based markup language used to declaratively lay out these components, and an object-oriented programming language which handles user interactions with the application. The result is a Rich Internet Application rendered using Flash Player and developed using industry standards and a development paradigm familiar to developers.

The major problem with Flex is its price.

Flex presentation server pricing starts at $12,000 for two CPUs and includes annual maintenance.

Macromedia's take on this seems to be "its an evolutionary step in web application design and development" - so $12K is a small drop in the bucket. Sun claims the same for JSF, but you don't see a hefty price tag on that sucker. What Macromedia doesn't seem to realize is that its important to market to developers. If you can inspire the developers to love your product - it's only natural that it will gain more traction. With a price of 12K and no free trial (CD by mail) - good luck on getting developer support.

Of course, as an independent consultant, I probably have a scewed perspective. Maybe the corporate drones like getting their development platform and tools shoved down their throat.

Posted in Java at Mar 29 2004, 07:36:10 AM MST 9 Comments

OGNL 2.6.4 Released

OGNL 2.6.4 was released today. So you're asking - "Why do care? You don't use it?" You're right, I don't use it - but I will be soon. It's the Expression Language used in Tapestry and WebWork - which I hope to learn, beat and abuse in the coming months. I've also had some discussions with Drew about adding it as an EL option to the Display Tag. BTW, with the release of 2.6.4, XWork 1.0.1 and WebWork 2.1 will be released very soon - quoted from the WebWork mailing list.

A lot of the WW and Tapestry folks swear by it and claim it's vastly superior to JSTL's EL. As far as I can tell, it has some more advanced features (i.e. the ability to call a method), but it's not *that* much better. It's not going to revolutionize my webapp productivity - is it? Of course, Jason and Erik will argue that [ insert WebWork or Tapestry here ] is the real productivity enhancer. Personally, it's not the MVC frameworks that slow me down. It's the meetings, the requirements gathering and the UI tweaking (CSS and JavaScript) that takes the most time - as well as the occasional fumbling with Hibernate. That's unlikely to go away no matter what MVC framework I use.

That's why I use AppFuse - b/c most of the CSS and JavaScript I use on a project is already in there. A little massaging here and there, and the UI tweaking for the whole app can be done in a matter of hours. Of course, Tiles helps tremendously with this - as Sitemesh would I suspect.

I think what helps me the most about AppFuse is having a structured process for developing webapps. Create POJO -> Create DAO -> Create Manager, etc. I suspect that my process will stay the same with Tapestry and WebWork - so that's why I'm not afraid to learn them. The productivity-enhancing attributes of AppFuse will not go away with a new framework, but some parts may become a bit easier. Of course, you can bet that if I trip and fall along the way (which I likely will), you'll be able to hear about it here. Maybe someday this site will get as many hits for these frameworks as it does for Struts (up to 914 before this post).

Posted in Java at Mar 21 2004, 01:34:28 PM MST 1 Comment