Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

can we use a java collection as hidden field in java  RSS feed

 
swapnil kataria
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
  • 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
 
Deepak Bala
Bartender
Posts: 6663
5
Firefox Browser Linux MyEclipse IDE
  • Mark post as helpful
  • send pies
  • 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 ?
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66143
141
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • 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
  • 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
 
Prasanna Soundarapandiyan
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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
  • 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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!