This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Spring and the fly likes Multiple Filed Binding with form Object Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "Multiple Filed Binding with form Object" Watch "Multiple Filed Binding with form Object" New topic
Author

Multiple Filed Binding with form Object

Smruti Ranjan
Greenhorn

Joined: Aug 19, 2013
Posts: 5
Hi

I am new to Spring MVC using spring 3.0. I have requirement. I have a field called mobile number which is a text box. I should provide an option to the user to add n number of mobile numbers, what i meant is there should be a button on click of which there should be another text field to be shown which accepts another mobile number. Can you please suggest the approach for implementing it in jsp, form binding and validating using Spring MVC.

Regards,
Smruti
Jhakda Velu
Ranch Hand

Joined: Feb 26, 2008
Posts: 166
You would need some script to add the fields on click of button and assign an id to it. You may look at these posts for further help

Page with dynamic fields
Another Example


If I become filthy rich, I'll sponsor research for painless dental treatment at Harvard Medical School. Thats why,I'm learning Java.I have 32 teeth, 22 are man made.
Smruti Ranjan
Greenhorn

Joined: Aug 19, 2013
Posts: 5
Hi,

Thanks for your response. I am getting an error can you help to resolve
Following is the jsp code

<c:forEach items="${form.sourceLocation}" var="source"
varStatus="status">
<tr>
<td align="center">${status.count}</td>
<td><form:input path="sourceLocation[${status.index}].selectedLocation"/></td>
</tr>
</c:forEach>

Following is the form class

public class form {
private List<Location> sourceLocation;
public List<Location> getSourceLocation() {
return sourceLocation;
}
public void setSourceLocation(List<Location> sourceLocation) {
this.sourceLocation = sourceLocation;
}
}

followign the Location class
public class Location {
private String selectedLocation;
public Location() {
}
public Location(String selectedLocation) {
this.selectedLocation = selectedLocation;
}
public String getSelectedLocation() {
return selectedLocation;
}
public void setSelectedLocation(String selectedLocation) {
this.selectedLocation = selectedLocation;
}

}

I am getting below error

org.springframework.beans.NotReadablePropertyException: Invalid property 'sourceLocation0' of bean class [demo.form]: Bean property 'sourceLocation0' is not readable or has an invalid getter method: Does the return type of the getter match the parameter type of the setter?

As per my analysis the property should be sourceLocation[0] instead on sourceLocation0. I went ahead and did a view source of page following is the content to which jstl form:input tag as converted to html

<td><input id="sourceLocation0.selectedLocation" name="sourceLocation0.selectedLocation" type="text" value=""/></td>

if i replace jsp with regular html input tag as below every thing works fine

<td><input name="sourceLocation[${status.index}].selectedLocation" value="${source.selectedLocation}" /></td>

Can you please suggest.

Thanks & Regards,
Smruti Ranjan




 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Multiple Filed Binding with form Object
 
Similar Threads
File upload using spring mvc 3.0
Spring MVC using domain entities as form command objects
What does @spring.bind / #springBind do?
Display uneditable field in jsp
Spring vs. Struts