Taras
Aug 9th, 2007, 09:59 AM
Hi
I am new to Spring and I decide to develop simple test application using this framework.
Application has 2 business objects
ApplicationUsers
public class ApplicationUsers implements java.io.Serializable {
private int userId;
private String username;
private String password;
private Set<UserContacts> userContactses = new HashSet<UserContacts>(0);
//common getters and setters
}
UserContacts
public class UserContacts implements java.io.Serializable {
private int contactId;
private ApplicationUsers applicationUsers;
private String contactName;
private String contactDescription;
//common getters and setters
}
So I need to implemet user registration functionality
This is Controller
public class RegisterFormController extends SimpleFormController {
private IApplicationUsersDAO userManager;
public RegisterFormController() {
setCommandName("applicationUsers");
setCommandClass(ApplicationUsers.class);
}
protected ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response, Object command,
BindException errors) throws Exception {
ApplicationUsers inputUser = (ApplicationUsers) command;
try {
userManager.createUser(inputUser);
} catch (Exception e) {
return showForm(request, response, errors);
}
return new ModelAndView(new RedirectView(getSuccessView()));
}
protected Object formBackingObject(HttpServletRequest arg0) throws Exception {
ApplicationUsers user = new ApplicationUsers();
return user;
}
//common getters and setters for userManager
}
And I have creazted JSP form
it has next fields
<form:form commandName="applicationUsers" method="post" id="userForm" >
<form:input path="username" id="username"/>
<form:input path="password" id="password"/>
<form:input path="userContactses[0].contact_name" id="email"/>
<input type="submit" name="save" value="Save" />
</form:form>
So when I am trying to access to this page - i recieve an Exception
org.springframework.beans.InvalidPropertyException : Invalid property 'userContactses[0]' of bean class [com.romexsoft.spring.domain.model.ApplicationUsers]: Cannot get element with index 0 from Set of size 0, accessed using property path 'userContactses[0]'
Is it problem in data binding? Plese help to resolve this problem...
I am new to Spring and I decide to develop simple test application using this framework.
Application has 2 business objects
ApplicationUsers
public class ApplicationUsers implements java.io.Serializable {
private int userId;
private String username;
private String password;
private Set<UserContacts> userContactses = new HashSet<UserContacts>(0);
//common getters and setters
}
UserContacts
public class UserContacts implements java.io.Serializable {
private int contactId;
private ApplicationUsers applicationUsers;
private String contactName;
private String contactDescription;
//common getters and setters
}
So I need to implemet user registration functionality
This is Controller
public class RegisterFormController extends SimpleFormController {
private IApplicationUsersDAO userManager;
public RegisterFormController() {
setCommandName("applicationUsers");
setCommandClass(ApplicationUsers.class);
}
protected ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response, Object command,
BindException errors) throws Exception {
ApplicationUsers inputUser = (ApplicationUsers) command;
try {
userManager.createUser(inputUser);
} catch (Exception e) {
return showForm(request, response, errors);
}
return new ModelAndView(new RedirectView(getSuccessView()));
}
protected Object formBackingObject(HttpServletRequest arg0) throws Exception {
ApplicationUsers user = new ApplicationUsers();
return user;
}
//common getters and setters for userManager
}
And I have creazted JSP form
it has next fields
<form:form commandName="applicationUsers" method="post" id="userForm" >
<form:input path="username" id="username"/>
<form:input path="password" id="password"/>
<form:input path="userContactses[0].contact_name" id="email"/>
<input type="submit" name="save" value="Save" />
</form:form>
So when I am trying to access to this page - i recieve an Exception
org.springframework.beans.InvalidPropertyException : Invalid property 'userContactses[0]' of bean class [com.romexsoft.spring.domain.model.ApplicationUsers]: Cannot get element with index 0 from Set of size 0, accessed using property path 'userContactses[0]'
Is it problem in data binding? Plese help to resolve this problem...