File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Other Application Frameworks and the fly likes Spring:bind tag for multiple objects Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Other Application Frameworks
Bookmark "Spring:bind tag for multiple objects" Watch "Spring:bind tag for multiple objects" New topic

Spring:bind tag for multiple objects


Joined: Sep 25, 2008
Posts: 2

iam using spring framework and wanted to do registration form, which should relate the two tables through hibernate. While binding the bean objects with <Spring:bind> tag i registered the bean class with command class and gave some command name.

like <spring:bind path="userreg.personAddress">
where userreg is the command name given to the registration class.Similarly did for all other fields with same command name.But if i want to bind username and password to another beanobject i.e another table,i cannot add new command name to a new command class as below.

<property name="commandName">
<property name="commandClass">
<property name="commandName">
<property name="commandClass">

how can i bind different objects to the same command object
Paul Sturrock

Joined: Apr 14, 2004
Posts: 10336

"VDS VDS", please check your private messages.

JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Rob Spoor

Joined: Oct 27, 2005
Posts: 20271


You clearly haven't read the naming policy properly, because your name is still not ok.

How To Ask Questions How To Answer Questions
pragas siva

Joined: Jul 12, 2011
Posts: 3
Test Post
pragas siva

Joined: Jul 12, 2011
Posts: 3
pragas siva wrote:Hi.

Just create one bean(Model). Inside bean create method to get second bean(Model).
using this method you can bind the second bean properties, in view.

Here is sample code for reference.

import java.util.Date;

* @author pragaspathi.s
public class TestBean1 {

private Date a;
private String b;
private String c;
private final TestBean2 tstbean2 = new TestBean2();

public TestBean2 getTstbean2() {

return tstbean2;

public Date getA() {
return a;

public void setA(Date a) {
this.a = a;

public String getB() {
return b;

public void setB(String b) {
this.b = b;

public String getC() {
return c;

public void setC(String c) {
this.c = c;

public class TestBean2 {

private String a2;
private String b2;
private String c2;

public String getA2() {
return a2;

public void setA2(String a2) {
this.a2 = a2;

public String getB2() {
return b2;

public void setB2(String b2) {
this.b2 = b2;

public String getC2() {
return c2;

public void setC2(String c2) {
this.c2 = c2;



package com.comobj.controllers;

import com.comobj.models.TestBean1;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.validation.DataBinder;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.multiaction.MultiActionController;

* @author pragaspathi.s
public class TestController extends MultiActionController {

public ModelAndView showForm(HttpServletRequest request, HttpServletResponse response) {
ModelAndView mv = new ModelAndView("Comobj");
mv.addObject("testBean1", new TestBean1());
System.out.println("thisis called ");
return mv;

public ModelAndView submitValue(HttpServletRequest request, HttpServletResponse response, TestBean1 m) {
System.out.println("this is called form test controller");
TestBean1 min = m;
System.out.println("--> from tst a " + min.getA());
System.out.println("--> from tst b " + min.getB());
System.out.println("--> from tstbn2 a2 " + min.getTstbean2().getA2());
DataBinder bnd = new DataBinder(new TestBean1());
ModelAndView mv = new ModelAndView("index");
return mv;


<%@ taglib prefix="c" uri="" %>
<%@ taglib prefix="fn" uri="" %>
<%@ taglib prefix="spring" uri="" %>
<%@ taglib prefix="form" uri="" %>
<%@taglib prefix="fmt" uri="" %>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Welcome to Spring Web MVC project</title>


<form:form action="submitValue.htm" method="POST" commandName="testBean1">
(TestBean1 property-->a) DATE : <spring:bind path="a">
<input type="input" name="a" id="stdate" value="<fmt:formatDate value="${a}" type="date" pattern="yyyy-MM-dd"/>"/>
(TestBean1 property-->b) <form:input path="b" />
(TestBean2 property-->a2) <form:input path="tstbean2.a2" />
<input type="submit" value="check">

I hope this might be help full.
pragas siva

Joined: Jul 12, 2011
Posts: 3
check it
I agree. Here's the link:
subject: Spring:bind tag for multiple objects
It's not a secret anymore!