PDA

View Full Version : multiple instances of domain object?


anicad
Apr 4th, 2006, 02:30 PM
Hi,

Is it possible to have multiple instances of a domain object on one form? If so, when an error occurs in one field, how does the BindException object know which instance the error occured in?

Thanks.

gmatthews
Apr 4th, 2006, 06:25 PM
public class MyCommand {

public MyDomainObject getDomain1() {
...
}

public MyDomainObject getDomain2() {
...
}
}



<spring:bind path="command.domain1.someField">
...
<spring:bind path="command.domain2.someField">

Is this what you mean?

epitoman
Apr 5th, 2006, 03:40 AM
Or you could use a collection

public class MyCommand {
public Collection getDomainObjects() {
...
}
}

and at jsp page you could write something like this

<c:forEach items="command.domainObjects" var="domainObject" varStatus="status">
<spring:bind path="command.domainObjects[${status.index}].someField">
...
</spring:bind>
</c:forEach>

anicad
Apr 5th, 2006, 09:46 AM
I'm trying to create multiple instances of my domain object when the flow starts.
For example, below is my FlowAction class definition
<bean id="formAction" class="org.springframework.webflow.action.FormAction">
<property name="formObjectName" value="searchCriteria"/>
<property name="formObjectClass" value="org.springframework.webflow.samples.phonebook.doma in.SearchCriteria"/>
<property name="formObjectScope" value="FLOW"/> </bean>
How do I set up the properties, so that I have another SearchCriteria Object with the object name "secondSearch"?

anicad
Apr 10th, 2006, 06:54 PM
why do i need the command class?

epitoman
Apr 11th, 2006, 11:02 AM
It's your form object that wraps multiple instances of your search criteria. You could of course put it in a scope and then access them from your page but using a form object feel a lot nicer to use