• 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
  • Liutauras Vilda
  • Paul Clapham
Sheriffs:
  • paul wheaton
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Piet Souris
Bartenders:
  • Mike London

Hidden field can carry any type of java objects ?

 
Ranch Hand
Posts: 162
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 67694
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

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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ?"
 
reply
    Bookmark Topic Watch Topic
  • New Topic