• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • Devaka Cooray
Saloon Keepers:
  • Ganesh Patekar
  • Tim Moores
  • Carey Brown
  • Stephan van Hulst
  • salvin francis
Bartenders:
  • Ron McLeod
  • Frits Walraven
  • Pete Letkeman

Dynamically increased form (Collection)  RSS feed

 
Ranch Hand
Posts: 105
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear Sir:

I am using Strut to do the Web design.
I got into a problem like this:

My web page will display several input fields for the properties a record(bean). When the user wants, he/she can press a button. The same type of
input fields (another record) will be added to the screen (page). User may
add as much new records as he/she wants. After he/she satisfied, user can press a "save data" button to send the information in the web page (or in the ActionForm)to the ActionServlet for processing.

That means the user may dynamically add the input fields of different instances of the same bean in the JSP page without submitting to ActionServlet. When he/she satisfied, user will submit the whole collection of beans to ActionServlet. The clent side display is dynamic before submission. The data submitted is a dynamiccally changed collection.

My questions are:

1) How can I define an Actionform or DynaActionForm that is suitable for this type of application ?
2) How can I do the dynamic client side display of input fields of bean (form element) using Struts tag before submitting the form ?
3) Is there any currently existing good Strut discussion forum ?

Please let me know how I can solve a problem like these using Strut.

Thank you.


John Chien
 
pie sneak
Sheriff
Posts: 4727
Mac Ruby VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I saw your complaint on the thread welcoming our new visiting hosts and decided to check out your post.

Usually it is difficult to get a response around here unless your question says "this is the code I've tried, why doesn't it work?" When it is phrased at a high-level of "how am I supposed to do this" it is often perceived as asking people to do the work for you.

By what you described, if you want the page to dynamically change the page without submitting a request, you'll have to do 100% of the dynamic functionality with javascript and very little to do with Struts.

It is also possible to make a submission to the server each time you add an entry but not update the backend until you have finished. This CAN be handled with Struts and would be my preference.

This forum is pretty good. The dev and user forums on the official Struts site are the only other ones that are any good that I know of. In either place you will get good replies if you can show code that you've tried and ask why it isn't working.
 
Ranch Hand
Posts: 834
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
agree with marc, this is the best java forum, however there is no responsibility of everyone here MUST respond to your thread, and remember you didn't pay single cents to javaranch, people helping each other , this is not 7-11 shop, serving you in 24hours , when people reply you late then you get angry on it , i think you better change your attitude, and apology to javaranch's moderator ..just my concern
 
John Chien
Ranch Hand
Posts: 105
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for the response.
Certainly, I know that there is no responsibility for you to give me any answer. However, if the forum does not have any response for a question, what is the purpose to have the forum.

I apologize for my previous post. I think I am a little worry about the project in that time.

Actually, I have code to be posted. However, I was rejected many times.
Somehow the forum does not take my code posting.

The reason I put a high level posting is the result of the rejection of the forum to receive my code posting.

When I do the high level posting, I do not expect to get a detailed answer. I expect to get a direction about how to resolve the issue. or to be directed to a reference site.

I know how to use DynaActionForm to dynamically handle the issue.

However, I do not like to go to server for every record that user want to add. The user may want to add thirty records before saving. In this case, user will have to access the server thirty times to dynamiccally increase the size. This will waste the network resource and delay the response.

I do not want to initialize the form to a very big size so that the user can input the records that he/she want. This should be handled dynamically.
If the structs can not solve something like this, I believe that the structs use in web will be some how limited.

What I want is that when the user dynamically add the records, the javascript can create the records that can be handled using DynaActionForm.

I think I want to create the DynaActionForm with a form property to be ArrayList or array. I will have it initilized without giving a size. In the client size. I will have a hidden property that keep the count that the user input the record. For each record, I will try to assign the name
(property) with the DynaActionForm's form property indexed using the hidden property. I will test to see if it works. If I succeed, I will post what I did. If I do not post anything, you can assue that I failed.

I apologize again for the confusion and trouble that I caused before.

Thanks,

John Chien
 
Ranch Hand
Posts: 502
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You probably need a List-backed property.

I havent done this using DynaAction form, but I used my own action bean. Please dont shout at me if this doesnt help you.

My action bean looked something like this



And your java script has to dynamically add new text fields into your struts form with the id of the text field set to "names[0]", "names[1]" and so on.

You can find more information on this page http://struts.apache.org/faqs/indexedprops.html
 
Ranch Hand
Posts: 4982
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have similar experiences that we allow the user to add something to the *list*. However, we use the hash table approach to solve it. The key is the position of the item, and the value is the item itself.

In the Form, we have:


and some special methods:


For adding an item, we just simply store the list in section, without really touching the items in the form. For deleting an item, we then obtain which item has been chosen from the form, and then remove it from the Hashtable.

Thus, we dont need to use JavaScript for handling the dynamic list.

Nick
[ November 09, 2004: Message edited by: Nicholas Cheung ]
 
Nicholas Cheung
Ranch Hand
Posts: 4982
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


agree with marc, this is the best java forum, however there is no responsibility of everyone here MUST respond to your thread, and remember you didn't pay single cents to javaranch, people helping each other , this is not 7-11 shop, serving you in 24hours , when people reply you late then you get angry on it , i think you better change your attitude, and apology to javaranch's moderator ..just my concern


Sometimes people really nervious when they need immediate help. We might try to make here a bit relax place for graceful discussion.

Nick
 
Jayesh Lalwani
Ranch Hand
Posts: 502
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by Nicholas Cheung:
I have similar experiences that we allow the user to add something to the *list*. However, we use the hash table approach to solve it. The key is the position of the item, and the value is the item itself.

In the Form, we have:


and some special methods:


For adding an item, we just simply store the list in section, without really touching the items in the form. For deleting an item, we then obtain which item has been chosen from the form, and then remove it from the Hashtable.


But, using HasTable, you will lose the order of the items, right? I wanted to keep the order of the items correct, so I used a List.




Thus, we dont need to use JavaScript for handling the dynamic list.

Nick

[ November 09, 2004: Message edited by: Nicholas Cheung ]



You need javascript if you want to dynamically add controls to the web page, without doing a postback to the server. That has nothing to do with Struts however. However, if you are adding controls dynamically into a Struts form, you have to be careful that the id's of the controls agree with Struts naming conventions, otherwise Struts wont populate your Bean correctly
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!