We help IT Professionals succeed at work.

using javabeans to request dynamically created form fields

sonu19
sonu19 asked
on
Medium Priority
251 Views
Last Modified: 2010-03-30
hey guys,

I want to use java beans
I have a form in which I have dynamically created fields. I want to get the values of those fields and put it into a database.

the name of the fields is dynamically created
Comment
Watch Question

Commented:
Pass your request params into your javabean, and you'll have access to all of your submitted data.
make something like this:
Enumerator names = request.getParametersNames();
 
while (names.hasNext()){
   String value=request.getParameter(names.next().toString);
    // add value to database
}

Open in new window

Commented:
send dynamically created fields with types and db column name and then create your sql statement with these info dynamically.

Commented:
Watch out - the javabean can't see your request. You have to handle it in your DoPost (or DoGet) method, so it would be something like this code. Of course, you haven't been very specific as to how you want to use this stuff, but I'm assuming it's to process the values. If you want to set the values, you'll have to update the response too.

public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    Debug.log(this, "doPost", "new request");
    Map requestNameValuePairs = request.getParameterMap();
    MyJavaBean mjb = new MyJavaBean();
    mjb.processParameters(requestNameValuePairs);
    // and so on
}
 
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    doPost(request, response);
}
        

Open in new window

Explore More ContentExplore courses, solutions, and other research materials related to this topic.