Reputation: 1670
In my project i dynamically generate the text box in table like below
project Name Date1 Date2 Date3 Date4 Date5 Activity
java Development Addnew
C++ Development Addnew
i display tables for one week.if user clicks addnew i generate the dynamic text box below the row where user clicked addnew button.
My problem is how to get all the textbox value in my spring controller as bean class.Because i am not sure abut how many text boxes are come in page load and submit.
Any Idea will be greatly appreciated!!!
Upvotes: 3
Views: 2080
Reputation: 36743
There aren't enough specifics in your question for a specific answer. However the general approach I would recommend.
I assume you'll need to update the list later, so I'd recommend a structure with an ID which can be used for CREATE and UPDATE operations, not just a plain list of Strings, this will also allow more fields later.
public void Foo {
private String project;
private String name;
private long id;
// getters + setters
}
JSON for a create
[{"project":"java","name":"Development",id:0}, {"project":"C++","name":"Development",id:0}]
JSON for a later update, i.e. with IDs round-tripped
[{"project":"java","name":"Development",id:100}, {"project":"C++","name":"Development",id:101}]
Upvotes: 2
Reputation: 8217
Go with the traditional getParameter()
method. I assume your text box will have unique names while generated using jquery
.
In the controller,
List<String> requestParameterNames = Collections.list((Enumeration<String>) request.getParameterNames());
for (String parameterName : requestParameterNames) {
String attributeName = parameterName;
String attributeValue = request.getParameter(parameterName);
// will have the text box values
}
Upvotes: 2