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 "beans". 112 entries found.

You can also try this same search on Google.

Hibernate's AdminApp - a demo of WW2 and Hibernate

After looking at Hibernate's AdminApp, as well as other WW2 apps - I've noticed something. WW2 developers don't seem to give a rats ass about referencing their POJOs in their Actions, or using Hibernate directly in their actions. At first glance, I think to myself, "boy that sure makes things easier." But then again - doesn't that tightly couple your web layer to your persistence layer?

I can understand the POJO reference in Actions - I'm about to give up on doing a parent/child relationship with Hibernate where the children are converted to ActionForms and then converted back (Hibernate loves to tell me "a different object with the same identifier value was already associated with the session: 1").

It would be SO much easier (with this particular problem) if I could just toss up POJOs to my view. The thought of importing "persistence.User" into my Action makes me cringe though. I don't know why, it just does. I need to get out of this patterns mindset I've been in for the last couple of years and get back to what really matters - simple, easy to learn, and fast to develop. I'm tired of banging my head against the wall with Struts and Hibernate.... I've been doing it for two days. It's not Hibernate, and it's not Struts, it's me... (thud, thud, thud).

Posted in Java at Dec 17 2003, 02:35:09 PM MST 15 Comments

Tiles Tips o' the Day

Here's a couple of things I learned today that might be useful to you Struts developers out there. When using Tiles, you'll normally import all the attributes into your baseLayout.jsp, and then your attributes are exposes as beans/scripting variables (you can actually grab them with JSTL tags). Rather than using:

<tiles:importAttribute/>

Use:

<tiles:importAttribute scope="request"/>

And then all your inserted pages can access these attributes. Pretty slick when you got a little JSTL love in the mix. The second tip is how to implement definition path switching. Let's look at the following baseLayout definition as an example:

  <definition name=".baseLayout" path="/layouts/baseLayout.jsp">
    <put name="titleKey"/>
    <put name="header" value="/common/header.jsp"/>
    <put name="sidebar" value=".sidebar"/>
    <put name="footer" value="/common/footer.jsp"/>
  </definition>

You currently cannot change the "path" attribute with a Controller, so you have to do it as the Tiles author recommends - by changing your path to refer to an action. So I changed the path on this particular definition to be:

<definition name=".baseLayout" path="/do/switchLayout">

Where my action-mapping is defined as follows:

 <action path="/switchLayout" 
   type="org.appfuse.webapp.action.SwitchLayoutAction">
   <forward name="printLayout" path="/layouts/printLayout.jsp" />
   <forward name="baseLayout" path="/layouts/baseLayout.jsp" />
 </action>

Then in SwitchLayoutAction.java, I have the following code:

boolean print =
    Boolean.valueOf(request.getParameter("print")).booleanValue();

// see if a print parameter is passed in the request
if (print) {
    log.debug("switching base layout to printing...");

    return mapping.findForward("printLayout");
} else {
    return mapping.findForward("baseLayout");
}

Pretty slick IMO! It's easy to make the printLayout.jsp only contain some simple wrapper stuff and only do <tile:insert attribute="content"/>. Of course, in this particular example, you could just use a print stylesheet (media="print"), but that doesn't work so well on 4.x browsers (man I hate those beotches).

Posted in Java at Sep 24 2003, 03:01:03 PM MDT 4 Comments

Building high-content web applications

I've recently been tasked with rebuilding a JSP-based site using a Struts architecture. One of the issues (that I see) in the current architecture is that there are a number of JSPs with the text for the pages hard-coded in them. After re-writing this app, we plan on deploying it to 25+ customers - and we certainly don't want to have 25 different JSPs (with text) for each customer. I've proposed a database, but that might be a little resource intensive - so I'm wondering how folks have done this in the past (I'm sure it's been done before)?

Options I see are:

  • A Database table with the following columns (page_id, title, content, section_id).
  • Text files that are imported using <c:import url=""/>

What options have you used (feel free to add more) - if you've used the database approach - how do you define the page table? Maybe we should use the Roller way and use Velocity and OSCache.

Posted in Java at Aug 19 2003, 06:30:28 PM MDT 18 Comments

Changing Struts' bean:message to JSTL's fmt:message

I converted AppFuse to use JSTL's <fmt:message> tag instead of Struts' <bean:message> tags this morning. It was pretty easy. Here's the steps I took:

1. First, I added the following to metadata/web/seb-settings.xml:

<!-- Define the basename for a resource bundle for I18N -->
<context-param>
    <param-name>javax.servlet.jsp.jstl.fmt.localizationContext</param-name>
    <param-value>ApplicationResources</param-value>
</context-param>

2. Then I added the format tag to web/common/taglibs.jsp:

<%@ taglib uri="http://java.sun.com/jstl/fmt" prefix="fmt" %>

3. Finally, I did find/replace with <bean:message/<fmt:message.

4. I also had to change my title and header keys in web/WEB-INF/tiles-config.xml to remove the . from the bean names. In other words, I converted title.key and heading.key to titleKey and headingKey and also made the appropriate changes in web/layouts/baseLayout.jsp.

Easy as Pie!

Posted in Java at Jul 10 2003, 07:59:29 AM MDT 35 Comments

[ANNOUNCE] Hibernate 2.0 Released!

Sweet! The Hibernate Team has lived up to their promise and released Hibernate 2.0 Final! [Download, Release Notes]

Posted in Java at Jun 08 2003, 10:36:54 AM MDT 6 Comments

[ANNOUNCE] Struts BSF (Scriptable Actions) 0.3

Boy, Don Brown is a busy man this week. He releases a new version of the Struts Cacoon plugin on Monday, and today he released a new version of Struts BSF.

This project allows Struts Actions to be written in the scripting language of one's choice rather than as Java classes. It uses the Beans Scripting Framework to allow scripts to be written in any language BSF supports like Perl, Python, Ruby, JavaScript, BeanShell, and I believe even VBScript.

Version 0.3 adds the ability to pass parameters from the Struts config file, a pluggable filter system to pre-define custom variables, more documentation, and more. [Learn More]

Looks cool, but I have no need (currently). If you're using the BSF and have experiences to share, please do so. I'm interested, it just hasn't made it past my crap filter yet.

Posted in Java at Jun 04 2003, 02:46:56 PM MDT 1 Comment

Struts Training: Week 4

I missed last week (Week 4, PosgreSQL), but I'm back this week - ready to report. I'm presenting next week on "remember-me" and XDoclet, so I'm working frantically trying to get AppFuse up-to-snuff to use as a lab template. Hopefully, I'll have that done by tomorrow night, as well as the lab and presentation.

Today's presentation is from James Turner on Indexed Properties and Validation. Awesome - I need this in my day job's project starting next week! Good timing, eh?!

So how do you use indexed properties in Forms? Two ways: Simple arrays of strings and arrays of beans (recommended). Here's a good tip - if you're using DynaActionForms, you can access a property in JSTL using {form.map.propertyName}. I did not know that - thanks James! Lots of good stuff in this one (too much to write down), I hope this preso is available online and a demo app goes with it. To validate simple array of strings, add indexedlistProperty to your <field> in validation.xml (you must also specify the property). If you're validating beans, use property="propertyName" and indexedListProperty="beanName".

However, do you really want to require all fields of your child beans? No, probably not. You (most likely), just want to require fields if some fields are populated. Struts provides us with the requiredif validator. No JavaScript validation exists for requiredif at this time. Hmmm, I wonder if XDoclet can generate indexed validation rules. Here's an example of how to do this with the current 1.1 RC1 Release.

<form name="myForm">
  <field property="lastName" indexedListProperty="person" 
    depends="">
    <arg0 key="label.lastName"/>
  </field>
  <field property="firstName" indexedListProperty="person" 
    depends="requiredif">
    <arg0 key="label.firstName"/>
    <var>
      <var-name>field[0]</var-name>
      <var-value>lastName</var-value>
    </var>
    <var>
      <var-name>fieldIndexed[0]</var-name>
      <var-value>true</var-value>
    </var>
    <var>
      <var-name>fieldTest[0]</var-name>
      <var-value>NOTNULL</var-value>
    </var>
  </field>
  ...
</form>

Note that the [0] is NOT an indicator of which indexed property to validate. RequiredIf is powerful but ugly, so James wrote something better. Unfortunately, it's too late for 1.1 and will be added for the 1.2 release. Sounds like most folks that use the Validator will be using a nightly build for awhile ;-). The new validator is called "validwhen," and looks as follows:

<field property="firstName"
  indexedListProperty="dependents"
  depends="validwhen">
  <arg0 key="dependentListForm.firstName.label"/>
  <var>
    <var-name>test</var-name>
    <var-value>((dependents[].lastName == null) or
                (dependents[].firstName != null))
    </var-value>
  </var>
</field>

Fricken sweet! James is sending me the code - cool! This will make my life soooooo much easier next week. Status of Struts 1.1 from James: they're working on getting the commons packages to a release state. Slides from today will be available at strutskickstart.com later this afternoon.

Posted in Java at Mar 29 2003, 09:32:28 AM MST 4 Comments

Struts Training: Week 3

I just signed in for 3rd week here in Struts Training. I'm coming to you live from Chelan, WA. So on with what Ted has to say.

Ted's talking about persistence in Struts: Transaction Script vs. Domain Model.

Transaction Script - organizes business logic by procedure. Great choice for small applications with simple logic. For example, online auction, public search engine or an address book.

Domain Model - an object model of the domain. Has a rich variety of objects that incorporate both data and behavior. Ted mentions that the Domain Model is better for larger applications. For example, managing inventory for an online auction might require using the domain model.

What Ted is doing is using the Domain Model to separate Struts from his Actions - so that he passes around a DomainRequest, DomainResponse, and gets his form from a factory. To me, this looks like a good way to make your Struts layer a lot more complicated! ;-) At the same time, Ted is getting this information from Martin Fowler's Patterns (in Enterprise Architecture, ISBN 0321127420) book, so maybe I should move to the domain model. Naahh, I think I'll keep using the Transaction Script method - it's probably easier for folks to learn and would definitely be easier for rookies to maintain.

Onto Hibernate and how it works:

- POJO beans, encourages fine-grained
- Utilizes "persistence by descriptor"
- Provides DBA-friendly text queries
- Plays well with others
- Buffet-style implementation

IMO, if you're not using Hibernate, you should know why. If you're starting a new project, it's worth looking at. If you're using it, but not using XDoclet - you should be. XDoclet is the best way to avoid DD Hell (quoted from Erik Hatcher).

I didn't know that Hibernate supported a version - did you? Apparently you can specify that a property is a version and Hibernate will use it as you'd expect. Don't see that I have a need for that, but possibly. Would a struts-resume user ever want to keep old versions of their resume? I like to keep old versions of mine, but I have to admit, I never look at them again.

<version name="version" />

Ted just touched on how Hibernate can generate your database schema for you. This is a very powerful feature IMO - especially with struts-resume. It makes it nice for an example app. For instance, with struts-resume, you can run "ant setup-db" and it'll drop tables and re-create your db schema for you.

A student asks about the bottom-up approach - what if you already have a database. My advice? Try looking at Middlegen, its Hibernate Plugin in designed to create an XDoclet-enabled POJO from a database schema. There's also the Reverse Schema Generator that is included with Hibernate. I've used this one and it works great. I've never used Middlegen, but I should be considering that I tag the generated POJO up with XDoclet tags.

Interesting: Ted just mentioned that Gavin (Hibernate's Lead Developer) is working on a book for Manning. It is on Object Relational persistence and it uses Hibernate for its example apps. Erik Hatcher, at his preso on Wednesday, also mentioned that an XDoclet in Action book will be published soon by Manning. He even showed us the book's cover - so I'm assuming it will be published soon.

Hibernate's Fashionable Friends: XDoclet, Commons Logging, Commons DBCP, DynaBeans and Turbine Caching.

To learn more about this Hibernate, checkout:

· AgileData Website (Scott Ambler)
· Hibernate Homepage
· Struts Application Site (Hibernate example and Struts Resume both use Hibernate with Struts)

Vic still likes RowSets and SQL better. I'm guessing this is because he's a SQL expert. The nice thing about Hibernate is that it's query language (HQL) is very much like SQL and allows you to do complex joins. At least, to my knowledge, I've never done any fancy joins in the HQL, just in the mapping (*.hbm.xml) files.

Quote from Ted: This is the year of JUnit books. Watch for them this summer..

Now Ted is covering StrutsTestCase, a JUnit extension that hooks into Struts and Cactus. IMO, it's an awesome way to test Struts Actions - even easier than testing a servlet with Cactus.

Another book: JUnit in Action (Manning) by Vincent Massol and Ted. To be published this summer. Vincent is the lead developer on Cactus, so I expect this to be a great book. Right now, I wish I had written my first book for Manning rather than Wrox. :-(

The one bad part about today's session is that I had to use a calling card to dial in and at $0.35/minute, I'm up to about $25! I should probably sign off soon and save some cash...

Tapestry - are you using it? A student asks about it and Ted mentions that he views it as a presentation framework like Velocity. I've heard lots of good things about it, but have never used it. Ted admits that he uses Velocity and gave up on using JSPs a while ago.

Good stuff - thanks Ted, I'm signing off (the QA session is still in progress).

Posted in Java at Mar 15 2003, 08:37:28 AM MST 1 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

Struts Update: 1.1 beta 3 to 1.1 RC1

While upgrading Hibernate last night and this morning, I also upgraded Struts. Now I'm having some issues there, so I'd better document those too. First of all, the following line doesn't seem to be rendering any client-side JavaScript anymore:

<html:javascript formName="resumeForm"
      dynamicJavascript="true" staticJavascript="false"/>

Update 1: Nevermind, it seems my Internet connection went dow while starting Tomcat. Since the Digester couldn't validate the Struts' XML configuration files with their respective DTDs, it stopped them from loading.

Update 2: This turned out to be a legitimate issue. Adding cdata="false" to the above tag enabled the browser to see the JavaScript by removing the "<![CDATA[" after <script type="text/javascript">

Revisiting the Hibernate upgrade, I needed to add dom4j.jar to WEB-INF/lib to solve java.lang.NoClassDefFoundError: org/dom4j/Node.

Now I'm getting:

java.lang.NoClassDefFoundError
	at net.sf.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:571)

What the @#$*%#? hibernate2.jar is in WEB-INF/lib??

Update 3: I had to add cglib.jar to WEB-INF/lib as well. Now back to an issue I'm having with the Validator where client-side validation is working when I click "cancel" (as in, it's disable), but server-side is kicks in. Argghhhh!

Update 4: I found an issue (via the struts-user list) about using the Validator with LookupDispatchAction. It basically doesn't allow you to control validation on a method level, so I've hacked the following workaround.

I changed <html:cancel> to be <html:button> and added onclick="cancel()", where cancel() is the following JavaScript method:

<script type="text/javascript">
function cancel() {
    location.href = '<html:rewrite forward="cancelUser"/>';
}
</script>

The "cancelUser" forward points to "/editUser.do?action=Cancel", which is an action-mapping that doesn't have validation (validation="false") and this hits the "cancel" method on UserAction and routes appropriately.

Phew - I'm beat. I never realized being an upgrade-happy-keyboard-monkey could be so much work!

Posted in Java at Feb 24 2003, 11:10:46 AM MST 4 Comments