• 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
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Multiple forms with Use bean.

 
Ranch Hand
Posts: 320
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi
I have a .jsp page that has forms for entering information. Let's say this page has forms to enter X Users into a database. on a website.
In my HTML code I can seperate each FORM by giving them a name, but the problem is when I submit this page to another .jsp where I want to do <jsp:useBean name="someUsers"/> and <jsp:setProperty name="someUsers" property="*"/>
Will the setProperty tag create an Array of Users so that each form is one user? If not, CAN I setup the useBean to make an array of Users?
If my original page had only 1 form and I did the useBean and setProperty it would populate the bean with the user information, but I would really like to be able to process multiple users at once.
Oh yeah, the page with the multiple user forms can have an undetermined number of User forms. I can also do something like pass a value of 'total forms' and then loop through them populating User objects but this is messy and also doesn't allow me to seperate my business logic from the display. I would much rather setProperty and then pass my array/collection of Users to my servlet for processing.
Any help would be very appreciated.
Thanks.
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If I understand what you are trying to do - it isn't possible. Only one <form> .. </form> at a time can be submitted in a request.
"Will the setProperty tag create an Array of Users so that each form is one user? If not, CAN I setup the useBean to make an array of Users?"
The setProperty tag is going to be calling methods based on the names of the properties with the data for the properties. It will not build an array for you.
I think you are trying to do too much in one Bean - how about making a Bean correspond to a single user, then have it check for legal data from the form properties. If all is well, pass that Bean to another class responsible for keeping the collection of users.
Bill

------------------
author of:
 
John Bateman
Ranch Hand
Posts: 320
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


I think you are trying to do too much in one Bean - how about making a Bean correspond to a single user, then have it check for legal data from the form properties. If all is well, pass that Bean to another class responsible for keeping the collection of users.


Hi
Thanks for the response. As an aside I think your exam cram book is great, I'd love to comment on the others but it's the only one I've got.
I guess I mislead you with my example, the real reason I am trying to process multiple forms with useBean is because if I have a User object that contains multiple Lottery Tickets, get populated in one command. (setProperty).
I guess I'll have to stop trying to be so lazy and do it the long way.
Thank again.
 
Sheriff
Posts: 7001
6
Eclipse IDE Python C++ Debian Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So why are these separate forms? Surely if you put all your fields into one form, and give the fields names which can be resolved to which set of data they belong to (like <input name='form1_field3'>, for example) then you can submit it and process it in one go.
If you still can't do this, you can try using JavaScript to make one button submit more than one form, although each form submission will be a separate HTTP request to the server (look up form.submit() in any JavaScript reference).
 
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by William Brogden:
If I understand what you are trying to do - it isn't possible. Only one <form> .. </form> at a time can be submitted in a request.


True, but I still think it is possible. Here is how..
Instead of creating multiple forms, you can create a multi select box for each field. Then you can use javascript to add or remove a user from those select boxes. When it's time to submit.. select everything in all the select boxes and then submit. On the server side you can access a String[] for each of the select box in the same order as you entered your user values.
<pre>
attribute user_id:
user_id1
user_id2
attribute passwd:
passwd1 //relates to user_id1
passwd2 //relates to user_id2
</pre>
and so on...
But, in order for this to work properly... you have to make sure all fields are mandatory and you have to declare two setter/getter methods for each member. One for a single value form submission...
setUserId(String id){...}
And one for multivalue...
setUserId(String[] ids){...}

BTW, I have never done this before but the logic seems ok.. it should work!
 
Eat that pie! EAT IT! Now read this tiny ad. READ IT!
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic