• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Frank Carver
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • fred rosenberger

Java Array Converter

 
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,

I am currently developing a web application that has a form which can let the users to add or remove records. I used JSTL for loop to render it and it's an Array String once the form was submitted to the server. So each row has different fields, and all the rows shares the same field name. So my design is to have a Bean class that stores many String Array in a single class, just like the following


String[] FixingDate;
String[] Final_Fixing_Indicator;
....
.............



However, the back end side only can parse the Object Array, but not multiple object in a BeanC Class. So I have to convert the multiple Array into Collection of Bean classes, just like the following,


for ( int i = 0; i < callFormBean.getCallableDate().length; i++ ) {

CallableScheduleDetails callDetails = new CallableScheduleDetails();
callDetails.setCallableDate(callFormBean.getCallableDate());
callDetails.setCallNoticeDate(callFormBean.getCallNoticeDate());

callList.add(callDetails);
}




where I store the Array from the request object into a formBean variable called CallableDate

This looks stupid, but do you have any better solution than this? I am looking forward to get the best approach from you !!!

Myriads of Thanks

Transistor
 
Ranch Hand
Posts: 884
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is what I would normally do:

For adding new record, I would design the user interface & flow of the steps such that user could only add a new record per transaction, unless it is the user business requirements to allow for adding of multiple records before inserting into the database. By doing this, I could get the values per record at my servlet using request.getParameter(), then depending on whether I'm using direct JDBC or ORM, I would then either form an insert SQL or a POJO.

For removing of records, if multiple removal is permitted, I'll pass to the servlet, a delimited String object. This String should contain the primary key, then at the servlet, I would formulate the delete SQL accordingly.
 
World domination requires a hollowed out volcano with good submarine access. Tiny ads are optional.
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic