dcsimg
What is the best practice for dynamically extracting form data from a request (without extracting each parameter explicitly by name)?
5 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   neal_ravindran
Posted On:   Saturday, December 7, 2002 07:43 PM

What is the best practice for extracting form data when a form has been created dynamically with data from a database. So all the names of form elements are unknown..could be like age_123,job_878(123,878 etc are ids in db) I can get the parameter names and loop on the Enumeration and use if(params.startswith(age))..split at underscore and extract value ). Is that the only approach? Any libraries/tag out there to do this some standard way?



You may be wondering how I got the form with no preset field names...I submit one form and that via servlet creates this second form with data from DB. The user can make changes and resubmit to DB(kinda like an edit form)

Re: What is the best practice for dynamically extracting form data from a request (without extracting each parameter explicitly by name)?

Posted By:   Ganesh_Kumar  
Posted On:   Friday, June 10, 2005 07:15 AM

Enumeration en ;

int i=0;

if(request.getParameterNames()!=null){

en = request.getParameterNames();


while(en.hasMoreElements()){


String name = (String)en.nextElement();

String value= request.getParameter(name);

System.out.println("NAME ::: "+name);

System.out.println("value ::: "+value);

if(value.trim().equals("")){

//handel errors

ActionErrors ae = new ActionErrors();

request.setAttribute(Action.ERROR_KEY, ae);

if (ae != null || ae.size( ) > 0) {

return mapping.findForward("failure");

}

}

i++;

}

Re: What is the best practice for dynamically extracting form data from a request (without extracting each parameter explicitly by name)?

Posted By:   Massimiliano_Ragazzi  
Posted On:   Tuesday, August 3, 2004 07:20 AM

Enumeration get_parametri = request.getParameterNames();


while(get_parametri.hasMoreElements()) {


String name_param = (String)get_parametri.nextElement();


String value_param =request.getParameter(parametro)


}



Ciao Massimiliano

Re: What is the best practice for dynamically extracting form data from a request (without extracting each parameter explicitly by name)?

Posted By:   Manjula_Kote  
Posted On:   Sunday, March 28, 2004 10:01 PM

If the names of request parameters are unknown you can use the method
"Enumeration getParameterNames()" to obtain an enumeration of all parameter names and then iteration over each element and call "getParameter()" or "getParamterValues()" on that method.

Re: What is the best practice for dynamically extracting form data from a request (without extracting each parameter explicitly by name)?

Posted By:   Kedar_Khanvilkar  
Posted On:   Tuesday, May 27, 2003 10:33 AM

did you try getParameterNames() and getParameterValues(java.lang.String name) on ServletRequest? Hope I am getting your question right.
-K

Re: What is the best practice for dynamically extracting form data from a request (without extracting each parameter explicitly by name)?

Posted By:   Jeff_Hubbach  
Posted On:   Tuesday, December 10, 2002 08:56 AM

We do something very similar on some of our web apps. What we do is have a hidden field listing the ids in comma-delimited format. That enables us to use a StringTokenizer on that list, iterate over it, and get out each pertinent value for each id (ie, quantity, age, etc). This solves your problem by making all your form fields known, you just have to concatenate age or job with whatever id you are on in the list.
About | Sitemap | Contact