Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
Win a copy of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds this week in the Cloud/Virtualization forum!
  • 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:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

Hidden field can carry any type of java objects ?  RSS feed

 
Ranch Hand
Posts: 162
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I need to use hidden variable to carry some big objects (like very long arraylist, String[][]), is there any known issue or restriction for hidden variable to carry such objects ?
 
Ranch Hand
Posts: 3640
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can store objects that you have described in a single hidden field.

Better you put in to session, if you to pass those objects to the next link.
 
Author and ninkuma
Marshal
Posts: 66797
168
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

You can store objects that you have described in a single hidden field.



No, you can't. Like all other input types, you are restricted to strings.
 
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm guessing you are you talking about hidden FORM fields? The concept of "hidden" applies only as a flag to the browsers HTML rendering engine... the browser has no concept of Java objects!!!
 
Artemesia Lakener
Ranch Hand
Posts: 162
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sorry, to clarify, I was talking about hidden form field like
<FORM ACTION="/myaction" >

<type="radio" name="..", value="..">...
....

<type="HIDDEN" name="hidden_obj" value="<%= request.getAttribue("obj") %>">

</FORM>

So, I do want to get an object passed. Can I do that this way ?
 
Ranch Hand
Posts: 541
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, you can't put an object there at all. Just a string. Remember what the <%= operator does, it prints out a String. Now Java has a little feature, where if you try and print out an object, it automatically calls the objects toString() function.

So what you have to do if you really want to do this, is convert it to a string, for example using ";" characters to seperate each string in the array. Then you have to read the string back in and create the objects from it again, for example using a StringTokenizer.

Other things you can consider are like said above, putting the objects on the Session object.

Perhaps just putting an 'id' in a hidden field, which refers to an item in a structure which is held at the application level.
 
Artemesia Lakener
Ranch Hand
Posts: 162
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks folks. So, it seems the only way to carry the "objects" over pages is to use "session" ? I am wondering how people handle such things when "HttpSession" was not available to java developers ? Furthermore, how do those ASP, Cold fusion people do it ? interesting.
 
Ranch Hand
Posts: 5093
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why wouldn't you have a session or be unable to create one?
If you have an Http server you have sessions, they're not some magical Java feature that some servers have and other don't.

Read up on the servlet specification and the HTTP specifications, you might learn a thing or two.
 
Artemesia Lakener
Ranch Hand
Posts: 162
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by Jeroen Wenting:
Why wouldn't you have a session or be unable to create one?
If you have an Http server you have sessions, they're not some magical Java feature that some servers have and other don't.

Read up on the servlet specification and the HTTP specifications, you might learn a thing or two.



I was just asking questions about "hidden fields", and I guess it has nothing to do with "whether session is better or can I use session ?"
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!