Binding Entities and Their Children to Java JSP Form Elements in Spring Framework MVC

Binding objects to JSP form elements is actually quite easy in Spring Framework using the “modelAttribute” and “path” tags. Our scenario was the use of two Hibernate POJOs comprised of a parent entity “Parent” and a single “Child” entity which needed to be displayed on screen with appropriate form elements (“input” and “select”). The entities were annotated for use as part of a larger application but the basic structure was:

public class Parent{
  private Int id
  private String description
  private Child child

public class Child{
  private Int id
  private String name

To display these objects on screen as part of a form in Spring Framework MVC we used the following “ParentController” controller with a “showparent” action. The action uses a “parentService.getParent(id)” method (not shown) to retrieve a single parent entity based on “id” and attach it to the form using a Map “model” and a returned “ModelAndView”. A “childService” is used to get the list of every possible child entity (also not shown) and this is also added to the “ModelAndView”:

@RequestMapping(value = "/showparent", method=RequestMethod.GET)
public ModelAndView protocolList(HttpServletRequest request)
	Map<String, Object> model = new HashMap<String, Object>();
	model.put ( "children", childService.getAll());
	model.put ( "parent", parentService.getParent(id));
	return new ModelAndView ( "showparent", model );

The form itself is very simple and uses Spring binding to automatically create and populate input fields:

<%@ taglib uri="" prefix="form" %>
<form:form modelAttribute="parent" >
Description:  <form:input path="description"/>
Child:  <form:select path="child" id="child" items="${children}" itemValue="id" itemLabel="name"/>

Spring Framework uses the “modelAttribute” and “path” tags to determine what is set on the form. In this case the forms “modelAttribute” is “parent” which means that the elements in the form are properties of the “parent” entity. The “description” is shown as the contents of a simple textbox input using “form:input”. The interesting part is the “form:select” which automatically populates the select with option objects based on the set of “child” objects in “children” and selects the correct “child” option for the “parent” based on the “itemValue”, “id” in this case.

Submitting changes to “parent” entities is covered in my more recent post.

Setting Up & Starting Apache and Tomcat on Solaris 10 x86

Apache, Java and Tomcat are all installed by default in my copy of Solaris 10 x86, I assume this is the same for all versions of Solaris. I was dreading compiling Apache and Tomcat from source and was even considering installing the package from Luckily I googled a bit more and soon realised everything was installed by default, which is actually a bit obvious when you think about it.

Thanks to a random bug report page on requesting an addition in documentation I got straight to the answer. I had to add an extra step in to add the required environment variables (which are now sitting in my “profile” file to be loaded each time). I’ve compressed the information a bit here but these are the steps I took to start Apache and Tomcat:

First add the two environment variables JAVA_HOME and CATALINA_BASE (for Tomcat) to your “/etc/profile” file or current session using usual “export” command:

export JAVA_HOME=/usr/java


export CATALINA_BASE=/var/apache/tomcat

Now you need to make sure the config files for both Apache and Tomcat exist with the right filenames. Luckily there are example config files included with both so you can just rename/copy these config files:

cp /etc/apache2/httpd.conf-example /etc/apache2/httpd.conf

cp /var/apache/tomcat/conf/server.xml-example /var/apache/tomcat/conf/server.xml

Now you can start up Apache:

svcadm enable apache

Now make a symbolic link to point the Tomcat “conf” directory to the Apache Tomcat “conf” directory (just to make sure config files come from the right place):

cd /usr/apache/tomcat

ln -s /var/apache/tomcat/conf conf

Now last of all, start up the Tomcat server using the script in the Tomcat “bin” directory:


Now you have both Apache and Tomcat running (on ports 80 and 8080 respectively). The home directory for Apache, where the html documents etc are stored, is located at “/var/apache2/htdocs/”. The home directory for Tomcat is at “/var/apache/tomcat/webapps/ROOT”.

Interestingly the test page for Tomcat at “http://localhost:8080″ states the environment variable as “$CATALINA_HOME” and not “$CATALINA_BASE” as I used. My Tomcat seems to be perfectly happy and I can run the sample applications so I guess you don’t need to worry about this.


If you have installed Oracle you can use Oracle’s own web application server (OC4J) at “http://localhost:1158″. There is a default page here with links to documentation etc. I’ll write more on using this once I figure out how to do dev work in Windows and push it to our Solaris installs.