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

can we use a java collection as hidden field in java

 
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i have a jsp containing some records,
i have to save that records in DB,

can i use a java collection as hidden field and access its element in javascript and put the value of html array into collection element

and then submit
 
Bartender
Posts: 6663
5
MyEclipse IDE Firefox Browser Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Nope. Not possible. I would question why the records need to be in the JSP to begin with. Why is the controller / POJO related to the controller unable to access these records ?
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Remember that all a JSP does is to create an HTML page to send t the browser. So you cannot do anything that you would not be able to do with HTML.
 
swapnil kataria
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
just look at my problem,
I have to add new Users. initially in my JSP page it will ask information for one record,

Name Email Phone
______ ________ _________

here is a button ADD MORE
as i click on this button it should ask for the entries of another record,
right now i am calling ajax on ADD MORE which is adding one more user to List of Users,
but at the same time i need to update the form also, (other wise if I enters some value and click ADD MORE, old value get disappered).

but calling this both function doesn't guranty which will run first, onclick="updateValuesInForm();addMore();"
it is not sure updateValuesInForm() will execute first and then addMore() which is ajax call,
so output is not coming fine everytime,

other way i am thinking i use normal html input for accepting entries and adding new entries normally in html, without going into action every time,
but no idea how to map these value to users in the List of Users at the time of submission, thats why i was asking for collection as hidden field
 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There are two possible solutiosn to this,

The simple solution may be
1. Try calling your addMore() method within the updateValuesInForm();
like

Calling like above ensures addmore() getting called after the functions in updateValuesInForm()

2. If you dont want to go with the above you may need to manipulate the formbean to accomodate or add the user details by implementing dedicated getters and setters. But i hope solution 1 will work as per your comments.
 
swapnil kataria
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi prasanna, are you sure about this,
earlier i tried this, but it was not working consistently

addMore(){
updateValuesInForm()

-----
---
----
---
}


updateValuesInForm() is the submission of form without doing any thing in action, just for maintaing value entered in earlier record
 
swapnil kataria
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
sry parsana, i tried your first solution,
but it is also not working consistently,

 
Prasanna Soundarapandiyan
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry man. I was considering them as method calls alone. But as per the fact you need to update the values to your action form and then you should call your ajax method.
For this,
1. create a flag variable like isNewUserAdded (with default values as "NO") in your form, when ever you are doing ADD MORE, while hitting the action set the variable as "YES". Then return back the response to jsp
2. Create a hidden variable in your jsp which maps to this value i.e <input type="hidden" id="isNewUserAddedFlag" value="${form.isNewUserAdded }" />
3. In the javascript on load of the jsp, if isNewUserAddedFlag is "YES" call the ajax method.
if (document.getElementById("isNewUserAddedFlag").value == "YES") {
addMore();
}
------------------------------------------

If the above solution doesn't work out, try this,

1. Create three string array variables for Name, Email and Phone.

2. On Click of ADD MORE dont use any ajax just dynamically add input text boxes alone with the same property as the first one.

3. Provide the values and submit the form. The string arrays will get populated with values seqeuntially in all the three arrays.
Note: I am not sure about this solution, try this out.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic