Tom Obermeyer

Greenhorn
+ Follow
since Mar 16, 2001
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Tom Obermeyer

exactly, mike.
that's why i have a hidden field holding my id field, which, itself, has a name of "somename" + i.
the 'i' is not the id, it's simply a counter.
another reason it's useful to have different parameter names for each row is for validation. you might want to say "this field at row 'i' is invalid." however, i'm just putting each error message below it's corresponding input box.
20 years ago
yes, mike, that is true.
however, i am not sure if the using request.getParameterNames(String) will ensure correct ordering. I use the counter as a numbering scheme, so it's useful anyway.
20 years ago
you can use javascript to dynamically build contents of a form. an example is at the following URL:
http://javascript.internet.com/forms/dynamic-input.html
the problem with this example is it doesn't keep the old values of the input boxes. and, this type of javascript won't work in netscape.
if you want to build the form on the server side like i did, reread through what i did in the earlier post.
bascially, just give your textboxes the same name, but append a counter variable to the end of the name. use a scriptlet or tage to loop through the counter, adding the textboxes with name="blah<%=counter%>" for each iteration.
then, to the servlet/class you post to, you can iterate through the parameters using the same counter (request.getParameter("blah"+counter) to do validation or whatever. you can iterate through the parameters to delete one that are marked for deletion. and you can add new textboxes by increasing the counter size by currentNumberTextBoxes + addNumberTextBoxes.
20 years ago
Thanks,
I actually came up with a solution, somewhat similar to yours. I post the form to a handler that distinguishes between adding, removing, and submitting (saving). On the form, each input is given a name like "inputName" + i, where i is the current count of the total number of rows of input boxes. I have a custom tag that iterates through the count, displaying the input tag--along with it's value, if any--for the current row count.
in any of the three cases, the handler will iterate through the total row count, taking the current row's "inputName"+i, creating the object that holds this value, and putting this object into a hashtable with the key being the current row count.
the handler puts the hashtable on the request and forwards back to the original page. then the page enumerates through the hashtable, displaying the input value stored in each object.
this way, i can add some rows, enter some inputs, then add more rows and keep the old input values.
for add, the handler will add N new objects to the hashtable, starting at row count + 1.
each row has a checkbox next to the input box. so for delete, i simply check the value of the checkbox for the current row count value, and then delete it.
the input box is required. but for add and delete, if the input box is empty, an error message won't be displayed. this keeps the page clean while the user is editing. of course, doing submit (save) will validate completely.
20 years ago
Does anyone have a code sample for dynamically building a form? Basically, I want to allow the user to specify how many input boxes to add/remove from a form, while at the same time, keeping the values of other input boxes.
An example is a list of line items on a purchase order. I want to be able to add new line items to the purchase order.
20 years ago
Thanks Paul. I left my question broad, but I was really pondering the incorporation of the concept of coarse-grained objects with regards to Enterprise JavaBeans design and development. How would you go about developing coarse-grained EJBs from object models that model "fine-grained" objects? It seems like a coarse-grained object would have the properties and behaviors of several objects in the model. At what point would your EJB be to "coarse?"