aspose file tools
The moose likes Java in General and the fly likes Java Array Converter Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "Java Array Converter" Watch "Java Array Converter" New topic
Author

Java Array Converter

YuenLian Wu
Ranch Hand

Joined: Nov 16, 2005
Posts: 73
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
Chengwei Lee
Ranch Hand

Joined: Apr 02, 2004
Posts: 884
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.


SCJP 1.4 * SCWCD 1.4 * SCBCD 1.3 * SCJA 1.0 * TOGAF 8
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Java Array Converter
 
Similar Threads
Struts HTML Lib w/Ajax - Can't get textbox value to Action class
Two Dimensional Array in struts
html:select vanishing values
collect multiple values using logic:iterate
Html form to form bean mapping, multiple checkboxes